mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-22 12:21:15 +00:00
This commit is contained in:
parent
5c04dab7b2
commit
892fdea2ea
5 changed files with 33 additions and 7 deletions
|
@ -11,6 +11,7 @@ import android.preference.CheckBoxPreference;
|
|||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
@ -101,7 +102,8 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
@Inject NotificationHandler mNotificationHandler;
|
||||
@Inject SharedPreferences mPreferences;
|
||||
|
||||
private Preference mCategoryRunConditions;
|
||||
private PreferenceGroup mCategoryRunConditions;
|
||||
private CheckBoxPreference mRunConditions;
|
||||
private CheckBoxPreference mStartServiceOnBoot;
|
||||
private ListPreference mPowerSource;
|
||||
private CheckBoxPreference mRunOnMobileData;
|
||||
|
@ -167,6 +169,8 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
|
||||
addPreferencesFromResource(R.xml.app_settings);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
mRunConditions =
|
||||
(CheckBoxPreference) findPreference(Constants.PREF_RUN_CONDITIONS);
|
||||
mStartServiceOnBoot =
|
||||
(CheckBoxPreference) findPreference(Constants.PREF_START_SERVICE_ON_BOOT);
|
||||
mPowerSource =
|
||||
|
@ -234,9 +238,15 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
|
||||
mCategorySyncthingOptions = findPreference("category_syncthing_options");
|
||||
setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange);
|
||||
mCategoryRunConditions = findPreference("category_run_conditions");
|
||||
mCategoryRunConditions = (PreferenceGroup) findPreference("category_run_conditions");
|
||||
setPreferenceCategoryChangeListener(mCategoryRunConditions, this::onRunConditionPreferenceChange);
|
||||
|
||||
if (!mRunConditions.isChecked()) {
|
||||
for (int index = 1; index < mCategoryRunConditions.getPreferenceCount(); ++index) {
|
||||
mCategoryRunConditions.getPreference(index).setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
exportConfig.setOnPreferenceClickListener(this);
|
||||
importConfig.setOnPreferenceClickListener(this);
|
||||
|
||||
|
@ -363,6 +373,16 @@ public class SettingsActivity extends SyncthingActivity {
|
|||
|
||||
public boolean onRunConditionPreferenceChange(Preference preference, Object o) {
|
||||
switch (preference.getKey()) {
|
||||
case Constants.PREF_RUN_CONDITIONS:
|
||||
boolean enabled = (Boolean) o;
|
||||
for (int index = 1; index < mCategoryRunConditions.getPreferenceCount(); ++index) {
|
||||
mCategoryRunConditions.getPreference(index).setEnabled(enabled);
|
||||
}
|
||||
if (enabled) {
|
||||
mRunOnMeteredWifi.setEnabled(mRunOnWifi.isChecked());
|
||||
mWifiSsidWhitelist.setEnabled(mRunOnWifi.isChecked());
|
||||
}
|
||||
break;
|
||||
case Constants.PREF_POWER_SOURCE:
|
||||
mPowerSource.setValue(o.toString());
|
||||
preference.setSummary(mPowerSource.getEntry());
|
||||
|
|
|
@ -14,6 +14,7 @@ public class Constants {
|
|||
|
||||
// Preferences - Run conditions
|
||||
public static final String PREF_START_SERVICE_ON_BOOT = "always_run_in_background";
|
||||
public static final String PREF_RUN_CONDITIONS = "static_run_conditions";
|
||||
public static final String PREF_RUN_ON_MOBILE_DATA = "run_on_mobile_data";
|
||||
public static final String PREF_RUN_ON_WIFI = "run_on_wifi";
|
||||
public static final String PREF_RUN_ON_METERED_WIFI = "run_on_metered_wifi";
|
||||
|
|
|
@ -169,6 +169,7 @@ public class RunConditionMonitor {
|
|||
*/
|
||||
private RunConditionCheckResult decideShouldRun() {
|
||||
// Get run conditions preferences.
|
||||
boolean prefRunConditions= mPreferences.getBoolean(Constants.PREF_RUN_CONDITIONS, false);
|
||||
boolean prefRunOnMobileData= mPreferences.getBoolean(Constants.PREF_RUN_ON_MOBILE_DATA, false);
|
||||
boolean prefRunOnWifi= mPreferences.getBoolean(Constants.PREF_RUN_ON_WIFI, true);
|
||||
boolean prefRunOnMeteredWifi= mPreferences.getBoolean(Constants.PREF_RUN_ON_METERED_WIFI, false);
|
||||
|
@ -179,6 +180,11 @@ public class RunConditionMonitor {
|
|||
boolean prefRespectPowerSaving = mPreferences.getBoolean(Constants.PREF_RESPECT_BATTERY_SAVING, true);
|
||||
boolean prefRespectMasterSync = mPreferences.getBoolean(Constants.PREF_RESPECT_MASTER_SYNC, false);
|
||||
|
||||
if (!prefRunConditions) {
|
||||
Log.v(TAG, "decideShouldRun: !runConditions");
|
||||
return SHOULD_RUN;
|
||||
}
|
||||
|
||||
List<BlockerReason> blockerReasons = new ArrayList<>();
|
||||
|
||||
// PREF_POWER_SOURCE
|
||||
|
|
|
@ -315,7 +315,7 @@ Please report any problems you encounter via Github.</string>
|
|||
<string name="category_experimental">Experimental</string>
|
||||
|
||||
<!-- Preference screen - Run conditions -->
|
||||
<string name="run_conditions_title">Run Conditions</string>
|
||||
<string name="run_conditions_title">Enable run conditions</string>
|
||||
<string name="run_conditions_summary">Use the following options to decide when Syncthing will run.</string>
|
||||
|
||||
<string name="run_on_mobile_data_title">Run on mobile data</string>
|
||||
|
|
|
@ -12,12 +12,11 @@
|
|||
android:title="@string/category_run_conditions"
|
||||
android:key="category_run_conditions">
|
||||
|
||||
<Preference
|
||||
<CheckBoxPreference
|
||||
android:key="static_run_conditions"
|
||||
android:persistent="false"
|
||||
android:selectable="false"
|
||||
android:title="@string/run_conditions_title"
|
||||
android:summary="@string/run_conditions_summary"/>
|
||||
android:summary="@string/run_conditions_summary"
|
||||
android:defaultValue="true" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="run_on_wifi"
|
||||
|
|
Loading…
Reference in a new issue