From 4aceda11cca8bb6640a5e1079a531607c79bdfea Mon Sep 17 00:00:00 2001 From: Navid Date: Sat, 3 Aug 2024 23:53:31 -0400 Subject: [PATCH] Sensor expiry alert resolution increased to 1 decimal point --- .../eveningoutpost/dexdrip/alert/SensorExpiry.java | 3 ++- .../java/com/eveningoutpost/dexdrip/models/JoH.java | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/alert/SensorExpiry.java b/app/src/main/java/com/eveningoutpost/dexdrip/alert/SensorExpiry.java index dcd1f455d0..2c8c5334ea 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/alert/SensorExpiry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/alert/SensorExpiry.java @@ -3,6 +3,7 @@ import static com.eveningoutpost.dexdrip.models.JoH.cancelNotification; import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalar; import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalarNatural; +import static com.eveningoutpost.dexdrip.models.JoH.niceTimeScalarNaturalp1; import static com.eveningoutpost.dexdrip.models.JoH.showNotification; import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SENSORY_EXPIRY_NOTIFICATION_ID; @@ -41,7 +42,7 @@ public SensorExpiry() { @Override public boolean activate() { - val expiry = niceTimeScalarNatural(SensorDays.get().getRemainingSensorPeriodInMs()); + val expiry = niceTimeScalarNaturalp1(SensorDays.get().getRemainingSensorPeriodInMs()); val notificationId = SENSORY_EXPIRY_NOTIFICATION_ID; cancelNotification(notificationId); val expireMsg = String.format("Sensor will expire in %s", expiry); // TODO i18n and format string diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java index 584cea0e38..86dfbad1ed 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java @@ -809,7 +809,7 @@ public static String niceTimeScalar(double t, int digits) { } - public static String niceTimeScalarNatural(long t) { + public static String niceTimeScalarNatural(long t) { // Shows the integer part only if (t > 3000000) t = t + 10000; // round up by 10 seconds if nearly an hour if ((t > Constants.DAY_IN_MS) && (t < Constants.WEEK_IN_MS * 2)) { final SimpleDateFormat df = new SimpleDateFormat("EEEE", Locale.getDefault()); @@ -820,6 +820,17 @@ public static String niceTimeScalarNatural(long t) { } } + public static String niceTimeScalarNaturalp1(long t) { // Rounds down to 1 decimal point. + if (t > 3000000) t = t + 10000; // round up by 10 seconds if nearly an hour + if ((t > Constants.DAY_IN_MS) && (t < Constants.WEEK_IN_MS * 2)) { + final SimpleDateFormat df = new SimpleDateFormat("EEEE", Locale.getDefault()); + final String day = df.format(new Date(JoH.tsl() + t)); + return ((t > Constants.WEEK_IN_MS) ? "next " : "") + day; + } else { + return niceTimeScalar(t, 1); + } + } + public static String niceTimeScalarRedux(long t) { return niceTimeScalar(t).replaceFirst("^1 ", ""); }