From 573a1de326a2dfa113db6ecc5ac3c3e011d400fd Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Sat, 17 Jun 2023 12:16:53 +0200 Subject: [PATCH] Remove incorrect assumption that event data is always a map (fixes #1884) (#1917) --- .../nutomic/syncthingandroid/model/Event.java | 2 +- .../service/EventProcessor.java | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/model/Event.java b/app/src/main/java/com/nutomic/syncthingandroid/model/Event.java index eb563955..592fd002 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/model/Event.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/model/Event.java @@ -8,6 +8,6 @@ public class Event { public int globalID; public String type; public String time; - public Map data; + public Object data; } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java b/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java index fff8c583..6b02ed40 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/EventProcessor.java @@ -99,6 +99,10 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener */ @Override public void onEvent(Event event) { + Map mapData = null; + try { + mapData = (Map) event.data; + } catch (ClassCastException e) { } switch (event.type) { case "ConfigSaved": if (mApi != null) { @@ -107,30 +111,30 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener } break; case "PendingDevicesChanged": - mapNullable((List>) event.data.get("added"), this::onPendingDevicesChanged); + mapNullable((List>) mapData.get("added"), this::onPendingDevicesChanged); break; case "FolderCompletion": CompletionInfo completionInfo = new CompletionInfo(); - completionInfo.completion = (Double) event.data.get("completion"); + completionInfo.completion = (Double) mapData.get("completion"); mApi.setCompletionInfo( - (String) event.data.get("device"), // deviceId - (String) event.data.get("folder"), // folderId + (String) mapData.get("device"), // deviceId + (String) mapData.get("folder"), // folderId completionInfo ); break; case "PendingFoldersChanged": - mapNullable((List>) event.data.get("added"), this::onPendingFoldersChanged); + mapNullable((List>) mapData.get("added"), this::onPendingFoldersChanged); break; case "ItemFinished": - String folder = (String) event.data.get("folder"); + String folder = (String) mapData.get("folder"); String folderPath = null; for (Folder f : mApi.getFolders()) { if (f.id.equals(folder)) { folderPath = f.path; } } - File updatedFile = new File(folderPath, (String) event.data.get("item")); - if (!"delete".equals(event.data.get("action"))) { + File updatedFile = new File(folderPath, (String) mapData.get("item")); + if (!"delete".equals(mapData.get("action"))) { Log.i(TAG, "Rescanned file via MediaScanner: " + updatedFile.toString()); MediaScannerConnection.scanFile(mContext, new String[]{updatedFile.getPath()}, null, null);