From 6547323ae7368a1bb5940ec30602714cb81f4154 Mon Sep 17 00:00:00 2001 From: Navid Date: Sat, 9 Nov 2024 21:40:06 -0500 Subject: [PATCH 1/2] Persistent High Alert Threshold range --- .../dexdrip/utils/Preferences.java | 17 +++++++++++++---- app/src/main/res/values/strings.xml | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java index 4d43f46ad0..50eb1f6d31 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java @@ -1,5 +1,7 @@ package com.eveningoutpost.dexdrip.utils; +import static com.eveningoutpost.dexdrip.EditAlertActivity.unitsConvert2Disp; +import static com.eveningoutpost.dexdrip.models.JoH.tolerantParseDouble; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; import static com.eveningoutpost.dexdrip.xdrip.gs; @@ -192,6 +194,8 @@ public class Preferences extends BasePreferenceActivity implements SearchPrefere private void refreshFragments() { refreshFragments(null); } + private static final double MIN_GLUCOSE_INPUT = 40; // The smallest acceptable input glucose value in mg/dL + private static final double MAX_GLUCOSE_INPUT = 400; // The largest acceptable input glucose value in mg/dL private void refreshFragments(final String jumpTo) { this.preferenceFragment = new AllPrefsFragment(jumpTo); @@ -749,16 +753,21 @@ public boolean onPreferenceChange(Preference preference, Object value) { } }; - private static Preference.OnPreferenceChangeListener sBindNumericUnitizedPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { // This listener adds glucose unit in addition to the value to the summary + private static Preference.OnPreferenceChangeListener sBindNumericUnitizedPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { // This listener adds glucose unit in addition to the value to the summary and rejects out-of-range inputs @Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (isNumeric(stringValue)) { final boolean domgdl = Pref.getString("units", "mgdl").equals("mgdl"); // Identify which unit is chosen + double submissionMgdl = domgdl ? tolerantParseDouble(stringValue) : tolerantParseDouble(stringValue) * Constants.MMOLL_TO_MGDL; + if (submissionMgdl > MAX_GLUCOSE_INPUT || submissionMgdl < MIN_GLUCOSE_INPUT) { + JoH.static_toast_long(xdrip.gs(R.string.the_value_must_be_between_min_and_max, unitsConvert2Disp(domgdl, MIN_GLUCOSE_INPUT), unitsConvert2Disp(domgdl, MAX_GLUCOSE_INPUT))); + return false; // Reject input if out of range + } preference.setSummary(stringValue + " " + (domgdl ? "mg/dl" : "mmol/l")); // Set the summary to show the value followed by the chosen unit - return true; + return true; // Accept input as it is numeric and in range } - return false; + return false; // Reject input if not numeric } }; private static Preference.OnPreferenceChangeListener sBindPreferenceTitleAppendToValueListenerUpdateChannel = new Preference.OnPreferenceChangeListener() { @@ -1009,7 +1018,7 @@ private static void bindPreferenceSummaryToValueAndEnsureNumeric(Preference pref .getString(preference.getKey(), "")); } - private static void bindPreferenceSummaryToUnitizedValueAndEnsureNumeric(Preference preference) { // Use this to show the value as well as the corresponding glucose unit as the summary + private static void bindPreferenceSummaryToUnitizedValueAndEnsureNumeric(Preference preference) { // Use this to show the value as well as the corresponding glucose unit as the summary, and reject out-of-range inputs preference.setOnPreferenceChangeListener(sBindNumericUnitizedPreferenceSummaryToValueListener); sBindNumericUnitizedPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 124349aa02..1d25e46dd6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -243,6 +243,7 @@ Persistent High Alert Enable Threshold + The value must be between %1$s and %2$s Forecasted Low Alert Extrapolate data to try to predict lows Alarm at Forecasted Low mins From a64bfd1d3faf793f7f2deeab88966ee05512462d Mon Sep 17 00:00:00 2001 From: Navid Date: Sat, 9 Nov 2024 23:38:11 -0500 Subject: [PATCH 2/2] Cleanup --- .../java/com/eveningoutpost/dexdrip/utils/Preferences.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java index 50eb1f6d31..07785d3d8b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java @@ -194,8 +194,8 @@ public class Preferences extends BasePreferenceActivity implements SearchPrefere private void refreshFragments() { refreshFragments(null); } - private static final double MIN_GLUCOSE_INPUT = 40; // The smallest acceptable input glucose value in mg/dL - private static final double MAX_GLUCOSE_INPUT = 400; // The largest acceptable input glucose value in mg/dL + public static final double MIN_GLUCOSE_INPUT = 40; // The smallest acceptable input glucose value in mg/dL + public static final double MAX_GLUCOSE_INPUT = 400; // The largest acceptable input glucose value in mg/dL private void refreshFragments(final String jumpTo) { this.preferenceFragment = new AllPrefsFragment(jumpTo);