show autosens icon properly

This commit is contained in:
Milos Kozak 2023-09-23 14:07:46 +02:00
parent ccabee0399
commit 0ef3d9b375
13 changed files with 30 additions and 20 deletions

View file

@ -249,7 +249,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
activity?.recreate() activity?.recreate()
return 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 { activity?.let {
OKDialog.show(it, rh.gs(app.aaps.configuration.R.string.configbuilder_sensitivity), rh.gs(R.string.sensitivity_warning)) OKDialog.show(it, rh.gs(app.aaps.configuration.R.string.configbuilder_sensitivity), rh.gs(R.string.sensitivity_warning))
} }

View file

@ -264,7 +264,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
fun isAutosensModeEnabledTest() { fun isAutosensModeEnabledTest() {
openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true) openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true)
objectivesPlugin.objectives[Objectives.AUTOSENS_OBJECTIVE].startedOn = 0 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() val c = constraintChecker.isAutosensModeEnabled()
assertThat(c.reasonList).hasSize(2) // Safety & Objectives assertThat(c.reasonList).hasSize(2) // Safety & Objectives
assertThat(c.mostLimitedReasonList).hasSize(2) // Safety & Objectives assertThat(c.mostLimitedReasonList).hasSize(2) // Safety & Objectives

View file

@ -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 { 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 return this
} }

View file

@ -150,5 +150,7 @@
<string name="key_objectiveuseactions" translatable="false">ObjectivesActionsUsed</string> <string name="key_objectiveuseactions" translatable="false">ObjectivesActionsUsed</string>
<string name="key_objectiveusescale" translatable="false">ObjectivesScaleUsed</string> <string name="key_objectiveusescale" translatable="false">ObjectivesScaleUsed</string>
<string name="key_virtual_pump_upload_status" translatable="false">virtualpump_uploadstatus</string> <string name="key_virtual_pump_upload_status" translatable="false">virtualpump_uploadstatus</string>
<string name="key_use_autosens" translatable="false">openapsama_useautosens</string>
<string name="key_used_autosens_on_main_phone" translatable="false">used_autosens_on_main_phone</string>
</resources> </resources>

View file

@ -270,7 +270,7 @@ class OpenAPSAMAPlugin @Inject constructor(
} }
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
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) if (!enabled) value.set(false, rh.gs(R.string.autosens_disabled_in_preferences), this)
return value return value
} }

View file

@ -30,6 +30,7 @@ import info.nightscout.interfaces.stats.TddCalculator
import info.nightscout.interfaces.utils.HardLimits import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.interfaces.utils.Round import info.nightscout.interfaces.utils.Round
import info.nightscout.plugins.aps.R import info.nightscout.plugins.aps.R
import info.nightscout.plugins.aps.events.EventResetOpenAPSGui
import info.nightscout.plugins.aps.utils.ScriptReader import info.nightscout.plugins.aps.utils.ScriptReader
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
@ -199,7 +200,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
if (constraintChecker.isAutosensModeEnabled().value()) { if (constraintChecker.isAutosensModeEnabled().value()) {
val autosensData = iobCobCalculator.getLastAutosensDataWithWaitForCalculationFinish("OpenAPSPlugin") val autosensData = iobCobCalculator.getLastAutosensDataWithWaitForCalculationFinish("OpenAPSPlugin")
if (autosensData == null) { 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 return
} }
lastAutosensResult = autosensData.autosensResult lastAutosensResult = autosensData.autosensResult
@ -345,7 +346,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
} }
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> { override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
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) if (!enabled) value.set(false, rh.gs(R.string.autosens_disabled_in_preferences), this)
return value return value
} }

View file

@ -6,6 +6,7 @@ import info.nightscout.annotations.OpenForTesting
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.aps.DetermineBasalAdapter import info.nightscout.interfaces.aps.DetermineBasalAdapter
import info.nightscout.interfaces.bgQualityCheck.BgQualityCheck import info.nightscout.interfaces.bgQualityCheck.BgQualityCheck
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.ConstraintsChecker import info.nightscout.interfaces.constraints.ConstraintsChecker
import info.nightscout.interfaces.iob.GlucoseStatusProvider import info.nightscout.interfaces.iob.GlucoseStatusProvider
import info.nightscout.interfaces.iob.IobCobCalculator 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()) if (tdd1D == null || tdd7D == null || tddLast4H == null || tddLast8to4H == null || tddLast24H == null || !dynIsfEnabled.value())
DetermineBasalAdapterSMBJS(ScriptReader(context), injector) DetermineBasalAdapterSMBJS(ScriptReader(context), injector)
else DetermineBasalAdapterSMBDynamicISFJS(ScriptReader(context), injector) else DetermineBasalAdapterSMBDynamicISFJS(ScriptReader(context), injector)
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
value.set(false, rh.gs(R.string.autosens_disabled_in_dyn_isf), this)
return value
}
} }

