Skip to content

Commit 47b71eb

Browse files
author
Vintache Jean
committed
fix merge conflict
2 parents c5dbedb + 601e540 commit 47b71eb

File tree

6 files changed

+86
-47
lines changed

6 files changed

+86
-47
lines changed

Colladia/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
android:label="@string/app_name"
1111
android:supportsRtl="true"
1212
android:theme="@style/ColladiaTheme" >
13-
android:screenOrientation="portrait" > <!-- disable auto-rotate -->
13+
<!-- android:screenOrientation="portrait" disable auto-rotate -->
1414

1515
<activity
1616
android:name=".LoginActivity"

Colladia/app/src/main/java/com/ia04nf28/colladia/DrawActivity.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ public void selectDrawerItem(MenuItem item)
8989
switch(item.getItemId())
9090
{
9191
case R.id.nav_home:
92-
/*Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
93-
startActivity(intent);*/
94-
Manager.instance(getApplicationContext()).quitWorkspace();
9592
finish();
9693
break;
9794

@@ -144,22 +141,7 @@ public boolean onOptionsItemSelected(MenuItem item)
144141
}
145142
}
146143

147-
/* public void onBackPressed() {
148-
super.onBackPressed();
149-
Log.d(TAG, "onBackPressed");
150-
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
151-
if (drawer.isDrawerOpen(GravityCompat.START)) {
152-
drawer.closeDrawer(GravityCompat.START);
153-
} else {
154-
super.onBackPressed();
155-
}
156-
}*/
157144

158-
@Override
159-
protected void onDestroy() {
160-
super.onDestroy();
161-
Manager.instance(getApplicationContext()).quitWorkspace();
162-
}
163145

164146
@Override
165147
public void onStateChange(Diagram currentDiagram) {
@@ -168,4 +150,18 @@ public void onStateChange(Diagram currentDiagram) {
168150
getSupportActionBar().setTitle(Manager.instance(getApplicationContext()).getCurrentDiagram().getName());
169151
}catch (Throwable e) {}
170152
}
153+
154+
155+
156+
@Override
157+
protected void onResume() {
158+
super.onResume();
159+
Manager.instance(getApplicationContext()).joinWorkspace();
160+
}
161+
162+
@Override
163+
protected void onPause() {
164+
super.onPause();
165+
Manager.instance(getApplicationContext()).quitWorkspace();
166+
}
171167
}

