From f9927aa6039c499204a78376ac5516a745e00507 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sat, 26 Jan 2019 18:12:05 +0100 Subject: [PATCH] FolderActivity/DeviceActivity: Fix restApi unavailable in onCreate() --- .../syncthingandroid/activities/DeviceActivity.java | 11 ++++++----- .../syncthingandroid/activities/FolderActivity.java | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java index 4182af96..7d085918 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/DeviceActivity.java @@ -223,8 +223,8 @@ public class DeviceActivity extends SyncthingActivity { // Edit mode. String passedId = getIntent().getStringExtra(EXTRA_DEVICE_ID); Log.d(TAG, "Initializing edit mode: deviceID=" + passedId); - RestApi restApi = getApi(); - List devices = mConfig.getDevices(restApi, false); + // getApi() is unavailable (onCreate > onPostCreate > onServiceConnected) + List devices = mConfig.getDevices(null, false); mDevice = null; for (Device currentDevice : devices) { if (currentDevice.deviceID.equals(passedId)) { @@ -237,9 +237,6 @@ public class DeviceActivity extends SyncthingActivity { finish(); return; } - if (restApi != null) { - restApi.getConnections(this::onReceiveConnections); - } mDeviceNeedsToUpdate = false; } } @@ -276,6 +273,10 @@ public class DeviceActivity extends SyncthingActivity { SyncthingServiceBinder syncthingServiceBinder = (SyncthingServiceBinder) iBinder; SyncthingService syncthingService = (SyncthingService) syncthingServiceBinder.getService(); syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0)); + RestApi restApi = syncthingService.getApi(); + if (restApi != null) { + restApi.getConnections(this::onReceiveConnections); + } } @Override diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java index cc38d3db..140d9457 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/FolderActivity.java @@ -235,8 +235,8 @@ public class FolderActivity extends SyncthingActivity { // Edit mode. String passedId = getIntent().getStringExtra(EXTRA_FOLDER_ID); Log.d(TAG, "Initializing edit mode: folder.id=" + passedId); - RestApi restApi = getApi(); - List folders = mConfig.getFolders(restApi); + // getApi() is unavailable (onCreate > onPostCreate > onServiceConnected) + List folders = mConfig.getFolders(null); mFolder = null; for (Folder currentFolder : folders) { if (currentFolder.id.equals(passedId)) { @@ -249,7 +249,7 @@ public class FolderActivity extends SyncthingActivity { finish(); return; } - mConfig.getFolderIgnoreList(restApi, mFolder, this::onReceiveFolderIgnoreList); + mConfig.getFolderIgnoreList(null, mFolder, this::onReceiveFolderIgnoreList); mFolderNeedsToUpdate = false; }