View file

@ -23,7 +23,6 @@
<string name="key_DynISFAdjust" translatable="false">DynISFAdjust</string> <string name="key_DynISFAdjust" translatable="false">DynISFAdjust</string>
<string name="key_adjust_sensitivity" translatable="false">dynisf_adjust_sensitivity</string> <string name="key_adjust_sensitivity" translatable="false">dynisf_adjust_sensitivity</string>
<string name="key_openapsma_max_basal" translatable="false">openapsma_max_basal</string> <string name="key_openapsma_max_basal" translatable="false">openapsma_max_basal</string>
<string name="key_openapsama_use_autosens" translatable="false">openapsama_useautosens</string>
<string name="dynisf_adjust_sensitivity">Adjust sensitivity and BG</string> <string name="dynisf_adjust_sensitivity">Adjust sensitivity and BG</string>
<string name="DynISFAdjust_title" formatted="false">DynamicISF Adjustment Factor %</string> <string name="DynISFAdjust_title" formatted="false">DynamicISF Adjustment Factor %</string>
@ -112,6 +111,7 @@
<string name="smb_disabled_in_preferences">SMB disabled in preferences</string> <string name="smb_disabled_in_preferences">SMB disabled in preferences</string>
<string name="uam_disabled_in_preferences">UAM disabled in preferences</string> <string name="uam_disabled_in_preferences">UAM disabled in preferences</string>
<string name="autosens_disabled_in_preferences">Autosens disabled in preferences</string> <string name="autosens_disabled_in_preferences">Autosens disabled in preferences</string>
<string name="autosens_disabled_in_dyn_isf">Autosens disabled in DynISF</string>
<!-- Verify if needed in safety--> <!-- Verify if needed in safety-->
<string name="limiting_iob">Limiting IOB to %1$.1f U because of %2$s</string> <string name="limiting_iob">Limiting IOB to %1$.1f U because of %2$s</string>

View file

@ -30,7 +30,7 @@
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_openapsama_use_autosens" android:key="@string/key_use_autosens"
android:title="@string/openapsama_use_autosens" /> android:title="@string/openapsama_use_autosens" />
<SwitchPreference <SwitchPreference

View file

@ -30,7 +30,7 @@
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/key_openapsama_use_autosens" android:key="@string/key_use_autosens"
android:title="@string/openapsama_use_autosens" /> android:title="@string/openapsama_use_autosens" />
<SwitchPreference <SwitchPreference

View file

