ApsMode enum - refactor of secureValueOf
This commit is contained in:
parent
5485792801
commit
6205c9b893
6 changed files with 7 additions and 13 deletions
|
@ -8,12 +8,6 @@ enum class ApsMode() {
|
|||
|
||||
companion object {
|
||||
|
||||
fun secureValueOf(stringValue: String): ApsMode {
|
||||
return try {
|
||||
valueOf(stringValue.uppercase())
|
||||
} catch (e: IllegalArgumentException) {
|
||||
UNDEFINED
|
||||
}
|
||||
}
|
||||
fun fromString(stringValue: String?) = values().firstOrNull { it.name == (stringValue?.uppercase() ?: UNDEFINED) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ class LoopPlugin @Inject constructor(
|
|||
get() {
|
||||
val closedLoopEnabled = constraintChecker.isClosedLoopAllowed()
|
||||
val maxIobAllowed = constraintChecker.getMaxIOBAllowed().value()
|
||||
val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
val apsMode = ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
val pump = activePlugin.activePump
|
||||
var isLGS = false
|
||||
if (!isSuspended && !pump.isSuspended()) if (closedLoopEnabled.value()) if (maxIobAllowed == HardLimits.MAX_IOB_LGS || apsMode == ApsMode.LGS) isLGS = true
|
||||
|
|
|
@ -16,7 +16,7 @@ class Objective6(injector: HasAndroidInjector) : Objective(injector, "maxiob", R
|
|||
tasks.add(MinimumDurationTask(this, T.days(1).msecs()))
|
||||
tasks.add(
|
||||
object : Task(this, R.string.closedmodeenabled) {
|
||||
override fun isCompleted(): Boolean = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) == ApsMode.CLOSED
|
||||
override fun isCompleted(): Boolean = ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name)) == ApsMode.CLOSED
|
||||
})
|
||||
tasks.add(
|
||||
object : Task(this, R.string.maxiobset) {
|
||||
|
|
|
@ -68,7 +68,7 @@ class SafetyPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
val mode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
val mode = ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
if (mode == ApsMode.OPEN) value.set(aapsLogger, false, rh.gs(R.string.closedmodedisabledinpreferences), this)
|
||||
if (!config.isEngineeringModeOrRelease()) {
|
||||
if (value.value()) {
|
||||
|
@ -160,7 +160,7 @@ class SafetyPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
|
||||
val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
val apsMode = ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
if (apsMode == ApsMode.LGS) maxIob.setIfSmaller(aapsLogger, HardLimits.MAX_IOB_LGS, rh.gs(info.nightscout.core.ui.R.string.limiting_iob, HardLimits.MAX_IOB_LGS, rh.gs(info.nightscout.core.ui.R.string.lowglucosesuspend)), this)
|
||||
return maxIob
|
||||
}
|
||||
|
|
|
@ -1284,7 +1284,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private fun getApsModeText(): String =
|
||||
when (ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))) {
|
||||
when (ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))) {
|
||||
ApsMode.OPEN -> rh.gs(info.nightscout.core.ui.R.string.openloop)
|
||||
ApsMode.CLOSED -> rh.gs(info.nightscout.core.ui.R.string.closedloop)
|
||||
ApsMode.LGS -> rh.gs(info.nightscout.core.ui.R.string.lowglucosesuspend)
|
||||
|
|
|
@ -162,7 +162,7 @@ class LoopDialog : DaggerDialogFragment() {
|
|||
val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(Constraint(true))
|
||||
val closedLoopAllowed2 = activePlugin.activeObjectives?.isAccomplished(Objectives.MAXIOB_OBJECTIVE) ?: false
|
||||
val lgsEnabled = constraintChecker.isLgsAllowed(Constraint(true))
|
||||
val apsMode = ApsMode.secureValueOf(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
val apsMode = ApsMode.fromString(sp.getString(info.nightscout.core.utils.R.string.key_aps_mode, ApsMode.OPEN.name))
|
||||
val pump = activePlugin.activePump
|
||||
|
||||
binding.overviewDisconnect15m.visibility = pumpDescription.tempDurationStep15mAllowed.toVisibility()
|
||||
|
|
Loading…
Reference in a new issue