From 0ef3d9b3757cc3b983132cae832d04cb51180395 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 23 Sep 2023 14:07:46 +0200 Subject: [PATCH] show autosens icon properly --- .../androidaps/activities/MyPreferenceFragment.kt | 2 +- .../plugins/constraints/ConstraintsCheckerTest.kt | 2 +- .../core/utils/extensions/JSONObjectExt.kt | 2 +- core/utils/src/main/res/values/keys.xml | 2 ++ .../plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt | 2 +- .../plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt | 5 +++-- .../OpenAPSSMBDynamicISFPlugin.kt | 6 ++++++ plugins/aps/src/main/res/values/strings.xml | 2 +- plugins/aps/src/main/res/xml/pref_openapsama.xml | 2 +- plugins/aps/src/main/res/xml/pref_openapssmb.xml | 2 +- .../plugins/general/overview/OverviewFragment.kt | 3 ++- .../plugins/general/overview/OverviewPlugin.kt | 8 +++++++- .../sensitivity/SensitivityWeightedAveragePlugin.kt | 12 +++--------- 13 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index bed5ff830f..a6e54e3a2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -249,7 +249,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang activity?.recreate() return } - if (key == rh.gs(info.nightscout.plugins.aps.R.string.key_openapsama_use_autosens) && sp.getBoolean(info.nightscout.plugins.aps.R.string.key_openapsama_use_autosens, false)) { + if (key == rh.gs(info.nightscout.core.utils.R.string.key_use_autosens) && sp.getBoolean(info.nightscout.core.utils.R.string.key_use_autosens, false)) { activity?.let { OKDialog.show(it, rh.gs(app.aaps.configuration.R.string.configbuilder_sensitivity), rh.gs(R.string.sensitivity_warning)) } diff --git a/app/src/test/java/info/nightscout/plugins/constraints/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/plugins/constraints/ConstraintsCheckerTest.kt index c33c3bfd64..29d30e839d 100644 --- a/app/src/test/java/info/nightscout/plugins/constraints/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/plugins/constraints/ConstraintsCheckerTest.kt @@ -264,7 +264,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { fun isAutosensModeEnabledTest() { openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true) objectivesPlugin.objectives[Objectives.AUTOSENS_OBJECTIVE].startedOn = 0 - `when`(sp.getBoolean(info.nightscout.plugins.aps.R.string.key_openapsama_use_autosens, false)).thenReturn(false) + `when`(sp.getBoolean(info.nightscout.core.utils.R.string.key_use_autosens, false)).thenReturn(false) val c = constraintChecker.isAutosensModeEnabled() assertThat(c.reasonList).hasSize(2) // Safety & Objectives assertThat(c.mostLimitedReasonList).hasSize(2) // Safety & Objectives diff --git a/core/main/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt b/core/main/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt index 8f38aab753..91611acc07 100644 --- a/core/main/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt +++ b/core/main/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt @@ -41,6 +41,6 @@ fun JSONObject.storeString(@StringRes key: Int, sp: SP, rh: ResourceHelper): JSO } fun JSONObject.storeBoolean(@StringRes key: Int, sp: SP, rh: ResourceHelper): JSONObject { - if (has(rh.gs(key))) sp.putString(key, getBoolean(rh.gs(key)).toString()) + if (has(rh.gs(key))) sp.putBoolean(key, getBoolean(rh.gs(key))) return this } diff --git a/core/utils/src/main/res/values/keys.xml b/core/utils/src/main/res/values/keys.xml index 682b40f85d..f8e845faa9 100644 --- a/core/utils/src/main/res/values/keys.xml +++ b/core/utils/src/main/res/values/keys.xml @@ -150,5 +150,7 @@ ObjectivesActionsUsed ObjectivesScaleUsed virtualpump_uploadstatus + openapsama_useautosens + used_autosens_on_main_phone \ No newline at end of file diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt index 04948aa6da..fe391f9d3e 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt @@ -270,7 +270,7 @@ class OpenAPSAMAPlugin @Inject constructor( } override fun isAutosensModeEnabled(value: Constraint): Constraint { - val enabled = sp.getBoolean(R.string.key_openapsama_use_autosens, false) + val enabled = sp.getBoolean(info.nightscout.core.utils.R.string.key_use_autosens, false) if (!enabled) value.set(false, rh.gs(R.string.autosens_disabled_in_preferences), this) return value } diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt index 7c48962884..ca8c0ae5f4 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt @@ -30,6 +30,7 @@ import info.nightscout.interfaces.stats.TddCalculator import info.nightscout.interfaces.utils.HardLimits import info.nightscout.interfaces.utils.Round import info.nightscout.plugins.aps.R +import info.nightscout.plugins.aps.events.EventResetOpenAPSGui import info.nightscout.plugins.aps.utils.ScriptReader import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.AAPSLogger @@ -199,7 +200,7 @@ open class OpenAPSSMBPlugin @Inject constructor( if (constraintChecker.isAutosensModeEnabled().value()) { val autosensData = iobCobCalculator.getLastAutosensDataWithWaitForCalculationFinish("OpenAPSPlugin") if (autosensData == null) { - rxBus.send(info.nightscout.plugins.aps.events.EventResetOpenAPSGui(rh.gs(R.string.openaps_no_as_data))) + rxBus.send(EventResetOpenAPSGui(rh.gs(R.string.openaps_no_as_data))) return } lastAutosensResult = autosensData.autosensResult @@ -345,7 +346,7 @@ open class OpenAPSSMBPlugin @Inject constructor( } override fun isAutosensModeEnabled(value: Constraint): Constraint { - val enabled = sp.getBoolean(R.string.key_openapsama_use_autosens, false) + val enabled = sp.getBoolean(info.nightscout.core.utils.R.string.key_use_autosens, false) if (!enabled) value.set(false, rh.gs(R.string.autosens_disabled_in_preferences), this) return value } diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt index 9ade4e2cde..22945e7c48 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMBDynamicISF/OpenAPSSMBDynamicISFPlugin.kt @@ -6,6 +6,7 @@ import info.nightscout.annotations.OpenForTesting import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.aps.DetermineBasalAdapter import info.nightscout.interfaces.bgQualityCheck.BgQualityCheck +import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.ConstraintsChecker import info.nightscout.interfaces.iob.GlucoseStatusProvider import info.nightscout.interfaces.iob.IobCobCalculator @@ -80,4 +81,9 @@ class OpenAPSSMBDynamicISFPlugin @Inject constructor( if (tdd1D == null || tdd7D == null || tddLast4H == null || tddLast8to4H == null || tddLast24H == null || !dynIsfEnabled.value()) DetermineBasalAdapterSMBJS(ScriptReader(context), injector) else DetermineBasalAdapterSMBDynamicISFJS(ScriptReader(context), injector) + + override fun isAutosensModeEnabled(value: Constraint): Constraint { + value.set(false, rh.gs(R.string.autosens_disabled_in_dyn_isf), this) + return value + } } \ No newline at end of file diff --git a/plugins/aps/src/main/res/values/strings.xml b/plugins/aps/src/main/res/values/strings.xml index 12ccc60a33..62774fbfc0 100644 --- a/plugins/aps/src/main/res/values/strings.xml +++ b/plugins/aps/src/main/res/values/strings.xml @@ -23,7 +23,6 @@ DynISFAdjust dynisf_adjust_sensitivity openapsma_max_basal - openapsama_useautosens Adjust sensitivity and BG DynamicISF Adjustment Factor % @@ -112,6 +111,7 @@ SMB disabled in preferences UAM disabled in preferences Autosens disabled in preferences + Autosens disabled in DynISF Limiting IOB to %1$.1f U because of %2$s diff --git a/plugins/aps/src/main/res/xml/pref_openapsama.xml b/plugins/aps/src/main/res/xml/pref_openapsama.xml index 155b434ef0..6c5327ca38 100644 --- a/plugins/aps/src/main/res/xml/pref_openapsama.xml +++ b/plugins/aps/src/main/res/xml/pref_openapsama.xml @@ -30,7 +30,7 @@