mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-09 03:37:03 +01:00
Add battery polling settings
This commit is contained in:
parent
6f7844418e
commit
bf16bf06c3
@ -40,6 +40,9 @@ public class DeviceSettingsPreferenceConst {
|
||||
public static final String PREF_BATTERY_NOTIFY_FULL_ENABLED = "battery_notify_full_enabled_";
|
||||
public static final String PREF_BATTERY_NOTIFY_FULL_THRESHOLD = "battery_notify_full_threshold_";
|
||||
|
||||
public static final String PREF_BATTERY_POLLING_ENABLE = "pref_battery_polling_enabled";
|
||||
public static final String PREF_BATTERY_POLLING_INTERVAL = "pref_battery_polling_interval";
|
||||
|
||||
public static final String PREF_SCREEN_NIGHT_MODE = "pref_screen_night_mode";
|
||||
public static final String PREF_SCREEN_SLEEP_MODE = "pref_screen_sleep_mode";
|
||||
public static final String PREF_SCREEN_LIFT_WRIST = "pref_screen_lift_wrist";
|
||||
|
@ -83,6 +83,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.preferences.GBSimpleSummaryProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.preferences.MinMaxTextWatcher;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.preferences.PreferenceCategoryMultiline;
|
||||
|
||||
public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment implements DeviceSpecificSettingsHandler {
|
||||
|
||||
@ -208,7 +209,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
}
|
||||
final BatteryConfig[] batteryConfigs = coordinator.getBatteryConfig(device);
|
||||
for (final BatteryConfig batteryConfig : batteryConfigs) {
|
||||
if (batteryConfigs.length > 1) {
|
||||
if (batteryConfigs.length > 1 || coordinator.addBatteryPollingSettings()) {
|
||||
final Preference prefHeader = new PreferenceCategory(requireContext());
|
||||
prefHeader.setKey("pref_battery_header_" + batteryConfig.getBatteryIndex());
|
||||
prefHeader.setIconSpaceReserved(false);
|
||||
@ -277,6 +278,40 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
));
|
||||
batteryScreen.addPreference(notifyFullThreshold);
|
||||
}
|
||||
|
||||
if (coordinator.addBatteryPollingSettings()) {
|
||||
final Preference prefHeader = new PreferenceCategoryMultiline(requireContext());
|
||||
prefHeader.setKey("pref_battery_polling_header");
|
||||
prefHeader.setIconSpaceReserved(false);
|
||||
prefHeader.setTitle(R.string.pref_battery_polling_configuration);
|
||||
prefHeader.setSummary(R.string.pref_battery_polling_summary);
|
||||
batteryScreen.addPreference(prefHeader);
|
||||
|
||||
final SwitchPreferenceCompat pollingToggle = new SwitchPreferenceCompat(requireContext());
|
||||
pollingToggle.setLayoutResource(R.layout.preference_checkbox);
|
||||
pollingToggle.setKey(PREF_BATTERY_POLLING_ENABLE);
|
||||
pollingToggle.setTitle(R.string.pref_battery_polling_enable);
|
||||
pollingToggle.setDefaultValue(false);
|
||||
pollingToggle.setIconSpaceReserved(false);
|
||||
batteryScreen.addPreference(pollingToggle);
|
||||
|
||||
final EditTextPreference pollingInterval = new EditTextPreference(requireContext());
|
||||
pollingInterval.setKey(PREF_BATTERY_POLLING_INTERVAL);
|
||||
pollingInterval.setTitle(R.string.pref_battery_polling_interval);
|
||||
pollingInterval.setDialogTitle(R.string.pref_battery_polling_interval);
|
||||
pollingInterval.setIconSpaceReserved(false);
|
||||
pollingInterval.setOnBindEditTextListener(editText -> {
|
||||
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
// Max is set to 8 days, which should be more than enough
|
||||
editText.addTextChangedListener(new MinMaxTextWatcher(editText, 0, 11520, true));
|
||||
editText.setSelection(editText.getText().length());
|
||||
});
|
||||
pollingInterval.setSummaryProvider(new GBSimpleSummaryProvider(
|
||||
getString(R.string.interval_fifteen_minutes),
|
||||
R.string.pref_battery_polling_interval_format
|
||||
));
|
||||
batteryScreen.addPreference(pollingInterval);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -559,6 +594,9 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
addPreferenceHandlerFor(PREF_SCREEN_LIFT_WRIST);
|
||||
addPreferenceHandlerFor(PREF_SYNC_CALENDAR);
|
||||
|
||||
addPreferenceHandlerFor(PREF_BATTERY_POLLING_ENABLE);
|
||||
addPreferenceHandlerFor(PREF_BATTERY_POLLING_INTERVAL);
|
||||
|
||||
addPreferenceHandlerFor(PREF_BLUETOOTH_CALLS_ENABLED);
|
||||
addPreferenceHandlerFor(PREF_DISPLAY_CALLER);
|
||||
addPreferenceHandlerFor(PREF_NOTIFICATION_DELAY_CALLS);
|
||||
|
@ -691,6 +691,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
|
||||
return batteryConfigs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addBatteryPollingSettings() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsPowerOff() {
|
||||
return false;
|
||||
|
@ -651,6 +651,8 @@ public interface DeviceCoordinator {
|
||||
|
||||
BatteryConfig[] getBatteryConfig(GBDevice device);
|
||||
|
||||
boolean addBatteryPollingSettings();
|
||||
|
||||
boolean supportsPowerOff();
|
||||
|
||||
PasswordCapabilityImpl.Mode getPasswordCapability();
|
||||
|
@ -0,0 +1,35 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.util.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
public class PreferenceCategoryMultiline extends PreferenceCategory {
|
||||
|
||||
private int maxSummaryLines = 5;
|
||||
|
||||
public PreferenceCategoryMultiline(Context ctx) {
|
||||
super(ctx, null);
|
||||
}
|
||||
|
||||
public PreferenceCategoryMultiline(Context ctx, int maxSummaryLines) {
|
||||
super(ctx, null);
|
||||
this.maxSummaryLines = maxSummaryLines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
TextView summary = (TextView) holder.findViewById(android.R.id.summary);
|
||||
if (summary == null)
|
||||
return;
|
||||
if (maxSummaryLines == 0 || maxSummaryLines == 1)
|
||||
return;
|
||||
summary.setSingleLine(false);
|
||||
summary.setMaxLines(maxSummaryLines);
|
||||
}
|
||||
}
|
@ -2918,6 +2918,13 @@
|
||||
<string name="toast_camera_support_required">Camera support is required for this function.</string>
|
||||
<string name="toast_camera_photo_taken">Photo has been taken and saved at: %s</string>
|
||||
|
||||
<!-- Battery polling preference strings -->
|
||||
<string name="pref_battery_polling_configuration">Battery polling configuration</string>
|
||||
<string name="pref_battery_polling_summary">This is best-effort, and might be delayed for several reasons</string>
|
||||
<string name="pref_battery_polling_enable">Enable battery polling</string>
|
||||
<string name="pref_battery_polling_interval">Battery polling interval</string>
|
||||
<string name="pref_battery_polling_interval_format">every %1$s minutes</string>
|
||||
|
||||
<string name="none">None</string>
|
||||
<string name="garmin_agps_url_i">AGPS %1$d URL</string>
|
||||
<string name="no_folder_selected">No folder selected</string>
|
||||
|
Loading…
Reference in New Issue
Block a user