diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
index 80fcf537a..da2f49302 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
@@ -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";
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
index 070a495cd..18abc61bf 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
@@ -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);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java
index eab493a70..2ed27c5c6 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java
@@ -691,6 +691,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return batteryConfigs;
}
+ @Override
+ public boolean addBatteryPollingSettings() {
+ return false;
+ }
+
@Override
public boolean supportsPowerOff() {
return false;
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java
index c921aa1a7..c58b6e0bb 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceCoordinator.java
@@ -651,6 +651,8 @@ public interface DeviceCoordinator {
BatteryConfig[] getBatteryConfig(GBDevice device);
+ boolean addBatteryPollingSettings();
+
boolean supportsPowerOff();
PasswordCapabilityImpl.Mode getPasswordCapability();
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/PreferenceCategoryMultiline.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/PreferenceCategoryMultiline.java
new file mode 100644
index 000000000..7d870ce07
--- /dev/null
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/preferences/PreferenceCategoryMultiline.java
@@ -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);
+ }
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index cfa98c797..5083857a9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -2918,6 +2918,13 @@
Camera support is required for this function.
Photo has been taken and saved at: %s
+
+ Battery polling configuration
+ This is best-effort, and might be delayed for several reasons
+ Enable battery polling
+ Battery polling interval
+ every %1$s minutes
+
None
AGPS %1$d URL
No folder selected