1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Add options button "undo ingoring devices and folders" (fixes #938) (#1185)

This commit is contained in:
Catfriend1 2018-07-18 19:11:11 +02:00 committed by Audrius Butkevicius
parent 765bc4a984
commit 6ead66b359
4 changed files with 58 additions and 16 deletions

View file

@ -81,6 +81,7 @@ public class SettingsActivity extends SyncthingActivity {
private static final String TAG = "SettingsFragment"; private static final String TAG = "SettingsFragment";
private static final String KEY_EXPORT_CONFIG = "export_config"; private static final String KEY_EXPORT_CONFIG = "export_config";
private static final String KEY_IMPORT_CONFIG = "import_config"; private static final String KEY_IMPORT_CONFIG = "import_config";
private static final String KEY_UNDO_IGNORED_DEVICES_FOLDERS = "undo_ignored_devices_folders";
private static final String KEY_ST_RESET_DATABASE = "st_reset_database"; private static final String KEY_ST_RESET_DATABASE = "st_reset_database";
private static final String KEY_ST_RESET_DELTAS = "st_reset_deltas"; private static final String KEY_ST_RESET_DELTAS = "st_reset_deltas";
@ -123,7 +124,7 @@ public class SettingsActivity extends SyncthingActivity {
private Options mOptions; private Options mOptions;
private Config.Gui mGui; private Config.Gui mGui;
private Boolean mRequireRestart = false; private Boolean mPendingConfig = false;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -193,6 +194,7 @@ public class SettingsActivity extends SyncthingActivity {
Preference exportConfig = findPreference("export_config"); Preference exportConfig = findPreference("export_config");
Preference importConfig = findPreference("import_config"); Preference importConfig = findPreference("import_config");
Preference undoIgnoredDevicesFolders = findPreference(KEY_UNDO_IGNORED_DEVICES_FOLDERS);
Preference debugFacilitiesEnabled = findPreference(Constants.PREF_DEBUG_FACILITIES_ENABLED); Preference debugFacilitiesEnabled = findPreference(Constants.PREF_DEBUG_FACILITIES_ENABLED);
Preference environmentVariables = findPreference("environment_variables"); Preference environmentVariables = findPreference("environment_variables");
Preference stResetDatabase = findPreference("st_reset_database"); Preference stResetDatabase = findPreference("st_reset_database");
@ -216,6 +218,7 @@ public class SettingsActivity extends SyncthingActivity {
exportConfig.setOnPreferenceClickListener(this); exportConfig.setOnPreferenceClickListener(this);
importConfig.setOnPreferenceClickListener(this); importConfig.setOnPreferenceClickListener(this);
undoIgnoredDevicesFolders.setOnPreferenceClickListener(this);
debugFacilitiesEnabled.setOnPreferenceChangeListener(this); debugFacilitiesEnabled.setOnPreferenceChangeListener(this);
environmentVariables.setOnPreferenceChangeListener(this); environmentVariables.setOnPreferenceChangeListener(this);
stResetDatabase.setOnPreferenceClickListener(this); stResetDatabase.setOnPreferenceClickListener(this);
@ -369,17 +372,17 @@ public class SettingsActivity extends SyncthingActivity {
} }
mApi.editSettings(mGui, mOptions); mApi.editSettings(mGui, mOptions);
mRequireRestart = true; mPendingConfig = true;
return true; return true;
} }
@Override @Override
public void onStop() { public void onStop() {
if (mRequireRestart) { if (mPendingConfig) {
if (mSyncthingService != null && mApi != null && if (mSyncthingService != null && mApi != null &&
mSyncthingService.getCurrentState() != SyncthingService.State.DISABLED) { mSyncthingService.getCurrentState() != SyncthingService.State.DISABLED) {
mApi.saveConfigAndRestart(); mApi.saveConfigAndRestart();
mRequireRestart = false; mPendingConfig = false;
} }
} }
super.onStop(); super.onStop();
@ -410,11 +413,11 @@ public class SettingsActivity extends SyncthingActivity {
mSyncOnlyOnSSIDs.setEnabled((Boolean) o); mSyncOnlyOnSSIDs.setEnabled((Boolean) o);
break; break;
case Constants.PREF_DEBUG_FACILITIES_ENABLED: case Constants.PREF_DEBUG_FACILITIES_ENABLED:
mRequireRestart = true; mPendingConfig = true;
break; break;
case Constants.PREF_ENVIRONMENT_VARIABLES: case Constants.PREF_ENVIRONMENT_VARIABLES:
if (((String) o).matches("^(\\w+=[\\w:/\\.]+)?( \\w+=[\\w:/\\.]+)*$")) { if (((String) o).matches("^(\\w+=[\\w:/\\.]+)?( \\w+=[\\w:/\\.]+)*$")) {
mRequireRestart = true; mPendingConfig = true;
} }
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)
@ -423,18 +426,18 @@ public class SettingsActivity extends SyncthingActivity {
} }
break; break;
case Constants.PREF_USE_WAKE_LOCK: case Constants.PREF_USE_WAKE_LOCK:
mRequireRestart = true; mPendingConfig = true;
break; break;
case Constants.PREF_USE_TOR: case Constants.PREF_USE_TOR:
mSocksProxyAddress.setEnabled(!(Boolean) o); mSocksProxyAddress.setEnabled(!(Boolean) o);
mHttpProxyAddress.setEnabled(!(Boolean) o); mHttpProxyAddress.setEnabled(!(Boolean) o);
mRequireRestart = true; mPendingConfig = true;
break; break;
case Constants.PREF_SOCKS_PROXY_ADDRESS: case Constants.PREF_SOCKS_PROXY_ADDRESS:
if (o.toString().trim().equals(mPreferences.getString(Constants.PREF_SOCKS_PROXY_ADDRESS, ""))) if (o.toString().trim().equals(mPreferences.getString(Constants.PREF_SOCKS_PROXY_ADDRESS, "")))
return false; return false;
if (handleSocksProxyPreferenceChange(preference, o.toString().trim())) { if (handleSocksProxyPreferenceChange(preference, o.toString().trim())) {
mRequireRestart = true; mPendingConfig = true;
} else { } else {
return false; return false;
} }
@ -443,7 +446,7 @@ public class SettingsActivity extends SyncthingActivity {
if (o.toString().trim().equals(mPreferences.getString(Constants.PREF_HTTP_PROXY_ADDRESS, ""))) if (o.toString().trim().equals(mPreferences.getString(Constants.PREF_HTTP_PROXY_ADDRESS, "")))
return false; return false;
if (handleHttpProxyPreferenceChange(preference, o.toString().trim())) { if (handleHttpProxyPreferenceChange(preference, o.toString().trim())) {
mRequireRestart = true; mPendingConfig = true;
} else { } else {
return false; return false;
} }
@ -464,7 +467,7 @@ public class SettingsActivity extends SyncthingActivity {
new TestRootTask(this).execute(); new TestRootTask(this).execute();
} else { } else {
new Thread(() -> Util.fixAppDataPermissions(getActivity())).start(); new Thread(() -> Util.fixAppDataPermissions(getActivity())).start();
mRequireRestart = true; mPendingConfig = true;
} }
return true; return true;
case KEY_EXPORT_CONFIG: case KEY_EXPORT_CONFIG:
@ -498,6 +501,25 @@ public class SettingsActivity extends SyncthingActivity {
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
.show(); .show();
return true; return true;
case KEY_UNDO_IGNORED_DEVICES_FOLDERS:
new AlertDialog.Builder(getActivity())
.setMessage(R.string.undo_ignored_devices_folders_question)
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
if (mApi == null) {
Toast.makeText(getActivity(),
getString(R.string.generic_error) + getString(R.string.syncthing_disabled_title),
Toast.LENGTH_SHORT).show();
return;
}
mApi.undoIgnoredDevicesAndFolders();
mPendingConfig = true;
Toast.makeText(getActivity(),
getString(R.string.undo_ignored_devices_folders_done),
Toast.LENGTH_SHORT).show();
})
.setNegativeButton(android.R.string.no, null)
.show();
return true;
case KEY_ST_RESET_DATABASE: case KEY_ST_RESET_DATABASE:
intent = new Intent(getActivity(), SyncthingService.class) intent = new Intent(getActivity(), SyncthingService.class)
.setAction(SyncthingService.ACTION_RESET_DATABASE); .setAction(SyncthingService.ACTION_RESET_DATABASE);
@ -571,7 +593,7 @@ public class SettingsActivity extends SyncthingActivity {
return; return;
} }
if (haveRoot) { if (haveRoot) {
settingsFragment.mRequireRestart = true; settingsFragment.mPendingConfig = true;
settingsFragment.mUseRoot.setChecked(true); settingsFragment.mUseRoot.setChecked(true);
} else { } else {
Toast.makeText(settingsFragment.getActivity(), R.string.toast_root_denied, Toast.LENGTH_SHORT) Toast.makeText(settingsFragment.getActivity(), R.string.toast_root_denied, Toast.LENGTH_SHORT)

View file

@ -269,6 +269,15 @@ public class RestApi {
} }
} }
/**
* Undo ignoring devices and folders.
*/
public void undoIgnoredDevicesAndFolders() {
Log.d(TAG, "Undo ignoring devices and folders ...");
mConfig.ignoredDevices.clear();
mConfig.ignoredFolders.clear();
}
/** /**
* Override folder changes. This is the same as hitting * Override folder changes. This is the same as hitting
* the "override changes" button from the web UI. * the "override changes" button from the web UI.

View file

@ -20,6 +20,7 @@ Please report any problems you encounter via Github.</string>
<!-- Generic texts used everywhere --> <!-- Generic texts used everywhere -->
<string name="generic_example">Example</string> <string name="generic_example">Example</string>
<string name="generic_error">Error</string>
<string name="accept">Accept</string> <string name="accept">Accept</string>
@ -375,6 +376,11 @@ Please report any problems you encounter via Github.</string>
<string name="gui_address">GUI Listen Addresses</string> <string name="gui_address">GUI Listen Addresses</string>
<!-- Titles for the preference to undo ignored devices and folders -->
<string name="undo_ignored_devices_folders_title">Undo ignoring devices and folders</string>
<string name="undo_ignored_devices_folders_question">This will undo previous decisions to ignore devices and folders. Continue?</string>
<string name="undo_ignored_devices_folders_done">Successfully undone decisions.</string>
<string name="export_config">Export Configuration</string> <string name="export_config">Export Configuration</string>
<!-- Toast after entering invalid integer value --> <!-- Toast after entering invalid integer value -->

View file

@ -136,6 +136,11 @@
android:title="@string/usage_reporting" android:title="@string/usage_reporting"
android:persistent="false" /> android:persistent="false" />
<Preference
android:key="undo_ignored_devices_folders"
android:title="@string/undo_ignored_devices_folders_title"
android:singleLine="true" />
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen