mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-11 04:25:53 +00:00
Implement mPendingRunConditions in SettingsActivity
to queue run condition changes until the user leaves the preferences screen after making changes. (fixes #1196)
This commit is contained in:
parent
6579e2ea94
commit
84dfbf9a6b
2 changed files with 36 additions and 17 deletions
|
@ -99,6 +99,7 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
@Inject NotificationHandler mNotificationHandler;
|
||||
@Inject SharedPreferences mPreferences;
|
||||
|
||||
private Preference mCategoryRunConditions;
|
||||
private CheckBoxPreference mAlwaysRunInBackground;
|
||||
private ListPreference mPowerSource;
|
||||
private CheckBoxPreference mRunOnMobileData;
|
||||
|
@ -140,6 +141,12 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
|
||||
private Boolean mPendingConfig = false;
|
||||
|
||||
/**
|
||||
* Indicates if run conditions were changed and need to be
|
||||
* re-evaluated when the user leaves the preferences screen.
|
||||
*/
|
||||
private Boolean mPendingRunConditions = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -227,10 +234,11 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
|
||||
mRunOnMeteredWifi.setEnabled(mRunOnWifi.isChecked());
|
||||
mWifiSsidWhitelist.setEnabled(mRunOnWifi.isChecked());
|
||||
setPreferenceCategoryChangeListener(findPreference("category_run_conditions"), this);
|
||||
|
||||
mCategorySyncthingOptions = findPreference("category_syncthing_options");
|
||||
setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange);
|
||||
mCategoryRunConditions = findPreference("category_run_conditions");
|
||||
setPreferenceCategoryChangeListener(mCategoryRunConditions, this::onRunConditionPreferenceChange);
|
||||
|
||||
exportConfig.setOnPreferenceClickListener(this);
|
||||
importConfig.setOnPreferenceClickListener(this);
|
||||
|
@ -354,6 +362,28 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean onRunConditionPreferenceChange(Preference preference, Object o) {
|
||||
switch (preference.getKey()) {
|
||||
case Constants.PREF_POWER_SOURCE:
|
||||
mPowerSource.setValue(o.toString());
|
||||
preference.setSummary(mPowerSource.getEntry());
|
||||
break;
|
||||
case Constants.PREF_RUN_ON_WIFI:
|
||||
mRunOnMeteredWifi.setEnabled((Boolean) o);
|
||||
mWifiSsidWhitelist.setEnabled((Boolean) o);
|
||||
break;
|
||||
case Constants.PREF_WIFI_SSID_WHITELIST:
|
||||
String wifiSsidSummary = TextUtils.join(", ", (Set<String>) o);
|
||||
preference.setSummary(TextUtils.isEmpty(wifiSsidSummary) ?
|
||||
getString(R.string.run_on_all_wifi_networks) :
|
||||
getString(R.string.run_on_whitelisted_wifi_networks, wifiSsidSummary)
|
||||
);
|
||||
break;
|
||||
}
|
||||
mPendingRunConditions = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onSyncthingPreferenceChange(Preference preference, Object o) {
|
||||
Splitter splitter = Splitter.on(",").trimResults().omitEmptyStrings();
|
||||
switch (preference.getKey()) {
|
||||
|
@ -432,6 +462,11 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
mPendingConfig = false;
|
||||
}
|
||||
}
|
||||
if (mPendingRunConditions) {
|
||||
if (mSyncthingService != null) {
|
||||
mSyncthingService.reEvaluateRunConditions();
|
||||
}
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -442,21 +477,6 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
switch (preference.getKey()) {
|
||||
case Constants.PREF_POWER_SOURCE:
|
||||
mPowerSource.setValue(o.toString());
|
||||
preference.setSummary(mPowerSource.getEntry());
|
||||
break;
|
||||
case Constants.PREF_RUN_ON_WIFI:
|
||||
mRunOnMeteredWifi.setEnabled((Boolean) o);
|
||||
mWifiSsidWhitelist.setEnabled((Boolean) o);
|
||||
break;
|
||||
case Constants.PREF_WIFI_SSID_WHITELIST:
|
||||
String wifiSsidSummary = TextUtils.join(", ", (Set<String>) o);
|
||||
preference.setSummary(TextUtils.isEmpty(wifiSsidSummary) ?
|
||||
getString(R.string.run_on_all_wifi_networks) :
|
||||
getString(R.string.run_on_whitelisted_wifi_networks, wifiSsidSummary)
|
||||
);
|
||||
break;
|
||||
case Constants.PREF_DEBUG_FACILITIES_ENABLED:
|
||||
mPendingConfig = true;
|
||||
break;
|
||||
|
|
|
@ -15,7 +15,6 @@ import android.net.wifi.WifiManager;
|
|||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
|
Loading…
Reference in a new issue