@ -1088,7 +1088,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
private fun updateSensitivity() { private fun updateSensitivity() {
_binding ?: return _binding ?: return
val lastAutosensData = overviewData.lastAutosensData(iobCobCalculator) val lastAutosensData = overviewData.lastAutosensData(iobCobCalculator)
if (constraintChecker.isAutosensModeEnabled().value() || !(config.NSCLIENT && lastAutosensData == null)) { if (config.NSCLIENT && sp.getBoolean(info.nightscout.core.utils.R.string.key_used_autosens_on_main_phone, false) ||
!config.NSCLIENT && constraintChecker.isAutosensModeEnabled().value()) {
binding.infoLayout.sensitivityIcon.setImageResource(info.nightscout.core.main.R.drawable.ic_swap_vert_black_48dp_green) binding.infoLayout.sensitivityIcon.setImageResource(info.nightscout.core.main.R.drawable.ic_swap_vert_black_48dp_green)
} else { } else {
binding.infoLayout.sensitivityIcon.setImageResource(info.nightscout.core.main.R.drawable.ic_x_swap_vert) binding.infoLayout.sensitivityIcon.setImageResource(info.nightscout.core.main.R.drawable.ic_x_swap_vert)

View file

@ -13,6 +13,7 @@ import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.utils.extensions.putDouble import info.nightscout.core.utils.extensions.putDouble
import info.nightscout.core.utils.extensions.putInt import info.nightscout.core.utils.extensions.putInt
import info.nightscout.core.utils.extensions.putString import info.nightscout.core.utils.extensions.putString
import info.nightscout.core.utils.extensions.storeBoolean
import info.nightscout.core.utils.extensions.storeDouble import info.nightscout.core.utils.extensions.storeDouble
import info.nightscout.core.utils.extensions.storeInt import info.nightscout.core.utils.extensions.storeInt
import info.nightscout.core.utils.extensions.storeString import info.nightscout.core.utils.extensions.storeString
@ -20,6 +21,7 @@ import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.core.validators.ValidatingEditTextPreference import info.nightscout.core.validators.ValidatingEditTextPreference
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.Overview import info.nightscout.interfaces.Overview
import info.nightscout.interfaces.constraints.ConstraintsChecker
import info.nightscout.interfaces.overview.OverviewMenus import info.nightscout.interfaces.overview.OverviewMenus
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
@ -56,7 +58,8 @@ class OverviewPlugin @Inject constructor(
private val config: Config, private val config: Config,
private val overviewData: OverviewData, private val overviewData: OverviewData,
private val overviewMenus: OverviewMenus, private val overviewMenus: OverviewMenus,
private val context: Context private val context: Context,
private val constraintsChecker: ConstraintsChecker
) : PluginBase( ) : PluginBase(
PluginDescription() PluginDescription()
.mainType(PluginType.GENERAL) .mainType(PluginType.GENERAL)
@ -187,6 +190,7 @@ class OverviewPlugin @Inject constructor(
.putDouble(R.string.key_statuslights_bat_warning, sp, rh) .putDouble(R.string.key_statuslights_bat_warning, sp, rh)
.putDouble(R.string.key_statuslights_bat_critical, sp, rh) .putDouble(R.string.key_statuslights_bat_critical, sp, rh)
.putInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, sp, rh) .putInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, sp, rh)
.put(rh.gs(info.nightscout.core.utils.R.string.key_used_autosens_on_main_phone), constraintsChecker.isAutosensModeEnabled().value()) // can be disabled by activated DynISF
override fun applyConfiguration(configuration: JSONObject) { override fun applyConfiguration(configuration: JSONObject) {
val previousUnits = sp.getString(info.nightscout.core.utils.R.string.key_units, "random") val previousUnits = sp.getString(info.nightscout.core.utils.R.string.key_units, "random")
@ -216,6 +220,8 @@ class OverviewPlugin @Inject constructor(
.storeDouble(R.string.key_statuslights_bat_warning, sp, rh) .storeDouble(R.string.key_statuslights_bat_warning, sp, rh)
.storeDouble(R.string.key_statuslights_bat_critical, sp, rh) .storeDouble(R.string.key_statuslights_bat_critical, sp, rh)
.storeInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, sp, rh) .storeInt(info.nightscout.core.utils.R.string.key_boluswizard_percentage, sp, rh)
.storeBoolean(info.nightscout.core.utils.R.string.key_used_autosens_on_main_phone, sp, rh)
val newUnits = sp.getString(info.nightscout.core.utils.R.string.key_units, "new") val newUnits = sp.getString(info.nightscout.core.utils.R.string.key_units, "new")
if (previousUnits != newUnits) { if (previousUnits != newUnits) {
overviewData.reset() overviewData.reset()

View file

@ -183,9 +183,7 @@ class SensitivityWeightedAveragePlugin @Inject constructor(
try { try {
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_maxtime))) sp.putDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_absorption_maxtime))) sp.putDouble(
info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble( info.nightscout.core.utils.R.string.key_absorption_maxtime, configuration.getDouble(
rh.gs( rh.gs(info.nightscout.core.utils.R.string.key_absorption_maxtime)
info.nightscout.core.utils.R.string.key_absorption_maxtime
)
) )
) )
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))) sp.putDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_period))) sp.putDouble(
@ -194,16 +192,12 @@ class SensitivityWeightedAveragePlugin @Inject constructor(
) )
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble( info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(
rh.gs( rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_max)
info.nightscout.core.utils.R.string.key_openapsama_autosens_max
)
) )
) )
if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble( if (configuration.has(rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min))) sp.getDouble(
info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble( info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(
rh.gs( rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min)
info.nightscout.core.utils.R.string.key_openapsama_autosens_min
)
) )
) )
} catch (e: JSONException) { } catch (e: JSONException) {