1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 08:11:17 +00:00

Save and restore folder/device settings on screen rotate (fixes #152).

This commit is contained in:
Felix Ableitner 2014-10-12 17:58:58 +03:00
parent 8d0518fa09
commit 560d7bf97a
3 changed files with 48 additions and 15 deletions

View file

@ -88,6 +88,28 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
mCurrentAddress = findPreference("current_address"); mCurrentAddress = findPreference("current_address");
mCurrentAddress.setSummary("?"); 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 @Override
@ -107,12 +129,6 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
if (mIsCreate) { if (mIsCreate) {
getActivity().setTitle(R.string.add_device); 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 { } else {
getActivity().setTitle(R.string.edit_device); getActivity().setTitle(R.string.edit_device);
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(); List<RestApi.Device> devices = mSyncthingService.getApi().getDevices();

View file

@ -95,6 +95,28 @@ public class FolderSettingsFragment extends PreferenceFragment
mVersioning.setOnPreferenceChangeListener(this); mVersioning.setOnPreferenceChangeListener(this);
mVersioningKeep = (EditTextPreference) findPreference("versioning_keep"); mVersioningKeep = (EditTextPreference) findPreference("versioning_keep");
mVersioningKeep.setOnPreferenceChangeListener(this); 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 @Override
@ -109,12 +131,6 @@ public class FolderSettingsFragment extends PreferenceFragment
if (mIsCreate) { if (mIsCreate) {
getActivity().setTitle(R.string.create_folder); 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 { } else {
getActivity().setTitle(R.string.edit_folder); getActivity().setTitle(R.string.edit_folder);
List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders(); List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();

View file

@ -24,6 +24,7 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.Serializable;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -61,7 +62,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
*/ */
public static final String LOCAL_DEVICE_CONNECTIONS = "total"; public static final String LOCAL_DEVICE_CONNECTIONS = "total";
public static class Device { public static class Device implements Serializable {
public String Addresses; public String Addresses;
public String Name; public String Name;
public String DeviceID; public String DeviceID;
@ -78,7 +79,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public long sys; public long sys;
} }
public static class Folder { public static class Folder implements Serializable {
public String Path; public String Path;
public String ID; public String ID;
public String Invalid; public String Invalid;
@ -88,7 +89,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public Versioning Versioning; public Versioning Versioning;
} }
public static class Versioning { public static class Versioning implements Serializable {
protected final Map<String, String> mParams = new HashMap<>(); protected final Map<String, String> mParams = new HashMap<>();
public String getType() { public String getType() {