fix: compile errors - WatchBridge uses node.id (Node is public field); MainActivity wrap JSONObject.put in try/catch
This commit is contained in:
@@ -46,13 +46,15 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
if (s != null) {
|
if (s != null) {
|
||||||
runOnUiThread(() -> status.setText("状态: " + s.optString("model") + " / " + s.optString("cwd")));
|
runOnUiThread(() -> status.setText("状态: " + s.optString("model") + " / " + s.optString("cwd")));
|
||||||
JSONObject payload = new JSONObject();
|
JSONObject payload = new JSONObject();
|
||||||
|
JSONObject msg = new JSONObject();
|
||||||
|
try {
|
||||||
payload.put("model", s.optString("model"));
|
payload.put("model", s.optString("model"));
|
||||||
payload.put("running", s.optBoolean("running", false));
|
payload.put("running", s.optBoolean("running", false));
|
||||||
payload.put("activeSessionId", s.optString("activeSessionId"));
|
payload.put("activeSessionId", s.optString("activeSessionId"));
|
||||||
JSONObject msg = new JSONObject();
|
|
||||||
msg.put("type", "status");
|
msg.put("type", "status");
|
||||||
msg.put("payload", payload);
|
msg.put("payload", payload);
|
||||||
if (watchBridge != null) watchBridge.sendToWatch(msg.toString());
|
if (watchBridge != null) watchBridge.sendToWatch(msg.toString());
|
||||||
|
} catch (Exception ignore) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class WatchBridge {
|
|||||||
.addOnSuccessListener(nodes -> {
|
.addOnSuccessListener(nodes -> {
|
||||||
if (nodes != null && nodes.size() > 0) {
|
if (nodes != null && nodes.size() > 0) {
|
||||||
node = nodes.get(0);
|
node = nodes.get(0);
|
||||||
main.post(() -> listener.onWatchConnected(true, node.getId()));
|
main.post(() -> listener.onWatchConnected(true, node.id));
|
||||||
registerListener();
|
registerListener();
|
||||||
} else {
|
} else {
|
||||||
main.post(() -> listener.onWatchConnected(false, null));
|
main.post(() -> listener.onWatchConnected(false, null));
|
||||||
@@ -59,14 +59,14 @@ public class WatchBridge {
|
|||||||
main.post(() -> listener.onWatchMessage(json));
|
main.post(() -> listener.onWatchMessage(json));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
messageApi.addListener(node.getId(), l)
|
messageApi.addListener(node.id, l)
|
||||||
.addOnSuccessListener(ignore -> { })
|
.addOnSuccessListener(ignore -> { })
|
||||||
.addOnFailureListener(e -> main.post(() -> listener.onError("addListener: " + e.getMessage())));
|
.addOnFailureListener(e -> main.post(() -> listener.onError("addListener: " + e.getMessage())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToWatch(String json) {
|
public void sendToWatch(String json) {
|
||||||
if (node == null) return;
|
if (node == null) return;
|
||||||
messageApi.sendMessage(node.getId(), json.getBytes())
|
messageApi.sendMessage(node.id, json.getBytes())
|
||||||
.addOnSuccessListener(ignore -> { })
|
.addOnSuccessListener(ignore -> { })
|
||||||
.addOnFailureListener(e -> main.post(() -> listener.onError("sendMessage: " + e.getMessage())));
|
.addOnFailureListener(e -> main.post(() -> listener.onError("sendMessage: " + e.getMessage())));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user