diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java index a06bc27d4..7b6331b1d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -356,20 +356,35 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { gbDevice.setBatteryState(deviceEvent.state); gbDevice.setBatteryVoltage(deviceEvent.voltage); - //show the notification if the battery level is below threshold and only if not connected to charger - if (deviceEvent.level <= gbDevice.getBatteryThresholdPercent() && - (BatteryState.BATTERY_LOW.equals(deviceEvent.state) || - BatteryState.BATTERY_NORMAL.equals(deviceEvent.state)) - ) { - GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), String.valueOf(deviceEvent.level)), - deviceEvent.extendedInfoAvailable() ? - context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), String.valueOf(deviceEvent.level)) + "\n" + - context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime())) + - context.getString(R.string.notif_battery_low_bigtext_number_of_charges, String.valueOf(deviceEvent.numCharges)) - : "" - , context); + if (deviceEvent.level == GBDevice.BATTERY_UNKNOWN) { + // no level available, just "high" or "low" + if (BatteryState.BATTERY_LOW.equals(deviceEvent.state)) { + GB.updateBatteryNotification(context.getString(R.string.notif_battery_low, gbDevice.getName()), + deviceEvent.extendedInfoAvailable() ? + context.getString(R.string.notif_battery_low_extended, gbDevice.getName(), + context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime())) + + context.getString(R.string.notif_battery_low_bigtext_number_of_charges, String.valueOf(deviceEvent.numCharges))) + : "" + , context); + } else { + GB.removeBatteryNotification(context); + } } else { - GB.removeBatteryNotification(context); + //show the notification if the battery level is below threshold and only if not connected to charger + if (deviceEvent.level <= gbDevice.getBatteryThresholdPercent() && + (BatteryState.BATTERY_LOW.equals(deviceEvent.state) || + BatteryState.BATTERY_NORMAL.equals(deviceEvent.state)) + ) { + GB.updateBatteryNotification(context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), String.valueOf(deviceEvent.level)), + deviceEvent.extendedInfoAvailable() ? + context.getString(R.string.notif_battery_low_percent, gbDevice.getName(), String.valueOf(deviceEvent.level)) + "\n" + + context.getString(R.string.notif_battery_low_bigtext_last_charge_time, DateFormat.getDateTimeInstance().format(deviceEvent.lastChargeTime.getTime())) + + context.getString(R.string.notif_battery_low_bigtext_number_of_charges, String.valueOf(deviceEvent.numCharges)) + : "" + , context); + } else { + GB.removeBatteryNotification(context); + } } gbDevice.sendDeviceUpdateIntent(context); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7f0f1b45f..8ab5a8107 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -343,6 +343,8 @@ %1$s battery left: %2$s%% Last charge: %s \n Number of charges: %s + %1$s battery low + %1$s battery low: %2$s Export database failed! Please check your settings. Your sleep Sleep per week