Fix loadLastRun

This commit is contained in:
Philoul 2022-06-08 07:42:00 +02:00
parent e89e5102f7
commit 636bdb0e94

View file

@ -319,31 +319,34 @@ class AutotunePlugin @Inject constructor(
fun loadLastRun() { fun loadLastRun() {
result = "" result = ""
lastRunSuccess = false lastRunSuccess = false
val json = JSONObject(sp.getString(R.string.key_autotune_last_run, "")) try {
lastNbDays = JsonHelper.safeGetString(json, "lastNbDays", "") val json = JSONObject(sp.getString(R.string.key_autotune_last_run, ""))
lastRun = JsonHelper.safeGetLong(json, "lastRun") lastNbDays = JsonHelper.safeGetString(json, "lastNbDays", "")
val pumpPeak = JsonHelper.safeGetInt(json, "pumpPeak") lastRun = JsonHelper.safeGetLong(json, "lastRun")
val pumpDia = JsonHelper.safeGetDouble(json, "pumpDia") val pumpPeak = JsonHelper.safeGetInt(json, "pumpPeak")
var localInsulin = LocalInsulin("PumpInsulin", pumpPeak, pumpDia) val pumpDia = JsonHelper.safeGetDouble(json, "pumpDia")
selectedProfile = JsonHelper.safeGetString(json, "pumpProfileName", "") var localInsulin = LocalInsulin("PumpInsulin", pumpPeak, pumpDia)
val profile = JsonHelper.safeGetJSONObject(json, "pumpProfile", null)?.let { pureProfileFromJson(it, dateUtil) } selectedProfile = JsonHelper.safeGetString(json, "pumpProfileName", "")
?:return val profile = JsonHelper.safeGetJSONObject(json, "pumpProfile", null)?.let { pureProfileFromJson(it, dateUtil) }
pumpProfile = ATProfile(ProfileSealed.Pure(profile), localInsulin, injector).also { it.profilename = selectedProfile } ?: return
val tunedPeak = JsonHelper.safeGetInt(json, "tunedPeak") pumpProfile = ATProfile(ProfileSealed.Pure(profile), localInsulin, injector).also { it.profilename = selectedProfile }
val tunedDia = JsonHelper.safeGetDouble(json, "tunedDia") val tunedPeak = JsonHelper.safeGetInt(json, "tunedPeak")
localInsulin = LocalInsulin("PumpInsulin", tunedPeak, tunedDia) val tunedDia = JsonHelper.safeGetDouble(json, "tunedDia")
val tunedProfileName = JsonHelper.safeGetString(json, "tunedProfileName", "") localInsulin = LocalInsulin("PumpInsulin", tunedPeak, tunedDia)
val tuned = JsonHelper.safeGetJSONObject(json, "tunedProfile", null)?.let { pureProfileFromJson(it, dateUtil) } val tunedProfileName = JsonHelper.safeGetString(json, "tunedProfileName", "")
?: return val tuned = JsonHelper.safeGetJSONObject(json, "tunedProfile", null)?.let { pureProfileFromJson(it, dateUtil) }
val circadianTuned = JsonHelper.safeGetJSONObject(json, "tunedCircadianProfile", null)?.let { pureProfileFromJson(it, dateUtil) } ?: return
?: return val circadianTuned = JsonHelper.safeGetJSONObject(json, "tunedCircadianProfile", null)?.let { pureProfileFromJson(it, dateUtil) }
tunedProfile = ATProfile(ProfileSealed.Pure(tuned), localInsulin, injector).also { atProfile -> ?: return
atProfile.profilename = tunedProfileName tunedProfile = ATProfile(ProfileSealed.Pure(tuned), localInsulin, injector).also { atProfile ->
atProfile.circadianProfile = ProfileSealed.Pure(circadianTuned) atProfile.profilename = tunedProfileName
atProfile.circadianProfile = ProfileSealed.Pure(circadianTuned)
}
result = JsonHelper.safeGetString(json, "result", "")
updateButtonVisibility = JsonHelper.safeGetInt(json, "updateButtonVisibility")
lastRunSuccess = true
} catch (e: Exception) {
} }
result = JsonHelper.safeGetString(json, "result", "")
updateButtonVisibility = JsonHelper.safeGetInt(json, "updateButtonVisibility")
lastRunSuccess = true
} }
private fun log(message: String) { private fun log(message: String) {