make SMB prefs more clear

This commit is contained in:
Milos Kozak 2020-07-26 12:56:47 +02:00
parent 1edef7fb4e
commit 007df3aab3
4 changed files with 55 additions and 24 deletions

View file

@ -185,9 +185,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
addPreferencesFromResourceIfEnabled(maintenancePlugin, rootKey) addPreferencesFromResourceIfEnabled(maintenancePlugin, rootKey)
} }
initSummary(preferenceScreen, pluginId != -1) initSummary(preferenceScreen, pluginId != -1)
for (plugin in pluginStore.plugins) { preprocessPreferences()
plugin.preprocessPreferences(this)
}
} }
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
@ -212,6 +210,13 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
checkForBiometricFallback(key) checkForBiometricFallback(key)
updatePrefSummary(findPreference(key)) updatePrefSummary(findPreference(key))
preprocessPreferences()
}
private fun preprocessPreferences() {
for (plugin in pluginStore.plugins) {
plugin.preprocessPreferences(this)
}
} }
private fun checkForBiometricFallback(key: String) { private fun checkForBiometricFallback(key: String) {

View file

@ -2,6 +2,9 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import android.content.Context; import android.content.Context;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.json.JSONException; 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.Profiler;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@Singleton @Singleton
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface { 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 HardLimits hardLimits;
private final Profiler profiler; private final Profiler profiler;
private final FabricPrivacy fabricPrivacy; private final FabricPrivacy fabricPrivacy;
private final SP sp;
// last values // last values
DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null; DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null;
@ -77,7 +82,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
IobCobCalculatorPlugin iobCobCalculatorPlugin, IobCobCalculatorPlugin iobCobCalculatorPlugin,
HardLimits hardLimits, HardLimits hardLimits,
Profiler profiler, Profiler profiler,
FabricPrivacy fabricPrivacy FabricPrivacy fabricPrivacy,
SP sp
) { ) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
@ -100,6 +106,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
this.hardLimits = hardLimits; this.hardLimits = hardLimits;
this.profiler = profiler; this.profiler = profiler;
this.fabricPrivacy = fabricPrivacy; this.fabricPrivacy = fabricPrivacy;
this.sp = sp;
} }
@Override @Override
@ -119,6 +126,25 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
return pump.getPumpDescription().isTempBasalCapable; 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 @Override
public APSResult getLastAPSResult() { public APSResult getLastAPSResult() {
return lastAPSResult; return lastAPSResult;
@ -174,7 +200,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
long startPart = System.currentTimeMillis(); long startPart = System.currentTimeMillis();
MealData mealData = iobCobCalculatorPlugin.getMealData(); MealData mealData = iobCobCalculatorPlugin.getMealData();
profiler.log(LTag.APS, "getMealData()", startPart); profiler.log(LTag.APS, "getMealData()", startPart);
Constraint<Double> maxIOBAllowedConstraint = constraintChecker.getMaxIOBAllowed(); Constraint<Double> maxIOBAllowedConstraint = constraintChecker.getMaxIOBAllowed();
inputConstraints.copyReasons(maxIOBAllowedConstraint); 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); 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(); startPart = System.currentTimeMillis();
Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback); Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback);
@ -234,8 +260,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
constraintChecker.isUAMEnabled(uam); constraintChecker.isUAMEnabled(uam);
inputConstraints.copyReasons(uam); inputConstraints.copyReasons(uam);
profiler.log(LTag.APS, "detectSensitivityandCarbAbsorption()", startPart); profiler.log(LTag.APS, "detectSensitivityandCarbAbsorption()", startPart);
profiler.log(LTag.APS, "SMB data gathering", start); profiler.log(LTag.APS, "SMB data gathering", start);
start = System.currentTimeMillis(); start = System.currentTimeMillis();
try { try {
@ -254,7 +280,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke(); DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
profiler.log(LTag.APS, "SMB calculation", start); profiler.log(LTag.APS, "SMB calculation", start);
if (determineBasalResultSMB == null) { if (determineBasalResultSMB == null) {
getAapsLogger().error(LTag.APS, "SMB calculation returned null"); getAapsLogger().error(LTag.APS, "SMB calculation returned null");
lastDetermineBasalAdapterSMBJS = null; lastDetermineBasalAdapterSMBJS = null;

View file

@ -761,7 +761,7 @@
<string name="enablesmbwithtemptarget">Enable SMB with temp targets</string> <string name="enablesmbwithtemptarget">Enable SMB with temp targets</string>
<string name="enablesmbwithtemptarget_summary">Enable SMB when there is temp target active (eating soon, exercise)</string> <string name="enablesmbwithtemptarget_summary">Enable SMB when there is temp target active (eating soon, exercise)</string>
<string name="enablesmbwithhightemptarget">Enable SMB with high temp targets</string> <string name="enablesmbwithhightemptarget">Enable SMB with high temp targets</string>
<string name="enablesmbwithhightemptarget_summary">Enable SMB when there is high temp target active (exercise)</string> <string name="enablesmbwithhightemptarget_summary">Enable SMB when there is high temp target active (exercise, above 100 mg/dl or 5.5 mmol/l)</string>
<string name="overview_insulin_label">Insulin</string> <string name="overview_insulin_label">Insulin</string>
<string name="overview_carbs_label">Carbs</string> <string name="overview_carbs_label">Carbs</string>
<string name="overview_buttons_selection">Buttons</string> <string name="overview_buttons_selection">Buttons</string>

View file

@ -38,20 +38,6 @@
android:summary="@string/enablesmb_summary" android:summary="@string/enablesmb_summary"
android:title="@string/enablesmb" /> android:title="@string/enablesmb" />
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/key_use_smb"
android:key="@string/key_enableSMB_with_COB"
android:summary="@string/enablesmbwithcob_summary"
android:title="@string/enablesmbwithcob" />
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/key_use_smb"
android:key="@string/key_enableSMB_with_temptarget"
android:summary="@string/enablesmbwithtemptarget_summary"
android:title="@string/enablesmbwithtemptarget" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:dependency="@string/key_use_smb" android:dependency="@string/key_use_smb"
@ -66,6 +52,20 @@
android:summary="@string/enablesmbalways_summary" android:summary="@string/enablesmbalways_summary"
android:title="@string/enablesmbalways" /> android:title="@string/enablesmbalways" />
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/key_use_smb"
android:key="@string/key_enableSMB_with_COB"
android:summary="@string/enablesmbwithcob_summary"
android:title="@string/enablesmbwithcob" />
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/key_use_smb"
android:key="@string/key_enableSMB_with_temptarget"
android:summary="@string/enablesmbwithtemptarget_summary"
android:title="@string/enablesmbwithtemptarget" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:dependency="@string/key_use_smb" android:dependency="@string/key_use_smb"