show autosens icon properly
This commit is contained in:
parent
ccabee0399
commit
0ef3d9b375
13 changed files with 30 additions and 20 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -150,5 +150,7 @@
|
|||
<string name="key_objectiveuseactions" translatable="false">ObjectivesActionsUsed</string>
|
||||
<string name="key_objectiveusescale" translatable="false">ObjectivesScaleUsed</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>
|
|
@ -270,7 +270,7 @@ class OpenAPSAMAPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
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)
|
||||
return value
|
||||
}
|
||||
|
|
|
@ -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<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)
|
||||
return value
|
||||
}
|
||||
|
|
|
@ -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<Boolean>): Constraint<Boolean> {
|
||||
value.set(false, rh.gs(R.string.autosens_disabled_in_dyn_isf), this)
|
||||
return value
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@
|
|||
<string name="key_DynISFAdjust" translatable="false">DynISFAdjust</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_openapsama_use_autosens" translatable="false">openapsama_useautosens</string>
|
||||
|
||||
<string name="dynisf_adjust_sensitivity">Adjust sensitivity and BG</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="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_dyn_isf">Autosens disabled in DynISF</string>
|
||||
|
||||
<!-- Verify if needed in safety-->
|
||||
<string name="limiting_iob">Limiting IOB to %1$.1f U because of %2$s</string>
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_openapsama_use_autosens"
|
||||
android:key="@string/key_use_autosens"
|
||||
android:title="@string/openapsama_use_autosens" />
|
||||
|
||||
<SwitchPreference
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_openapsama_use_autosens"
|
||||
android:key="@string/key_use_autosens"
|
||||
android:title="@string/openapsama_use_autosens" />
|
||||
|
||||
<SwitchPreference
|
||||
|
|
|
@ -1088,7 +1088,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
private fun updateSensitivity() {
|
||||
_binding ?: return
|
||||
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)
|
||||
} else {
|
||||
binding.infoLayout.sensitivityIcon.setImageResource(info.nightscout.core.main.R.drawable.ic_x_swap_vert)
|
||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.core.ui.dialogs.OKDialog
|
|||
import info.nightscout.core.utils.extensions.putDouble
|
||||
import info.nightscout.core.utils.extensions.putInt
|
||||
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.storeInt
|
||||
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.interfaces.Config
|
||||
import info.nightscout.interfaces.Overview
|
||||
import info.nightscout.interfaces.constraints.ConstraintsChecker
|
||||
import info.nightscout.interfaces.overview.OverviewMenus
|
||||
import info.nightscout.interfaces.plugin.PluginBase
|
||||
import info.nightscout.interfaces.plugin.PluginDescription
|
||||
|
@ -56,7 +58,8 @@ class OverviewPlugin @Inject constructor(
|
|||
private val config: Config,
|
||||
private val overviewData: OverviewData,
|
||||
private val overviewMenus: OverviewMenus,
|
||||
private val context: Context
|
||||
private val context: Context,
|
||||
private val constraintsChecker: ConstraintsChecker
|
||||
) : PluginBase(
|
||||
PluginDescription()
|
||||
.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_critical, 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) {
|
||||
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_critical, 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")
|
||||
if (previousUnits != newUnits) {
|
||||
overviewData.reset()
|
||||
|
|
|
@ -183,9 +183,7 @@ class SensitivityWeightedAveragePlugin @Inject constructor(
|
|||
try {
|
||||
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(
|
||||
rh.gs(
|
||||
info.nightscout.core.utils.R.string.key_absorption_maxtime
|
||||
)
|
||||
rh.gs(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(
|
||||
|
@ -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(
|
||||
info.nightscout.core.utils.R.string.key_openapsama_autosens_max, configuration.getDouble(
|
||||
rh.gs(
|
||||
info.nightscout.core.utils.R.string.key_openapsama_autosens_max
|
||||
)
|
||||
rh.gs(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(
|
||||
info.nightscout.core.utils.R.string.key_openapsama_autosens_min, configuration.getDouble(
|
||||
rh.gs(
|
||||
info.nightscout.core.utils.R.string.key_openapsama_autosens_min
|
||||
)
|
||||
rh.gs(info.nightscout.core.utils.R.string.key_openapsama_autosens_min)
|
||||
)
|
||||
)
|
||||
} catch (e: JSONException) {
|
||||
|
|
Loading…
Reference in a new issue