Medtrum: Move Initializers to onStart()

This commit is contained in:
jbr7rr 2023-09-14 21:14:09 +02:00
parent 471ed28a04
commit ac50149563
3 changed files with 13 additions and 12 deletions

View file

@ -95,6 +95,7 @@ import kotlin.math.abs
override fun onStart() {
super.onStart()
aapsLogger.debug(LTag.PUMP, "MedtrumPlugin onStart()")
medtrumPump.loadVarsFromSP()
val intent = Intent(context, MedtrumService::class.java)
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE)
disposable += rxBus

View file

@ -279,7 +279,16 @@ class MedtrumPump @Inject constructor(
var desiredHourlyMaxInsulin: Int = 40
var desiredDailyMaxInsulin: Int = 180
init {
fun pumpType(): PumpType = pumpType(deviceType)
fun pumpType(type: Int): PumpType =
when (type) {
MedtrumSnUtil.MD_0201, MedtrumSnUtil.MD_8201 -> PumpType.MEDTRUM_NANO
MedtrumSnUtil.MD_8301 -> PumpType.MEDTRUM_300U
else -> PumpType.MEDTRUM_UNTESTED
}
fun loadVarsFromSP() {
// Load stuff from SP
_patchSessionToken = sp.getLong(R.string.key_session_token, 0L)
_lastConnection = sp.getLong(R.string.key_last_connection, 0L)
@ -304,16 +313,9 @@ class MedtrumPump @Inject constructor(
} catch (e: Exception) {
aapsLogger.warn(LTag.PUMP, "Error decoding basal profile from SP: $encodedString")
}
}
fun pumpType(): PumpType = pumpType(deviceType)
fun pumpType(type: Int): PumpType =
when (type) {
MedtrumSnUtil.MD_0201, MedtrumSnUtil.MD_8201 -> PumpType.MEDTRUM_NANO
MedtrumSnUtil.MD_8301 -> PumpType.MEDTRUM_300U
else -> PumpType.MEDTRUM_UNTESTED
}
loadUserSettingsFromSP()
}
fun loadUserSettingsFromSP() {
desiredPatchExpiration = sp.getBoolean(R.string.key_patch_expiration, false)

View file

@ -145,8 +145,6 @@ class MedtrumService : DaggerService(), BLECommCallback {
handleConnectionStateChange(connectionState)
}
}
medtrumPump.loadUserSettingsFromSP()
}
override fun onDestroy() {