From c961562c3c8bf715735c8ba71657ca7999904a90 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 7 Nov 2016 20:01:36 +0900 Subject: [PATCH] Fixed settings behaviour when Syncthing is disabled --- .../fragments/SettingsFragment.java | 17 ++++++++++++----- .../syncthingandroid/service/RestApi.java | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java index 539f1d05..26f2c5bf 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/SettingsFragment.java @@ -21,9 +21,9 @@ import com.nutomic.syncthingandroid.activities.SyncthingActivity; import com.nutomic.syncthingandroid.model.Config; import com.nutomic.syncthingandroid.model.Device; import com.nutomic.syncthingandroid.model.Options; -import com.nutomic.syncthingandroid.views.WifiSsidPreference; import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.service.SyncthingService; +import com.nutomic.syncthingandroid.views.WifiSsidPreference; import java.security.InvalidParameterException; import java.util.List; @@ -149,16 +149,23 @@ public class SettingsFragment extends PreferenceFragment public void onServiceConnected() { mSyncthingService = ((SyncthingActivity) getActivity()).getService(); mSyncthingService.registerOnApiChangeListener(this); - mGui = mSyncthingService.getApi().getGui(); - mOptions = mSyncthingService.getApi().getOptions(); + if (mSyncthingService.getApi().isConfigLoaded()) { + mGui = mSyncthingService.getApi().getGui(); + mOptions = mSyncthingService.getApi().getOptions(); + } } @Override public void onApiChange(SyncthingService.State currentState) { boolean enabled = currentState == SyncthingService.State.ACTIVE; - getPreferenceScreen().setEnabled(enabled); - if (!enabled) + if (!enabled || !mSyncthingService.getApi().isConfigLoaded()) { + PreferenceScreen ps = getPreferenceScreen(); + for (int i = 0; i < ps.getPreferenceCount(); i++) { + Preference p = ps.getPreference(i); + p.setEnabled("category_run_conditions".equals(p.getKey())); + } return; + } mApi = mSyncthingService.getApi(); mSyncthingVersion.setSummary(mApi.getVersion()); diff --git a/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java index 608d56c3..b506fa43 100644 --- a/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java @@ -326,6 +326,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, }).execute(); } + public boolean isConfigLoaded() { + return mConfig != null; + } + /** * Requests and parses system version information. */