mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-25 19:35:53 +00:00
WIP - Better run conditions UI
This commit is contained in:
parent
634d09c5a2
commit
6d9f9dea80
6 changed files with 82 additions and 41 deletions
|
@ -89,7 +89,7 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
@Inject SharedPreferences mPreferences;
|
||||
|
||||
private CheckBoxPreference mAlwaysRunInBackground;
|
||||
private CheckBoxPreference mSyncOnlyCharging;
|
||||
private ListPreference mPowerSource;
|
||||
private CheckBoxPreference mSyncOnlyWifi;
|
||||
private WifiSsidPreference mSyncOnlyOnSSIDs;
|
||||
|
||||
|
@ -147,15 +147,13 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
PreferenceScreen screen = getPreferenceScreen();
|
||||
mAlwaysRunInBackground =
|
||||
(CheckBoxPreference) findPreference(Constants.PREF_ALWAYS_RUN_IN_BACKGROUND);
|
||||
mSyncOnlyCharging =
|
||||
(CheckBoxPreference) findPreference(Constants.PREF_SYNC_ONLY_CHARGING);
|
||||
mPowerSource =
|
||||
(ListPreference) findPreference(Constants.PREF_POWER_SOURCE);
|
||||
mSyncOnlyWifi =
|
||||
(CheckBoxPreference) findPreference(Constants.PREF_SYNC_ONLY_WIFI);
|
||||
mSyncOnlyOnSSIDs =
|
||||
(WifiSsidPreference) findPreference(Constants.PREF_SYNC_ONLY_WIFI_SSIDS);
|
||||
|
||||
mSyncOnlyCharging.setEnabled(mAlwaysRunInBackground.isChecked());
|
||||
mSyncOnlyWifi.setEnabled(mAlwaysRunInBackground.isChecked());
|
||||
mSyncOnlyOnSSIDs.setEnabled(mSyncOnlyWifi.isChecked());
|
||||
|
||||
ListPreference languagePref = (ListPreference) findPreference(Languages.PREFERENCE_LANGUAGE);
|
||||
|
@ -236,6 +234,7 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
|
||||
/* Initialize summaries */
|
||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
screen.findPreference(Constants.PREF_POWER_SOURCE).setSummary(mPowerSource.getEntry());
|
||||
handleSocksProxyPreferenceChange(screen.findPreference(Constants.PREF_SOCKS_PROXY_ADDRESS), mPreferences.getString(Constants.PREF_SOCKS_PROXY_ADDRESS, ""));
|
||||
handleHttpProxyPreferenceChange(screen.findPreference(Constants.PREF_HTTP_PROXY_ADDRESS), mPreferences.getString(Constants.PREF_HTTP_PROXY_ADDRESS, ""));
|
||||
|
||||
|
@ -395,22 +394,9 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
switch (preference.getKey()) {
|
||||
case Constants.PREF_ALWAYS_RUN_IN_BACKGROUND:
|
||||
boolean value = (Boolean) o;
|
||||
mAlwaysRunInBackground.setSummary((value)
|
||||
? R.string.always_run_in_background_enabled
|
||||
: R.string.always_run_in_background_disabled);
|
||||
mSyncOnlyCharging.setEnabled(value);
|
||||
mSyncOnlyWifi.setEnabled(value);
|
||||
mSyncOnlyOnSSIDs.setEnabled(false);
|
||||
// Uncheck items when disabled, so it is clear they have no effect.
|
||||
if (!value) {
|
||||
mSyncOnlyCharging.setChecked(false);
|
||||
mSyncOnlyWifi.setChecked(false);
|
||||
}
|
||||
break;
|
||||
case Constants.PREF_SYNC_ONLY_WIFI:
|
||||
mSyncOnlyOnSSIDs.setEnabled((Boolean) o);
|
||||
case Constants.PREF_POWER_SOURCE:
|
||||
mPowerSource.setValue(o.toString());
|
||||
preference.setSummary(mPowerSource.getEntry());
|
||||
break;
|
||||
case Constants.PREF_DEBUG_FACILITIES_ENABLED:
|
||||
mPendingConfig = true;
|
||||
|
|
|
@ -13,7 +13,8 @@ public class Constants {
|
|||
public static final String PREF_ALWAYS_RUN_IN_BACKGROUND = "always_run_in_background";
|
||||
public static final String PREF_SYNC_ONLY_WIFI = "sync_only_wifi";
|
||||
public static final String PREF_SYNC_ONLY_WIFI_SSIDS = "sync_only_wifi_ssids_set";
|
||||
public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
|
||||
// to_be_deleted public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
|
||||
public static final String PREF_POWER_SOURCE = "power_source";
|
||||
public static final String PREF_RESPECT_BATTERY_SAVING = "respect_battery_saving";
|
||||
public static final String PREF_USE_ROOT = "use_root";
|
||||
public static final String PREF_NOTIFICATION_TYPE = "notification_type";
|
||||
|
|
|
@ -38,6 +38,10 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
|||
|
||||
private static final String TAG = "RunConditionMonitor";
|
||||
|
||||
private static final String POWER_SOURCE_AC_BATTERY = "ac_and_battery_power";
|
||||
private static final String POWER_SOURCE_AC = "ac_power";
|
||||
private static final String POWER_SOURCE_BATTERY = "battery_power";
|
||||
|
||||
public interface OnRunConditionChangedListener {
|
||||
void onRunConditionChanged(boolean shouldRun);
|
||||
}
|
||||
|
@ -95,7 +99,7 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
|||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
List<String> watched = Lists.newArrayList(
|
||||
Constants.PREF_SYNC_ONLY_CHARGING,
|
||||
Constants.PREF_POWER_SOURCE,
|
||||
Constants.PREF_SYNC_ONLY_WIFI, Constants.PREF_RESPECT_BATTERY_SAVING,
|
||||
Constants.PREF_SYNC_ONLY_WIFI_SSIDS);
|
||||
if (watched.contains(key)) {
|
||||
|
@ -152,7 +156,7 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
|||
boolean prefAlwaysRunInBackground = mPreferences.getBoolean(Constants.PREF_ALWAYS_RUN_IN_BACKGROUND, false);
|
||||
boolean prefRespectPowerSaving = mPreferences.getBoolean(Constants.PREF_RESPECT_BATTERY_SAVING, true);
|
||||
boolean prefRunOnlyOnWifi= mPreferences.getBoolean(Constants.PREF_SYNC_ONLY_WIFI, false);
|
||||
boolean prefRunOnlyWhenCharging = mPreferences.getBoolean(Constants.PREF_SYNC_ONLY_CHARGING, false);
|
||||
String prefPowerSource = mPreferences.getString(Constants.PREF_POWER_SOURCE, POWER_SOURCE_AC_BATTERY);
|
||||
Set<String> whitelistedWifiSsids = mPreferences.getStringSet(Constants.PREF_SYNC_ONLY_WIFI_SSIDS, new HashSet<>());
|
||||
boolean prefWifiWhitelistEnabled = !whitelistedWifiSsids.isEmpty();
|
||||
|
||||
|
@ -173,10 +177,23 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
|||
return true;
|
||||
}
|
||||
|
||||
// Run only when charging.
|
||||
if (prefRunOnlyWhenCharging && !isCharging()) {
|
||||
Log.v(TAG, "decideShouldRun: prefRunOnlyWhenCharging && !isCharging");
|
||||
return false;
|
||||
// PREF_POWER_SOURCE
|
||||
switch (prefPowerSource) {
|
||||
case POWER_SOURCE_AC:
|
||||
if (!isOnAcPower()) {
|
||||
Log.v(TAG, "decideShouldRun: POWER_SOURCE_AC && !isOnAcPower");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case POWER_SOURCE_BATTERY:
|
||||
if (isOnAcPower()) {
|
||||
Log.v(TAG, "decideShouldRun: POWER_SOURCE_BATTERY && isOnAcPower");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case POWER_SOURCE_AC_BATTERY:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Run only on wifi.
|
||||
|
@ -206,7 +223,7 @@ public class RunConditionMonitor implements SharedPreferences.OnSharedPreference
|
|||
/**
|
||||
* Functions for run condition information retrieval.
|
||||
*/
|
||||
private boolean isCharging() {
|
||||
private boolean isOnAcPower() {
|
||||
Intent batteryIntent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
||||
return status == BatteryManager.BATTERY_STATUS_CHARGING ||
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources translatable="false">
|
||||
|
||||
<!-- DeviceActivity -->
|
||||
<string-array name="compress_values">
|
||||
<item>never</item>
|
||||
<item>metadata</item>
|
||||
<item>always</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Preference screen -->
|
||||
<string-array name="power_source_values">
|
||||
<item>ac_and_battery_power</item>
|
||||
<item>ac_power</item>
|
||||
<item>battery_power</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="notification_type_entry_values">
|
||||
<item>normal</item>
|
||||
<item>low_priority</item>
|
||||
|
|
|
@ -285,15 +285,27 @@ Please report any problems you encounter via Github.</string>
|
|||
<string name="category_debug">Debug</string>
|
||||
<string name="category_experimental">Experimental</string>
|
||||
|
||||
<string name="always_run_in_background">Always run in background</string>
|
||||
<!-- Preference screen - Run conditions -->
|
||||
<string name="always_run_in_background">to_be_deleted</string>
|
||||
<string name="always_run_in_background_enabled">to_be_deleted</string>
|
||||
<string name="always_run_in_background_disabled">to_be_deleted</string>
|
||||
<string name="sync_only_charging">to_be_deleted</string>
|
||||
|
||||
<!-- Preference summary in case it is enabled -->
|
||||
<string name="always_run_in_background_enabled">Syncthing always runs in the background, according to preferences below.</string>
|
||||
<string name="service_settings_title">Service setting</string>
|
||||
<string name="service_settings_summary">Running Syncthing as a service adds a persistent notification to prevent it from being ended by android. Checking this option starts syncthing automatically when the phone boots.</string>
|
||||
|
||||
<!-- Preference summary in case it is disabled -->
|
||||
<string name="always_run_in_background_disabled">Syncthing only runs when explicitly started, and can be stopped by menu button.</string>
|
||||
<string name="run_as_background_service">Run as background service</string>
|
||||
|
||||
<string name="sync_only_charging">Run only when charging</string>
|
||||
<string name="run_conditions_title">Run Conditions</string>
|
||||
<string name="run_conditions_summary">Use the following options to decide when the syncthing UI and syncing will be available.</string>
|
||||
|
||||
<string name="power_source_title">Run when device powered by</string>
|
||||
|
||||
<string-array name="power_source_entries">
|
||||
<item>AC and battery power</item>
|
||||
<item>AC power</item>
|
||||
<item>Battery power</item>
|
||||
</string-array>
|
||||
|
||||
<string name="sync_only_wifi">Run only on wifi</string>
|
||||
|
||||
|
|
|
@ -5,16 +5,33 @@
|
|||
android:title="@string/category_run_conditions"
|
||||
android:key="category_run_conditions">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="always_run_in_background"
|
||||
android:title="@string/always_run_in_background"
|
||||
android:defaultValue="false" />
|
||||
<Preference
|
||||
android:key="static_service_settings"
|
||||
android:persistent="false"
|
||||
android:selectable="false"
|
||||
android:title="@string/service_settings_title"
|
||||
android:summary="@string/service_settings_summary"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="sync_only_charging"
|
||||
android:title="@string/sync_only_charging"
|
||||
android:key="always_run_in_background"
|
||||
android:title="@string/run_as_background_service"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<Preference
|
||||
android:key="static_run_conditions"
|
||||
android:persistent="false"
|
||||
android:selectable="false"
|
||||
android:title="@string/run_conditions_title"
|
||||
android:summary="@string/run_conditions_summary"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="power_source"
|
||||
android:title="@string/power_source_title"
|
||||
android:entryValues="@array/power_source_values"
|
||||
android:entries="@array/power_source_entries"
|
||||
android:summary="@null"
|
||||
android:defaultValue="ac_and_battery_power" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="sync_only_wifi"
|
||||
android:title="@string/sync_only_wifi"
|
||||
|
|
Loading…
Reference in a new issue