mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Save and restore folder/device settings on screen rotate (fixes #152).
This commit is contained in:
parent
8d0518fa09
commit
560d7bf97a
3 changed files with 48 additions and 15 deletions
|
@ -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<RestApi.Device> devices = mSyncthingService.getApi().getDevices();
|
||||
|
|
|
@ -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<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();
|
||||
|
|
|
@ -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<String, String> mParams = new HashMap<>();
|
||||
|
||||
public String getType() {
|
||||
|
|
Loading…
Reference in a new issue