diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java b/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java index 0bc4ab48e5..6257ac04b2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java @@ -30,9 +30,14 @@ public class PersistentHigh { private static final String TAG = PersistentHigh.class.getSimpleName(); private static final String PERSISTENT_HIGH_SINCE = "persistent_high_since"; + public static double persistentHighThreshold = Home.convertToMgDlIfMmol(JoH.tolerantParseDouble(Pref.getString("highValue", "170"))); // By default, the persistent High threshold is equal to the High Value public static boolean checkForPersistentHigh() { + if (!Pref.getBoolean("high_value_is_persistent_high_threshold", true)) { // If the user has chosen not to use the High Value as the threshold + persistentHighThreshold = Home.convertToMgDlIfMmol(JoH.tolerantParseDouble(Pref.getString("persistent_high_threshold", "170"))); // Set the threshold to the value chosen by the user + } + // skip if not enabled if (!Pref.getBooleanDefaultFalse("persistent_high_alert_enabled")) return false; @@ -40,18 +45,15 @@ public static boolean checkForPersistentHigh() { final List last = BgReading.latest(1); if ((last != null) && (last.size() > 0)) { - final double highMarkMgDl = Home.convertToMgDlIfMmol( - JoH.tolerantParseDouble(Pref.getString("highValue", "170"), 170d)); - final long now = JoH.tsl(); final long since = now - last.get(0).timestamp; // only process if last reading <10 mins if (since < MINUTE_IN_MS * 10) { - // check if exceeding high - if (last.get(0).getDg_mgdl() > highMarkMgDl) { + // check if exceeding persistent high threshold + if (last.get(0).getDg_mgdl() > persistentHighThreshold) { final double this_slope = last.get(0).getDg_slope() * MINUTE_IN_MS; - Log.d(TAG, "CheckForPersistentHigh: Slope: " + JoH.qs(this_slope)+ " "+JoH.dateTimeText(last.get(0).timestamp)); + Log.d(TAG, "CheckForPersistentHigh: Slope: " + JoH.qs(this_slope) + " " + JoH.dateTimeText(last.get(0).timestamp)); // if not falling if (this_slope > 0 && !last.get(0).hide_slope) { @@ -78,7 +80,7 @@ public static boolean checkForPersistentHigh() { return false; } - if (!dataQualityCheck(high_since, highMarkMgDl)) { + if (!dataQualityCheck(high_since, persistentHighThreshold)) { Log.d(TAG, "Insufficient data quality to raise persistent high alert"); return false; } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java b/app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java index cc1a2c7cd3..2395e7fca2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java @@ -1,5 +1,6 @@ package com.eveningoutpost.dexdrip.models; +import static com.eveningoutpost.dexdrip.evaluators.PersistentHigh.persistentHighThreshold; import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId; import static com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.NOT_COMPUTABLE; import static com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.getTrend; @@ -1834,10 +1835,8 @@ public static boolean checkForPersistentHigh() { final long since = now - last.get(0).timestamp; // only process if last reading <10 mins if (since < 600000) { - // check if exceeding high - if (last.get(0).calculated_value > - Home.convertToMgDlIfMmol( - JoH.tolerantParseDouble(Pref.getString("highValue", "170")))) { + // check if exceeding persistent high threshold + if (last.get(0).calculated_value > persistentHighThreshold) { final double this_slope = last.get(0).calculated_value_slope * 60000; //Log.d(TAG, "CheckForPersistentHigh: Slope: " + JoH.qs(this_slope)); 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 bfda878ff3..e892922fc1 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java @@ -748,6 +748,19 @@ public boolean onPreferenceChange(Preference preference, Object value) { return false; } }; + + private static Preference.OnPreferenceChangeListener sBindNumericUnitizedPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { // This listener adds glucose unit in addition to the value to the summary + @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 + preference.setSummary(stringValue + " " + (domgdl ? "mg/dl" : "mmol/l")); // Set the summary to show the value followed by the chosen unit + return true; + } + return false; + } + }; private static Preference.OnPreferenceChangeListener sBindPreferenceTitleAppendToValueListenerUpdateChannel = new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object value) { @@ -996,6 +1009,13 @@ 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 + preference.setOnPreferenceChangeListener(sBindNumericUnitizedPreferenceSummaryToValueListener); + sBindNumericUnitizedPreferenceSummaryToValueListener.onPreferenceChange(preference, + PreferenceManager + .getDefaultSharedPreferences(preference.getContext()) + .getString(preference.getKey(), "")); + } @RequiredArgsConstructor public static class AllPrefsFragment extends PreferenceFragment { @@ -1074,6 +1094,7 @@ public void onCreate(Bundle savedInstanceState) { bindPreferenceSummaryToValue(findPreference("rising_bg_val")); bindPreferenceSummaryToValue(findPreference("other_alerts_sound")); bindPreferenceSummaryToValue(findPreference("bridge_battery_alert_level")); + bindPreferenceSummaryToUnitizedValueAndEnsureNumeric(findPreference("persistent_high_threshold")); addPreferencesFromResource(R.xml.pref_data_source); @@ -3057,6 +3078,7 @@ public static void handleUnitsChange(Preference preference, Object newValue, All final Double lowVal = Double.parseDouble(preferences.getString("lowValue", "0")); final Double default_insulin_sensitivity = Double.parseDouble(preferences.getString("profile_insulin_sensitivity_default", "54")); final Double default_target_glucose = Double.parseDouble(preferences.getString("plus_target_range", "100")); + final Double persistent_high_Val = Double.parseDouble(preferences.getString("persistent_high_threshold", "0")); static_units = newValue.toString(); @@ -3068,6 +3090,11 @@ public static void handleUnitsChange(Preference preference, Object newValue, All preferences.edit().putString("plus_target_range", Long.toString(Math.round(default_target_glucose * Constants.MMOLL_TO_MGDL))).apply(); Profile.invalidateProfile(); } + if (persistent_high_Val < 36) { + ProfileEditor.convertData(Constants.MMOLL_TO_MGDL); + preferences.edit().putString("persistent_high_threshold", Long.toString(Math.round(persistent_high_Val * Constants.MMOLL_TO_MGDL))).apply(); + Profile.invalidateProfile(); + } if (lowVal < 36) { ProfileEditor.convertData(Constants.MMOLL_TO_MGDL); preferences.edit().putString("lowValue", Long.toString(Math.round(lowVal * Constants.MMOLL_TO_MGDL))).apply(); @@ -3084,6 +3111,11 @@ public static void handleUnitsChange(Preference preference, Object newValue, All preferences.edit().putString("plus_target_range", JoH.qs(default_target_glucose * Constants.MGDL_TO_MMOLL,1)).apply(); Profile.invalidateProfile(); } + if (persistent_high_Val > 35) { + ProfileEditor.convertData(Constants.MGDL_TO_MMOLL); + preferences.edit().putString("persistent_high_threshold", JoH.qs(persistent_high_Val * Constants.MGDL_TO_MMOLL, 1)).apply(); + Profile.invalidateProfile(); + } if (lowVal > 35) { ProfileEditor.convertData(Constants.MGDL_TO_MMOLL); preferences.edit().putString("lowValue", JoH.qs(lowVal * Constants.MGDL_TO_MMOLL, 1)).apply(); @@ -3096,6 +3128,7 @@ public static void handleUnitsChange(Preference preference, Object newValue, All if (allPrefsFragment != null) { allPrefsFragment.setSummary("highValue"); allPrefsFragment.setSummary("lowValue"); + allPrefsFragment.setSummary("persistent_high_threshold"); } if (profile_insulin_sensitivity_default != null) { Log.d(TAG, "refreshing profile insulin sensitivity default display"); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96c77ea6be..124349aa02 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -241,6 +241,8 @@ Other Alerts Extra Alerts (xDrip+) Persistent High Alert + Enable + Threshold Forecasted Low Alert Extrapolate data to try to predict lows Alarm at Forecasted Low mins @@ -436,15 +438,15 @@ "New Version date: " "Old Version date: " Speak your note text - Alarm if above high value + Notify if above threshold for longer than the time specified below for longer than (minutes) - Choose sound used for persistent high alarm. - Persistent High Sound + Choose the sound used for the alarm. + Alert Sound Forecast Lows Raise alarm on Forecast Low Notify when predicted low time reaches threshold - Predicted Low Sound - Choose sound used for predicted low alarm. + Alert Sound + Choose the sound used for the alarm. Notify when Parakeet device stops checking in Parakeet related alerts Raise Parakeet notification silently when charging @@ -1509,7 +1511,9 @@ Noisy Readings Falling/Rising BG Alert Preferences (for these alerts) - When above High level for too long and not heading downwards + When above threshold and not falling for long + When enabled, High Value is the threshold.\nWhen disabled, the threshold is the value specified below. + Threshold: High Value SEARCH ALL Full Screen mode @@ -1861,7 +1865,8 @@ Choose yMax for when there are no greater readings. Verify settings and wait for connectivity. Raise notifications when the sensor gets close to expiry. - Sensor expiry + Sensor Expiry Notifications + Enable Close Advanced settings for Libre 2 Show raw values in graph diff --git a/app/src/main/res/xml/pref_notifications.xml b/app/src/main/res/xml/pref_notifications.xml index 587c470d52..20effa5b24 100644 --- a/app/src/main/res/xml/pref_notifications.xml +++ b/app/src/main/res/xml/pref_notifications.xml @@ -293,14 +293,26 @@ - + android:title="@string/persistent_high_alert_enable" /> + + - - + - - + + + + + - - +