From 02043095a6bb308a64774463434e925f5fdd893f Mon Sep 17 00:00:00 2001 From: Lode Hoste Date: Sat, 21 Mar 2015 22:55:19 +0100 Subject: [PATCH] Make sure the mFolder reference is valid (fixes #271). --- .../fragments/DeviceSettingsFragment.java | 2 +- .../fragments/FolderSettingsFragment.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java index 2b6b2fd6..0a8f73a7 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java @@ -151,7 +151,7 @@ public class DeviceSettingsFragment extends PreferenceFragment implements return; } mDevice = device; - mDeviceId.setOnPreferenceClickListener(this); // TODO is this needed? + mDeviceId.setOnPreferenceClickListener(this); } mSyncthingService.getApi().getConnections(DeviceSettingsFragment.this); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java index afa1329f..ce7ed458 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java @@ -10,6 +10,7 @@ import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.PreferenceScreen; import android.support.v4.preference.PreferenceFragment; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -43,6 +44,8 @@ public class FolderSettingsFragment extends PreferenceFragment */ public static final String EXTRA_REPO_ID = "folder_id"; + private static final String TAG = "FolderSettingsFragment"; + private static final String KEY_NODE_SHARED = "device_shared"; private SyncthingService mSyncthingService; @@ -98,7 +101,8 @@ public class FolderSettingsFragment extends PreferenceFragment if (mIsCreate) { if (savedInstanceState != null) { mFolder = (RestApi.Folder) savedInstanceState.getSerializable("folder"); - } else { + } + if (mFolder == null) { mFolder = new RestApi.Folder(); mFolder.ID = ""; mFolder.Path = ""; @@ -131,15 +135,22 @@ public class FolderSettingsFragment extends PreferenceFragment if (mIsCreate) { getActivity().setTitle(R.string.create_folder); } else { + RestApi.Folder folder = null; getActivity().setTitle(R.string.edit_folder); List folders = mSyncthingService.getApi().getFolders(); for (int i = 0; i < folders.size(); i++) { if (folders.get(i).ID.equals( getActivity().getIntent().getStringExtra(EXTRA_REPO_ID))) { - mFolder = folders.get(i); + folder = folders.get(i); break; } } + if (folder == null) { + Log.w(TAG, "Folder not found in API update"); + getActivity().finish(); + return; + } + mFolder = folder; } mFolderId.setText(mFolder.ID);