From a90f486eae7c078cbc0556339ef21c6fba1db82e Mon Sep 17 00:00:00 2001 From: Navid Date: Fri, 25 Oct 2024 20:11:21 -0400 Subject: [PATCH 1/5] Persistent High threshold fix --- .../java/com/eveningoutpost/dexdrip/Home.java | 2 ++ .../eveningoutpost/dexdrip/ui/FlipUnits.java | 25 +++++++++++++++++++ .../dexdrip/utils/Preferences.java | 12 ++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java index 85193b0887..ceca112c04 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java @@ -6,6 +6,7 @@ import static com.eveningoutpost.dexdrip.models.JoH.quietratelimit; import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; +import static com.eveningoutpost.dexdrip.ui.FlipUnits.triggerUnitsChange; import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.X; import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; @@ -385,6 +386,7 @@ protected void onCreate(Bundle savedInstanceState) { setVolumeControlStream(AudioManager.STREAM_MUSIC); checkedeula = checkEula(); + triggerUnitsChange(); // Correct defaults that are in mg/dL if we are using mmol/L binding = ActivityHomeBinding.inflate(getLayoutInflater()); binding.setVs(homeShelf); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java new file mode 100644 index 0000000000..94e05b76e2 --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java @@ -0,0 +1,25 @@ +package com.eveningoutpost.dexdrip.ui; + +import static com.eveningoutpost.dexdrip.utils.Preferences.handleUnitsChange; + +import com.eveningoutpost.dexdrip.Home; +import com.eveningoutpost.dexdrip.utilitymodels.Pref; + +/** + * Created by Navid200 on 25/10/2024. + * + * handleUnitsChange runs only when units are changed. But, even if we don't change units, we may need to trigger that method. + * Triggers handleUnitsChange to correct values that are in mg/dL even though the selected unit is mmol/L. + */ +public class FlipUnits { + + public static void triggerUnitsChange() { + + final boolean domgdl = Pref.getString("units", "mgdl").equals("mgdl"); // Identify which unit is chosen + if (!domgdl) { // Only if the selected unit is mmol/L + handleUnitsChange(null, "mmol", null); + Home.staticRefreshBGCharts(); + } + } +} + 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..3e9b222c32 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,6 @@ package com.eveningoutpost.dexdrip.utils; +import static com.eveningoutpost.dexdrip.EditAlertActivity.unitsConvert2Disp; import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName; import static com.eveningoutpost.dexdrip.xdrip.gs; @@ -755,6 +756,11 @@ 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 ? Double.parseDouble(stringValue) : Double.parseDouble(stringValue) * Constants.MMOLL_TO_MGDL; + if (submissionMgdl > 400 || submissionMgdl < 40) { + JoH.static_toast_long("The value must be between " + unitsConvert2Disp(domgdl, 40) + " and " + unitsConvert2Disp(domgdl, 400)); + return false; + } preference.setSummary(stringValue + " " + (domgdl ? "mg/dl" : "mmol/l")); // Set the summary to show the value followed by the chosen unit return true; } @@ -1009,7 +1015,11 @@ 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 From d69b318f7d8dfd954468945105052b9f89c78b0b Mon Sep 17 00:00:00 2001 From: Navid Date: Sat, 26 Oct 2024 17:46:42 -0400 Subject: [PATCH 2/5] Cleanup --- .../java/com/eveningoutpost/dexdrip/Home.java | 7 ++++-- .../eveningoutpost/dexdrip/ui/FlipUnits.java | 25 ------------------- .../dexdrip/utils/Preferences.java | 6 +++-- 3 files changed, 9 insertions(+), 29 deletions(-) delete mode 100644 app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java index ceca112c04..d46b7c3b50 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java @@ -6,13 +6,13 @@ import static com.eveningoutpost.dexdrip.models.JoH.quietratelimit; import static com.eveningoutpost.dexdrip.models.JoH.tsl; import static com.eveningoutpost.dexdrip.services.Ob1G5CollectionService.getTransmitterID; -import static com.eveningoutpost.dexdrip.ui.FlipUnits.triggerUnitsChange; import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.X; import static com.eveningoutpost.dexdrip.utilitymodels.ColorCache.getCol; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.DAY_IN_MS; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; +import static com.eveningoutpost.dexdrip.utils.Preferences.handleUnitsChange; import static com.eveningoutpost.dexdrip.xdrip.gs; import android.Manifest; @@ -386,7 +386,10 @@ protected void onCreate(Bundle savedInstanceState) { setVolumeControlStream(AudioManager.STREAM_MUSIC); checkedeula = checkEula(); - triggerUnitsChange(); // Correct defaults that are in mg/dL if we are using mmol/L + if (!Pref.getString("units", "mgdl").equals("mgdl")) { // Only if the selected unit is mmol/L + handleUnitsChange(null, "mmol", null); // Trigger the correction of values if needed based on the selected unit + staticRefreshBGCharts(); // Refresh home screen + } binding = ActivityHomeBinding.inflate(getLayoutInflater()); binding.setVs(homeShelf); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java b/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java deleted file mode 100644 index 94e05b76e2..0000000000 --- a/app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.eveningoutpost.dexdrip.ui; - -import static com.eveningoutpost.dexdrip.utils.Preferences.handleUnitsChange; - -import com.eveningoutpost.dexdrip.Home; -import com.eveningoutpost.dexdrip.utilitymodels.Pref; - -/** - * Created by Navid200 on 25/10/2024. - * - * handleUnitsChange runs only when units are changed. But, even if we don't change units, we may need to trigger that method. - * Triggers handleUnitsChange to correct values that are in mg/dL even though the selected unit is mmol/L. - */ -public class FlipUnits { - - public static void triggerUnitsChange() { - - final boolean domgdl = Pref.getString("units", "mgdl").equals("mgdl"); // Identify which unit is chosen - if (!domgdl) { // Only if the selected unit is mmol/L - handleUnitsChange(null, "mmol", null); - Home.staticRefreshBGCharts(); - } - } -} - 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 3e9b222c32..cc05706899 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java @@ -189,6 +189,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); @@ -757,8 +759,8 @@ public boolean onPreferenceChange(Preference preference, Object value) { if (isNumeric(stringValue)) { final boolean domgdl = Pref.getString("units", "mgdl").equals("mgdl"); // Identify which unit is chosen double submissionMgdl = domgdl ? Double.parseDouble(stringValue) : Double.parseDouble(stringValue) * Constants.MMOLL_TO_MGDL; - if (submissionMgdl > 400 || submissionMgdl < 40) { - JoH.static_toast_long("The value must be between " + unitsConvert2Disp(domgdl, 40) + " and " + unitsConvert2Disp(domgdl, 400)); + if (submissionMgdl > MAX_GLUCOSE_INPUT || submissionMgdl < MIN_GLUCOSE_INPUT) { + JoH.static_toast_long("The value must be between " + unitsConvert2Disp(domgdl, MIN_GLUCOSE_INPUT) + " and " + unitsConvert2Disp(domgdl, MAX_GLUCOSE_INPUT)); return false; } preference.setSummary(stringValue + " " + (domgdl ? "mg/dl" : "mmol/l")); // Set the summary to show the value followed by the chosen unit From d00302dcaac0557261a644ff944083b87ce9e6ac Mon Sep 17 00:00:00 2001 From: Navid Date: Sun, 27 Oct 2024 07:54:19 -0400 Subject: [PATCH 3/5] Cleanup 2 --- app/src/main/java/com/eveningoutpost/dexdrip/Home.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java index d46b7c3b50..94e2b394b6 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java @@ -387,8 +387,7 @@ protected void onCreate(Bundle savedInstanceState) { checkedeula = checkEula(); if (!Pref.getString("units", "mgdl").equals("mgdl")) { // Only if the selected unit is mmol/L - handleUnitsChange(null, "mmol", null); // Trigger the correction of values if needed based on the selected unit - staticRefreshBGCharts(); // Refresh home screen + handleUnitsChange(null, "mmol", null); // Trigger the correction of values (defaults) if needed based on the selected unit } binding = ActivityHomeBinding.inflate(getLayoutInflater()); From 11710ebe5b7e2557d535ee9494dad05466e89d5f Mon Sep 17 00:00:00 2001 From: Navid Date: Tue, 29 Oct 2024 10:38:40 -0400 Subject: [PATCH 4/5] Fixed --- app/src/main/java/com/eveningoutpost/dexdrip/Home.java | 4 ---- .../dexdrip/utilitymodels/IdempotentMigrations.java | 5 +++++ .../java/com/eveningoutpost/dexdrip/utils/Preferences.java | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java index 94e2b394b6..85193b0887 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Home.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Home.java @@ -12,7 +12,6 @@ import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS; import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS; -import static com.eveningoutpost.dexdrip.utils.Preferences.handleUnitsChange; import static com.eveningoutpost.dexdrip.xdrip.gs; import android.Manifest; @@ -386,9 +385,6 @@ protected void onCreate(Bundle savedInstanceState) { setVolumeControlStream(AudioManager.STREAM_MUSIC); checkedeula = checkEula(); - 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 based on the selected unit - } binding = ActivityHomeBinding.inflate(getLayoutInflater()); binding.setVs(homeShelf); 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 cc05706899..2baf1acf18 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java @@ -1,6 +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; @@ -758,7 +759,7 @@ 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 ? Double.parseDouble(stringValue) : Double.parseDouble(stringValue) * Constants.MMOLL_TO_MGDL; + double submissionMgdl = domgdl ? tolerantParseDouble(stringValue) : tolerantParseDouble(stringValue) * Constants.MMOLL_TO_MGDL; if (submissionMgdl > MAX_GLUCOSE_INPUT || submissionMgdl < MIN_GLUCOSE_INPUT) { JoH.static_toast_long("The value must be between " + unitsConvert2Disp(domgdl, MIN_GLUCOSE_INPUT) + " and " + unitsConvert2Disp(domgdl, MAX_GLUCOSE_INPUT)); return false; From 0eec76c15c9ea834f706facac86a32c8b8e6a5c6 Mon Sep 17 00:00:00 2001 From: Navid Date: Wed, 30 Oct 2024 09:56:10 -0400 Subject: [PATCH 5/5] Translate --- app/prod/release/output-metadata.json | 20 +++++++++++++++++++ .../dexdrip/utils/Preferences.java | 2 +- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/prod/release/output-metadata.json diff --git a/app/prod/release/output-metadata.json b/app/prod/release/output-metadata.json new file mode 100644 index 0000000000..005a7be332 --- /dev/null +++ b/app/prod/release/output-metadata.json @@ -0,0 +1,20 @@ +{ + "version": 3, + "artifactType": { + "type": "APK", + "kind": "Directory" + }, + "applicationId": "com.eveningoutpost.dexdrip", + "variantName": "prodRelease", + "elements": [ + { + "type": "SINGLE", + "filters": [], + "attributes": [], + "versionCode": 1603091400, + "versionName": "11710ebe5-Navid_2024_10_15b-2024.10.30", + "outputFile": "app-prod-release.apk" + } + ], + "elementType": "File" +} \ No newline at end of file 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 2baf1acf18..380a6b2987 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("The value must be between " + unitsConvert2Disp(domgdl, MIN_GLUCOSE_INPUT) + " and " + unitsConvert2Disp(domgdl, MAX_GLUCOSE_INPUT)); + JoH.static_toast_long(xdrip.gs(R.string.the_value_must_be_between_space) + unitsConvert2Disp(domgdl, MIN_GLUCOSE_INPUT) + xdrip.gs(R.string.space_and_space) + unitsConvert2Disp(domgdl, MAX_GLUCOSE_INPUT)); return false; } preference.setSummary(stringValue + " " + (domgdl ? "mg/dl" : "mmol/l")); // Set the summary to show the value followed by the chosen unit diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 124349aa02..90b7486e61 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -243,6 +243,8 @@ Persistent High Alert Enable Threshold + "The value must be between " + " and " Forecasted Low Alert Extrapolate data to try to predict lows Alarm at Forecasted Low mins