Skip to content

Commit

Permalink
Sensor expiry alert resolution increased to 1 decimal point
Browse files Browse the repository at this point in the history
  • Loading branch information
Navid200 committed Aug 4, 2024
1 parent 0bd5d9b commit 4aceda1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/eveningoutpost/dexdrip/models/JoH.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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 ", "");
}
Expand Down

0 comments on commit 4aceda1

Please sign in to comment.