Colladia/app/src/main/java/com/ia04nf28/colladia/DrawColladiaView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ private void upTouch(float x, float y)
507507
switch(mode)
508508
{
509509
case INSERT:
510-
//Manager.instance(applicationCtx).updatePositionElement(drawElem, iAbsolutePoint, mAbsolutePoint);
511510
drawElem.set(iAbsolutePoint,mAbsolutePoint);
512511
Manager.instance(applicationCtx).addElement(drawElem);
513512
drawElem = null;

Colladia/app/src/main/java/com/ia04nf28/colladia/LoginActivity.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void onPropertyChanged(Observable sender, int propertyId) {
103103
updateColorPickerButton(color);
104104
}
105105

106-
@Override
106+
/*@Override
107107
protected void onStop() {
108108
super.onStop();
109109
@@ -120,7 +120,7 @@ protected void onStop() {
120120
121121
// save edits
122122
editor.apply();
123-
}
123+
}*/
124124

125125
/**
126126
* Attempts to connect.
@@ -224,8 +224,22 @@ public void onAnimationEnd(Animator animation) {
224224
}
225225

226226
private void startDrawActivity() {
227+
228+
// get user
229+
User user = Manager.instance(getApplicationContext()).getUser();
230+
String url = Manager.instance(getApplicationContext()).getUrl();
231+
232+
// edit settings
233+
SharedPreferences settings = getPreferences(MODE_PRIVATE);
234+
SharedPreferences.Editor editor = settings.edit();
235+
editor.putString("login", user.getLogin());
236+
editor.putString("url", url);
237+
editor.putInt("color", user.getColor());
238+
239+
// save edits
240+
editor.apply();
241+
227242
Intent intent = new Intent(this, WorkspacesListActivity.class);
228-
//Intent intent = new Intent(this, DrawActivity.class);
229243
startActivity(intent);
230244
}
231245

@@ -254,5 +268,11 @@ private void showColorPickerDialog() {
254268
private void updateColorPickerButton(int color){
255269
mColorPickerButton.setBackgroundColor(color);
256270
}
271+
272+
@Override
273+
protected void onResume() {
274+
super.onResume();
275+
Manager.instance(getApplicationContext()).getLogged().set(false);
276+
}
257277
}
258278

Colladia/app/src/main/java/com/ia04nf28/colladia/WorkspacesListActivity.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,19 @@ public void onClick(DialogInterface di, int i) {
166166
}
167167

168168
private void updateAdapter(List<String> list){
169-
listView.setAdapter(new ArrayAdapter<String>(this,R.layout.list_workspaces,list));
169+
listView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_workspaces, list));
170170
}
171171

172172

173173
@Override
174-
protected void onDestroy() {
175-
super.onDestroy();
176-
Manager.instance(getApplicationContext()).quitServer();
174+
protected void onResume() {
175+
super.onResume();
176+
Manager.instance(getApplicationContext()).joinServer();
177177
}
178178

179-
179+
@Override
180+
protected void onPause() {
181+
super.onPause();
182+
Manager.instance(getApplicationContext()).quitServer();
183+
}
180184
}

Colladia/app/src/main/java/com/ia04nf28/colladia/model/Manager.java

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ public void login(User user, String url) {
152152
// TODO check url
153153
// TODO if url valid
154154

155+
joinServer();
156+
157+
}
158+
159+
public void joinServer(){
155160
if(requestTimer!=null) {
156161
requestTimer.cancel();
157162
requestTimer = new Timer();
@@ -160,24 +165,31 @@ public void login(User user, String url) {
160165
// end of if url valid
161166
}
162167

163-
164-
public void joinWorkspace(){
165-
requestTimerElements.schedule(createElementsTask(), 0, delayRequestElements);
166-
}
167-
168-
public void quitWorkspace(){
169-
requestTimerElements.cancel();
170-
requestTimerElements = new Timer();
171-
lastClock = "0";
172-
currentDiagram = null;
168+
public void joinWorkspace() {
169+
if (getCurrentDiagram() != null) {
170+
if (requestTimerElements != null) {
171+
requestTimerElements.cancel();
172+
requestTimerElements = new Timer();
173+
lastClock = "0";
174+
}
175+
requestTimerElements.schedule(createElementsTask(), 0, delayRequestElements);
176+
}
173177
}
174178

175179
public void quitServer(){
176-
logged.set(false);
177-
requestTimer.cancel();
178-
requestTimer = new Timer();
180+
if(requestTimer!=null) {
181+
requestTimer.cancel();
182+
requestTimer = new Timer();
183+
}
179184
}
180185

186+
public void quitWorkspace() {
187+
if(requestTimerElements!=null) {
188+
requestTimerElements.cancel();
189+
requestTimerElements = new Timer();
190+
lastClock = "0";
191+
}
192+
}
181193

182194
/**
183195
* Method that handle every response from the server
@@ -188,11 +200,6 @@ private void responseRequestHandler(String responseRequest){
188200
JSONObject mainObject = new JSONObject(responseRequest);
189201
if (mainObject.getString(STATUS_FIELD).equalsIgnoreCase(STATUS_OK)){
190202
Log.d(TAG, "Request success "+responseRequest );
191-
// if first response
192-
if (!logged.get())
193-
{
194-
logged.set(true);
195-
}
196203
if(mainObject.has(CLOCK_FIELD))
197204
lastClock = mainObject.getString(CLOCK_FIELD);
198205

@@ -306,7 +313,20 @@ private void requestDiagrams() {
306313
Requestator.instance(context).getDiagramsList(new Response.Listener<String>() {
307314
@Override
308315
public void onResponse(String s) {
309-
responseRequestHandler(s);
316+
try {
317+
JSONObject mainObject = new JSONObject(s);
318+
if (mainObject.getString(STATUS_FIELD).equalsIgnoreCase(STATUS_OK)) {
319+
if (!logged.get())
320+
{
321+
logged.set(true);
322+
}
323+
responseRequestHandler(s);
324+
}
325+
} catch (JSONException e) {
326+
e.printStackTrace();
327+
}
328+
329+
310330
}
311331
});
312332
}

0 commit comments

Comments
 (0)