diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java index 466a2698..f32a2404 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/DeviceSettingsFragment.java @@ -88,6 +88,28 @@ public class DeviceSettingsFragment extends PreferenceFragment implements mCurrentAddress = findPreference("current_address"); mCurrentAddress.setSummary("?"); } + + if (mIsCreate) { + if (savedInstanceState != null) { + mDevice = (RestApi.Device) savedInstanceState.getSerializable("device"); + } else { + mDevice = new RestApi.Device(); + mDevice.Name = ""; + mDevice.DeviceID = ""; + mDevice.Addresses = "dynamic"; + mDevice.Compression = true; + ((EditTextPreference) mDeviceId).setText(mDevice.DeviceID); + } + } + } + + /** + * Save current settings in case we are in create mode and they aren't yet stored in the config. + */ + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putSerializable("device", mDevice); } @Override @@ -107,12 +129,6 @@ public class DeviceSettingsFragment extends PreferenceFragment implements if (mIsCreate) { getActivity().setTitle(R.string.add_device); - mDevice = new RestApi.Device(); - mDevice.Name = ""; - mDevice.DeviceID = ""; - mDevice.Addresses = "dynamic"; - mDevice.Compression = true; - ((EditTextPreference) mDeviceId).setText(mDevice.DeviceID); } else { getActivity().setTitle(R.string.edit_device); List devices = mSyncthingService.getApi().getDevices(); diff --git a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java index 5f860152..5e704d11 100644 --- a/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java +++ b/src/main/java/com/nutomic/syncthingandroid/fragments/FolderSettingsFragment.java @@ -95,6 +95,28 @@ public class FolderSettingsFragment extends PreferenceFragment mVersioning.setOnPreferenceChangeListener(this); mVersioningKeep = (EditTextPreference) findPreference("versioning_keep"); mVersioningKeep.setOnPreferenceChangeListener(this); + + if (mIsCreate) { + if (savedInstanceState != null) { + mFolder = (RestApi.Folder) savedInstanceState.getSerializable("folder"); + } else { + mFolder = new RestApi.Folder(); + mFolder.ID = ""; + mFolder.Path = ""; + mFolder.RescanIntervalS = 86400; + mFolder.DeviceIds = new ArrayList<>(); + mFolder.Versioning = new RestApi.Versioning(); + } + } + } + + /** + * Save current settings in case we are in create mode and they aren't yet stored in the config. + */ + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putSerializable("folder", mFolder); } @Override @@ -109,12 +131,6 @@ public class FolderSettingsFragment extends PreferenceFragment if (mIsCreate) { getActivity().setTitle(R.string.create_folder); - mFolder = new RestApi.Folder(); - mFolder.ID = ""; - mFolder.Path = ""; - mFolder.RescanIntervalS = 86400; - mFolder.DeviceIds = new ArrayList<>(); - mFolder.Versioning = new RestApi.Versioning(); } else { getActivity().setTitle(R.string.edit_folder); List folders = mSyncthingService.getApi().getFolders(); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index d1183a7e..a951b6bf 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -24,6 +24,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.io.Serializable; import java.security.InvalidParameterException; import java.text.DecimalFormat; import java.util.ArrayList; @@ -61,7 +62,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, */ public static final String LOCAL_DEVICE_CONNECTIONS = "total"; - public static class Device { + public static class Device implements Serializable { public String Addresses; public String Name; public String DeviceID; @@ -78,7 +79,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, public long sys; } - public static class Folder { + public static class Folder implements Serializable { public String Path; public String ID; public String Invalid; @@ -88,7 +89,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, public Versioning Versioning; } - public static class Versioning { + public static class Versioning implements Serializable { protected final Map mParams = new HashMap<>(); public String getType() {