diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java index 68dfa246..9e0a8a2f 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/NodeSettingsFragment.java @@ -39,7 +39,6 @@ public class NodeSettingsFragment extends PreferenceFragment implements private SyncthingService mSyncthingService; - // FIXME: is null private RestApi.Node mNode; private Preference mNodeId; @@ -93,11 +92,13 @@ public class NodeSettingsFragment extends PreferenceFragment implements @Override public void onApiChange(SyncthingService.State currentState) { if (currentState != SyncthingService.State.ACTIVE) { - SyncthingService.showDisabledDialog(getActivity()); getActivity().finish(); return; } + if (getActivity() == null || getActivity().isFinishing()) + return; + if (mIsCreate) { getActivity().setTitle(R.string.add_node); mNode = new RestApi.Node(); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java index 6331fecd..adf2ad8f 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/RepoSettingsFragment.java @@ -52,7 +52,6 @@ public class RepoSettingsFragment extends PreferenceFragment private SyncthingService mSyncthingService; - // FIXME: is null private RestApi.Repo mRepo; private EditTextPreference mRepoId; @@ -102,11 +101,13 @@ public class RepoSettingsFragment extends PreferenceFragment @Override public void onApiChange(SyncthingService.State currentState) { if (currentState != SyncthingService.State.ACTIVE) { - SyncthingService.showDisabledDialog(getActivity()); getActivity().finish(); return; } + if (getActivity() == null || getActivity().isFinishing()) + return; + if (mIsCreate) { getActivity().setTitle(R.string.create_repo); mRepo = new RestApi.Repo(); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index 68905cde..b2b71585 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -739,7 +739,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener { /** * Updates or creates the given node. */ - public void editRepo(Repo repo, boolean create, Activity activity) { + public void editRepo(Repo repo, boolean create, Context context) { try { JSONArray repos = mConfig.getJSONArray("Repositories"); JSONObject r = null; @@ -777,7 +777,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener { params.put(key, repo.Versioning.getParams().get(key)); } r.put("Versioning", versioning); - configUpdated(activity); + configUpdated(context); } catch (JSONException e) { Log.w(TAG, "Failed to edit repo " + repo.ID + " at " + repo.Directory, e); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java index 1ea8138c..2897b12a 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java @@ -131,6 +131,7 @@ public class SyncthingService extends Service { ConfigXml config = new ConfigXml(SyncthingService.this); mApi = new RestApi(SyncthingService.this, config.getWebGuiUrl(), config.getApiKey()); + mCurrentState = State.STARTING; registerOnWebGuiAvailableListener(mApi); new PollWebGuiAvailableTask().execute(); }