1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 20:31:16 +00:00

Don't disable all settings when Syncthing is disabled

This commit is contained in:
Felix Ableitner 2017-10-09 13:11:15 +09:00
parent 0b5649be98
commit cefd9dcfc0
3 changed files with 27 additions and 18 deletions

View file

@ -59,6 +59,7 @@ public class SettingsActivity extends SyncthingActivity {
private CheckBoxPreference mSyncOnlyWifi; private CheckBoxPreference mSyncOnlyWifi;
private WifiSsidPreference mSyncOnlyOnSSIDs; private WifiSsidPreference mSyncOnlyOnSSIDs;
private Preference mCategorySyncthingOptions;
private EditTextPreference mDeviceName; private EditTextPreference mDeviceName;
private EditTextPreference mListenAddresses; private EditTextPreference mListenAddresses;
private EditTextPreference mMaxRecvKbps; private EditTextPreference mMaxRecvKbps;
@ -71,6 +72,8 @@ public class SettingsActivity extends SyncthingActivity {
private EditTextPreference mAddress; private EditTextPreference mAddress;
private CheckBoxPreference mUrAccepted; private CheckBoxPreference mUrAccepted;
private Preference mCategoryBackup;
private CheckBoxPreference mUseRoot; private CheckBoxPreference mUseRoot;
private Preference mSyncthingVersion; private Preference mSyncthingVersion;
@ -134,6 +137,7 @@ public class SettingsActivity extends SyncthingActivity {
mAddress = (EditTextPreference) findPreference("address"); mAddress = (EditTextPreference) findPreference("address");
mUrAccepted = (CheckBoxPreference) findPreference("urAccepted"); mUrAccepted = (CheckBoxPreference) findPreference("urAccepted");
mCategoryBackup = findPreference("category_backup");
Preference exportConfig = findPreference("export_config"); Preference exportConfig = findPreference("export_config");
Preference importConfig = findPreference("import_config"); Preference importConfig = findPreference("import_config");
@ -152,8 +156,8 @@ public class SettingsActivity extends SyncthingActivity {
mSyncOnlyOnSSIDs.setEnabled(mSyncOnlyWifi.isChecked()); mSyncOnlyOnSSIDs.setEnabled(mSyncOnlyWifi.isChecked());
setPreferenceCategoryChangeListener(findPreference("category_run_conditions"), this); setPreferenceCategoryChangeListener(findPreference("category_run_conditions"), this);
setPreferenceCategoryChangeListener( mCategorySyncthingOptions = findPreference("category_syncthing_options");
findPreference("category_syncthing_options"), this::onSyncthingPreferenceChange); setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange);
exportConfig.setOnPreferenceClickListener(this); exportConfig.setOnPreferenceClickListener(this);
importConfig.setOnPreferenceClickListener(this); importConfig.setOnPreferenceClickListener(this);
@ -163,9 +167,9 @@ public class SettingsActivity extends SyncthingActivity {
stReset.setOnPreferenceClickListener(this); stReset.setOnPreferenceClickListener(this);
mUseRoot.setOnPreferenceClickListener(this); mUseRoot.setOnPreferenceClickListener(this);
useWakelock.setOnPreferenceChangeListener(this::onRequireRestart); useWakelock.setOnPreferenceChangeListener((p, o) -> requireRestart());
foregroundService.setOnPreferenceChangeListener(this::onRequireRestart); foregroundService.setOnPreferenceChangeListener((p, o) -> requireRestart());
useTor.setOnPreferenceChangeListener(this::onRequireRestart); useTor.setOnPreferenceChangeListener((p, o) -> requireRestart());
try { try {
appVersion.setSummary(getActivity().getPackageManager() appVersion.setSummary(getActivity().getPackageManager()
@ -195,14 +199,11 @@ public class SettingsActivity extends SyncthingActivity {
@Override @Override
public void onApiChange(SyncthingService.State currentState) { public void onApiChange(SyncthingService.State currentState) {
boolean syncthingActive = currentState == SyncthingService.State.ACTIVE; boolean syncthingActive = currentState == SyncthingService.State.ACTIVE;
boolean enableAllPrefs = syncthingActive && mSyncthingService.getApi().isConfigLoaded(); boolean isSyncthingRunning = syncthingActive && mSyncthingService.getApi().isConfigLoaded();
PreferenceScreen ps = getPreferenceScreen(); mCategorySyncthingOptions.setEnabled(isSyncthingRunning);
for (int i = 0; i < ps.getPreferenceCount(); i++) { mCategoryBackup.setEnabled(isSyncthingRunning);
Preference p = ps.getPreference(i);
p.setEnabled(enableAllPrefs || "category_run_conditions".equals(p.getKey()));
}
if (!enableAllPrefs) if (!isSyncthingRunning)
return; return;
mApi = mSyncthingService.getApi(); mApi = mSyncthingService.getApi();
@ -273,8 +274,11 @@ public class SettingsActivity extends SyncthingActivity {
return true; return true;
} }
public boolean onRequireRestart(Preference preference, Object o) { public boolean requireRestart() {
mSyncthingService.getApi().showRestartDialog(getActivity()); if (mSyncthingService.getCurrentState() != SyncthingService.State.DISABLED &&
mSyncthingService.getApi() != null) {
mSyncthingService.getApi().showRestartDialog(getActivity());
}
return true; return true;
} }
@ -304,7 +308,7 @@ public class SettingsActivity extends SyncthingActivity {
break; break;
case KEY_STTRACE: case KEY_STTRACE:
if (((String) o).matches("[0-9a-z, ]*")) if (((String) o).matches("[0-9a-z, ]*"))
mSyncthingService.getApi().showRestartDialog(getActivity()); requireRestart();
else { else {
Toast.makeText(getActivity(), R.string.toast_invalid_sttrace, Toast.LENGTH_SHORT) Toast.makeText(getActivity(), R.string.toast_invalid_sttrace, Toast.LENGTH_SHORT)
.show(); .show();
@ -313,7 +317,7 @@ public class SettingsActivity extends SyncthingActivity {
break; break;
case "environment_variables": case "environment_variables":
if (((String) o).matches("^(\\w+=[\\w:/\\.]+)?( \\w+=[\\w:/\\.]+)*$")) { if (((String) o).matches("^(\\w+=[\\w:/\\.]+)?( \\w+=[\\w:/\\.]+)*$")) {
mSyncthingService.getApi().showRestartDialog(getActivity()); requireRestart();
} }
else { else {
Toast.makeText(getActivity(), R.string.toast_invalid_environment_variables, Toast.LENGTH_SHORT) Toast.makeText(getActivity(), R.string.toast_invalid_environment_variables, Toast.LENGTH_SHORT)
@ -336,7 +340,7 @@ public class SettingsActivity extends SyncthingActivity {
new TestRootTask().execute(); new TestRootTask().execute();
} else { } else {
new Thread(() -> Util.fixAppDataPermissions(getActivity())).start(); new Thread(() -> Util.fixAppDataPermissions(getActivity())).start();
mSyncthingService.getApi().showRestartDialog(getActivity()); requireRestart();
} }
return true; return true;
case KEY_EXPORT_CONFIG: case KEY_EXPORT_CONFIG:
@ -402,7 +406,7 @@ public class SettingsActivity extends SyncthingActivity {
@Override @Override
protected void onPostExecute(Boolean haveRoot) { protected void onPostExecute(Boolean haveRoot) {
if (haveRoot) { if (haveRoot) {
mSyncthingService.getApi().showRestartDialog(getActivity()); requireRestart();
mUseRoot.setChecked(true); mUseRoot.setChecked(true);
} else { } else {
Toast.makeText(getActivity(), R.string.toast_root_denied, Toast.LENGTH_SHORT) Toast.makeText(getActivity(), R.string.toast_root_denied, Toast.LENGTH_SHORT)

View file

@ -425,6 +425,10 @@ public class SyncthingService extends Service implements
return sp.getBoolean(Constants.PREF_ALWAYS_RUN_IN_BACKGROUND, false); return sp.getBoolean(Constants.PREF_ALWAYS_RUN_IN_BACKGROUND, false);
} }
public State getCurrentState() {
return mCurrentState;
}
/** /**
* Exports the local config and keys to {@link Constants#EXPORT_PATH}. * Exports the local config and keys to {@link Constants#EXPORT_PATH}.
*/ */

View file

@ -133,6 +133,7 @@
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen
android:key="category_backup"
android:title="@string/category_backup"> android:title="@string/category_backup">
<Preference <Preference