Skip to content

Commit 7dd59b7

Browse files
author
Brandyn A. White
committed
Fixed back button in card tree and fixed connection shutdown
Signed-off-by: Brandyn A. White <[email protected]>
1 parent 9d107e8 commit 7dd59b7

File tree

6 files changed

+35
-143
lines changed

6 files changed

+35
-143
lines changed
-34.8 KB
Binary file not shown.

android/WearScript/src/main/java/com/dappervision/wearscript/BackgroundService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ static public String getDefaultUrl() {
8787
return (new String(wsUrlArray)).trim();
8888
}
8989

90+
public boolean treeBack() {
91+
synchronized (lock) {
92+
if (cardTree == null || cardTree.isRootCurrent())
93+
return true;
94+
cardTree.back();
95+
return false;
96+
}
97+
}
98+
9099
public void updateActivityView(final String mode) {
91100
if (activity == null)
92101
return;

android/WearScript/src/main/java/com/dappervision/wearscript/SocketClient.java

Lines changed: 0 additions & 134 deletions
This file was deleted.

android/WearScript/src/main/java/com/dappervision/wearscript/WearScriptConnection.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ private void setDeviceChannels(String device, Value[] channels) {
176176

177177
public void connect(URI uri) {
178178
synchronized (this) {
179+
if (shutdown) {
180+
Log.w(TAG, "Trying to connect while shutdown");
181+
return;
182+
}
179183
Log.i(TAG, uri.toString());
180-
if (uri.equals(this.uri) && client.isConnected()) {
184+
if (uri.equals(this.uri) && connected) {
181185
onConnect();
182186
return;
183187
}
@@ -245,6 +249,7 @@ public void shutdown() {
245249
synchronized (this) {
246250
this.shutdown = true;
247251
disconnect();
252+
client.getHandlerThread().getLooper().quit();
248253
}
249254
}
250255

@@ -262,7 +267,7 @@ public void run() {
262267
while (true) {
263268
Log.w(TAG, "Lifecycle: Trying to reconnect...");
264269
synchronized (WearScriptConnection.this) {
265-
if (client.isConnected() || shutdown) {
270+
if (connected || shutdown) {
266271
reconnecting = false;
267272
break;
268273
}
@@ -281,7 +286,7 @@ public void run() {
281286
// NOTE(brandyn): This ensures that we at least leave this thread with one of...
282287
// 1.) socket connected (disconnect after this would trigger a reconnect)
283288
// 2.) another thread that will try again
284-
if (!client.isConnected() && !shutdown)
289+
if (!connected && !shutdown)
285290
reconnect();
286291
}
287292
}
@@ -313,20 +318,24 @@ public void onMessage(String s) {
313318
@Override
314319
public void onDisconnect(int i, String s) {
315320
Log.w(TAG, "Lifecycle: Underlying socket disconnected: i: " + i + " s: " + s);
316-
if (shutdown)
317-
return;
321+
synchronized (this) {
322+
connected = false;
323+
if (shutdown)
324+
return;
325+
}
318326
WearScriptConnection.this.onDisconnect();
319-
connected = false;
320327
reconnect();
321328
}
322329

323330
@Override
324331
public void onError(Exception e) {
325332
Log.w(TAG, "Lifecycle: Underlying socket errored: " + e.getLocalizedMessage());
326-
if (shutdown)
327-
return;
333+
synchronized (this) {
334+
connected = false;
335+
if (shutdown)
336+
return;
337+
}
328338
WearScriptConnection.this.onDisconnect();
329-
connected = false;
330339
reconnect();
331340
}
332341

android/WearScript/src/main/java/com/dappervision/wearscript/managers/ConnectionManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public void onEvent(ChannelUnsubscribeEvent e) {
106106

107107
public void shutdown() {
108108
synchronized (this) {
109+
super.shutdown();
109110
connection.shutdown();
110111
}
111112
}

android/WearScript/src/main/java/com/dappervision/wearscript/ui/ScriptActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public void onResume() {
110110
super.onResume();
111111
}
112112

113+
@Override
114+
public void onBackPressed() {
115+
Log.d(TAG, "Back pressed");
116+
if (bs == null || bs.treeBack())
117+
super.onBackPressed();
118+
}
119+
113120
public void onDestroy() {
114121
Log.i(TAG, "Lifecycle: ScriptActivity: onDestroy");
115122
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

0 commit comments

Comments
 (0)