From 69a3ce51bac1861dabca3739069d57d39405cf7f Mon Sep 17 00:00:00 2001 From: Navid Date: Sun, 3 Nov 2024 11:01:04 -0500 Subject: [PATCH 1/2] Persistent High threshold fix --- .../utilitymodels/IdempotentMigrations.java | 5 +++++ .../dexdrip/utils/Preferences.java | 16 ++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java index 65c0c5776a..693035bc90 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java @@ -1,5 +1,7 @@ package com.eveningoutpost.dexdrip.utilitymodels; +import static com.eveningoutpost.dexdrip.utils.Preferences.handleUnitsChange; + import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; @@ -60,6 +62,9 @@ public void performAll() { IncompatibleApps.notifyAboutIncompatibleApps(); CompatibleApps.notifyAboutCompatibleApps(); legacySettingsMoveLanguageFromNoToNb(); + if (!Pref.getString("units", "mgdl").equals("mgdl")) { // Only if the selected unit is mmol/L + handleUnitsChange(null, "mmol", null); // Trigger the correction of values (defaults) if needed + } } 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 e892922fc1..68a6abd318 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; @@ -188,6 +190,8 @@ public class Preferences extends BasePreferenceActivity implements SearchPrefere private volatile String scanFormat = null; // The format of the scan private volatile String scanContents = null; // Text content of the scan coming either from camera or file private volatile byte[] scanRawBytes = null; // Raw bytes of the scan + private static final double MIN_GLUCOSE_INPUT = 40; // The smallest input glucose value xDrip accepts + private static final double MAX_GLUCOSE_INPUT = 400; // The largest input glucose value xDrip accepts private void refreshFragments() { refreshFragments(null); @@ -755,10 +759,15 @@ 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 false; + return false; // Reject input if not numeric } }; private static Preference.OnPreferenceChangeListener sBindPreferenceTitleAppendToValueListenerUpdateChannel = new Preference.OnPreferenceChangeListener() { @@ -1009,7 +1018,10 @@ 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: + // 1- show the value as summary; + // 2- amend the value in summary with the corresponding glucose unit; + // 3- reject inputs outside the 40-400 mg/dL range. 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 68ff43a9bb0c96de5255ed1f340236bfe4b66708 Mon Sep 17 00:00:00 2001 From: Navid Date: Sun, 3 Nov 2024 16:15:37 -0500 Subject: [PATCH 2/2] Cleanup --- .../main/java/com/eveningoutpost/dexdrip/utils/Preferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 68a6abd318..b8035cf4f4 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java @@ -761,7 +761,7 @@ public boolean onPreferenceChange(Preference preference, Object value) { 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))); + 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