Skip to content

Commit

Permalink
Persistent High threshold fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Navid200 committed Oct 26, 2024
1 parent 9f769df commit a90f486
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/java/com/eveningoutpost/dexdrip/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/com/eveningoutpost/dexdrip/ui/FlipUnits.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a90f486

Please sign in to comment.