From 11710ebe5b7e2557d535ee9494dad05466e89d5f Mon Sep 17 00:00:00 2001 From: Navid Date: Tue, 29 Oct 2024 10:38:40 -0400 Subject: [PATCH] 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;