From 007df3aab33c6b6b70bcd2a3e0df810c786101a1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 26 Jul 2020 12:56:47 +0200 Subject: [PATCH] make SMB prefs more clear --- .../activities/MyPreferenceFragment.kt | 11 ++++-- .../aps/openAPSSMB/OpenAPSSMBPlugin.java | 38 ++++++++++++++++--- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/pref_openapssmb.xml | 28 +++++++------- 4 files changed, 55 insertions(+), 24 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 fce062f89f..e01ea6da78 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -185,9 +185,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang addPreferencesFromResourceIfEnabled(maintenancePlugin, rootKey) } initSummary(preferenceScreen, pluginId != -1) - for (plugin in pluginStore.plugins) { - plugin.preprocessPreferences(this) - } + preprocessPreferences() } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { @@ -212,6 +210,13 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang checkForBiometricFallback(key) updatePrefSummary(findPreference(key)) + preprocessPreferences() + } + + private fun preprocessPreferences() { + for (plugin in pluginStore.plugins) { + plugin.preprocessPreferences(this) + } } private fun checkForBiometricFallback(key: String) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java index 6da05d9075..71b726d622 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java @@ -2,6 +2,9 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB; import android.content.Context; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.SwitchPreference; + import org.jetbrains.annotations.NotNull; import org.json.JSONException; @@ -42,6 +45,7 @@ import info.nightscout.androidaps.utils.HardLimits; import info.nightscout.androidaps.utils.Profiler; import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.resources.ResourceHelper; +import info.nightscout.androidaps.utils.sharedPreferences.SP; @Singleton public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface { @@ -56,6 +60,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr private final HardLimits hardLimits; private final Profiler profiler; private final FabricPrivacy fabricPrivacy; + private final SP sp; // last values DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null; @@ -77,7 +82,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr IobCobCalculatorPlugin iobCobCalculatorPlugin, HardLimits hardLimits, Profiler profiler, - FabricPrivacy fabricPrivacy + FabricPrivacy fabricPrivacy, + SP sp ) { super(new PluginDescription() .mainType(PluginType.APS) @@ -100,6 +106,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr this.hardLimits = hardLimits; this.profiler = profiler; this.fabricPrivacy = fabricPrivacy; + this.sp = sp; } @Override @@ -119,6 +126,25 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr return pump.getPumpDescription().isTempBasalCapable; } + @Override + public void preprocessPreferences(PreferenceFragmentCompat preferenceFragment) { + super.preprocessPreferences(preferenceFragment); + boolean smbAlwaysEnabled = sp.getBoolean(R.string.key_enableSMB_always, false); + + SwitchPreference withCOB = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_enableSMB_with_COB)); + if (withCOB != null) { + withCOB.setVisible(!smbAlwaysEnabled); + } + SwitchPreference withTempTarget = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_enableSMB_with_temptarget)); + if (withTempTarget != null) { + withTempTarget.setVisible(!smbAlwaysEnabled); + } + SwitchPreference afterCarbs = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_enableSMB_after_carbs)); + if (afterCarbs != null) { + afterCarbs.setVisible(!smbAlwaysEnabled); + } + } + @Override public APSResult getLastAPSResult() { return lastAPSResult; @@ -174,7 +200,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr long startPart = System.currentTimeMillis(); MealData mealData = iobCobCalculatorPlugin.getMealData(); - profiler.log(LTag.APS, "getMealData()", startPart); + profiler.log(LTag.APS, "getMealData()", startPart); Constraint maxIOBAllowedConstraint = constraintChecker.getMaxIOBAllowed(); inputConstraints.copyReasons(maxIOBAllowedConstraint); @@ -219,7 +245,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr } IobTotal[] iobArray = iobCobCalculatorPlugin.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget); - profiler.log(LTag.APS, "calculateIobArrayInDia()", startPart); + profiler.log(LTag.APS, "calculateIobArrayInDia()", startPart); startPart = System.currentTimeMillis(); Constraint smbAllowed = new Constraint<>(!tempBasalFallback); @@ -234,8 +260,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr constraintChecker.isUAMEnabled(uam); inputConstraints.copyReasons(uam); - profiler.log(LTag.APS, "detectSensitivityandCarbAbsorption()", startPart); - profiler.log(LTag.APS, "SMB data gathering", start); + profiler.log(LTag.APS, "detectSensitivityandCarbAbsorption()", startPart); + profiler.log(LTag.APS, "SMB data gathering", start); start = System.currentTimeMillis(); try { @@ -254,7 +280,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr long now = System.currentTimeMillis(); DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke(); - profiler.log(LTag.APS, "SMB calculation", start); + profiler.log(LTag.APS, "SMB calculation", start); if (determineBasalResultSMB == null) { getAapsLogger().error(LTag.APS, "SMB calculation returned null"); lastDetermineBasalAdapterSMBJS = null; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5f200a45ad..055194017d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -761,7 +761,7 @@ Enable SMB with temp targets Enable SMB when there is temp target active (eating soon, exercise) Enable SMB with high temp targets - Enable SMB when there is high temp target active (exercise) + Enable SMB when there is high temp target active (exercise, above 100 mg/dl or 5.5 mmol/l) Insulin Carbs Buttons diff --git a/app/src/main/res/xml/pref_openapssmb.xml b/app/src/main/res/xml/pref_openapssmb.xml index f30107ea15..9123bb66d3 100644 --- a/app/src/main/res/xml/pref_openapssmb.xml +++ b/app/src/main/res/xml/pref_openapssmb.xml @@ -38,20 +38,6 @@ android:summary="@string/enablesmb_summary" android:title="@string/enablesmb" /> - - - - + + + +