Merge branch 'Autotune/SaveLastRun' into Autotune/TestTuneWeekDaysMerge
# Conflicts: # app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneFragment.kt # app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt
This commit is contained in:
commit
31d9c0ea50
3 changed files with 64 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.general.autotune
|
||||
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
|
@ -87,6 +88,7 @@ class AutotuneFragment : DaggerFragment() {
|
|||
sp.putBoolean(R.string.key_autotune_tune_insulin_curve, false) // put to false tune insulin curve
|
||||
sp.putBoolean(R.string.key_autotune_additional_log, false) // put to false additional log
|
||||
autotunePlugin.lastRun = sp.getLong(R.string.key_autotune_last_run, 0)
|
||||
autotunePlugin.loadLastRun()
|
||||
if (autotunePlugin.lastNbDays.isEmpty())
|
||||
autotunePlugin.lastNbDays = sp.getInt(R.string.key_autotune_default_tune_days, 5).toString()
|
||||
val defaultValue = sp.getInt(R.string.key_autotune_default_tune_days, 5).toDouble()
|
||||
|
@ -168,6 +170,7 @@ class AutotuneFragment : DaggerFragment() {
|
|||
autotunePlugin.tunedProfile?.profilename = localName
|
||||
autotunePlugin.updateProfile(autotunePlugin.tunedProfile)
|
||||
autotunePlugin.updateButtonVisibility = View.GONE
|
||||
autotunePlugin.saveLastRun()
|
||||
uel.log(
|
||||
UserEntry.Action.STORE_PROFILE,
|
||||
UserEntry.Sources.Autotune,
|
||||
|
@ -187,6 +190,7 @@ class AutotuneFragment : DaggerFragment() {
|
|||
autotunePlugin.tunedProfile?.profilename = ""
|
||||
autotunePlugin.updateProfile(autotunePlugin.pumpProfile)
|
||||
autotunePlugin.updateButtonVisibility = View.VISIBLE
|
||||
autotunePlugin.saveLastRun()
|
||||
uel.log(
|
||||
UserEntry.Action.STORE_PROFILE,
|
||||
UserEntry.Sources.Autotune,
|
||||
|
@ -275,6 +279,12 @@ class AutotuneFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.tuneLastrun.setOnClickListener {
|
||||
autotunePlugin.loadLastRun()
|
||||
updateGui()
|
||||
}
|
||||
binding.tuneLastrun.paintFlags = binding.tuneLastrun.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
|
@ -288,7 +298,6 @@ class AutotuneFragment : DaggerFragment() {
|
|||
}, { fabricPrivacy.logException(it) })
|
||||
checkNewDay()
|
||||
binding.selectWeekDays.visibility = binding.showWeekDaysCheckbox.isChecked.toVisibility()
|
||||
binding.tuneDays.value = autotunePlugin.lastNbDays.toDouble()
|
||||
updateGui()
|
||||
}
|
||||
|
||||
|
@ -301,6 +310,7 @@ class AutotuneFragment : DaggerFragment() {
|
|||
@Synchronized
|
||||
private fun updateGui() {
|
||||
_binding ?: return
|
||||
binding.tuneDays.value = autotunePlugin.lastNbDays.toDouble()
|
||||
profileStore = activePlugin.activeProfileSource.profile ?: ProfileStore(injector, JSONObject(), dateUtil)
|
||||
profileName = if (binding.profileList.text.toString() == rh.gs(R.string.active)) "" else binding.profileList.text.toString()
|
||||
profileFunction.getProfile()?.let { currentProfile ->
|
||||
|
|
|
@ -7,6 +7,7 @@ import info.nightscout.androidaps.data.LocalInsulin
|
|||
import info.nightscout.androidaps.data.ProfileSealed
|
||||
import info.nightscout.androidaps.database.entities.UserEntry
|
||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||
import info.nightscout.androidaps.extensions.pureProfileFromJson
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
|
@ -17,6 +18,7 @@ import info.nightscout.androidaps.plugins.general.autotune.events.EventAutotuneU
|
|||
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
||||
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
import info.nightscout.androidaps.utils.MidnightTime
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||
|
@ -219,7 +221,7 @@ class AutotunePlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
lastRunSuccess = true
|
||||
sp.putLong(R.string.key_autotune_last_run, lastRun)
|
||||
saveLastRun()
|
||||
rxBus.send(EventAutotuneUpdateGui())
|
||||
calculationRunning = false
|
||||
tunedProfile?.let {
|
||||
|
@ -328,6 +330,54 @@ class AutotunePlugin @Inject constructor(
|
|||
localProfilePlugin.storeSettings()
|
||||
}
|
||||
|
||||
fun saveLastRun() {
|
||||
val json = JSONObject()
|
||||
json.put("lastNbDays", lastNbDays)
|
||||
json.put("lastRun",lastRun)
|
||||
json.put("pumpProfile", pumpProfile.profile.toPureNsJson(dateUtil))
|
||||
json.put("pumpProfileName", pumpProfile.profilename)
|
||||
json.put("pumpPeak", pumpProfile.peak)
|
||||
json.put("pumpDia", pumpProfile.dia)
|
||||
json.put("tunedProfile", tunedProfile?.profile?.toPureNsJson(dateUtil))
|
||||
json.put("tunedCircadianProfile", tunedProfile?.circadianProfile?.toPureNsJson(dateUtil))
|
||||
json.put("tunedProfileName", tunedProfile?.profilename)
|
||||
json.put("tunedPeak", tunedProfile?.peak)
|
||||
json.put("tunedDia", tunedProfile?.dia)
|
||||
json.put("result", result)
|
||||
json.put("updateButtonVisibility", updateButtonVisibility)
|
||||
sp.putString(R.string.key_autotune_last_run, json.toString())
|
||||
}
|
||||
|
||||
fun loadLastRun() {
|
||||
result = ""
|
||||
lastRunSuccess = false
|
||||
val json = JSONObject(sp.getString(R.string.key_autotune_last_run, ""))
|
||||
lastNbDays = JsonHelper.safeGetString(json, "lastNbDays", "")
|
||||
lastRun = JsonHelper.safeGetLong(json, "lastRun")
|
||||
val pumpPeak = JsonHelper.safeGetInt(json, "pumpPeak")
|
||||
val pumpDia = JsonHelper.safeGetDouble(json, "pumpDia")
|
||||
var localInsulin = LocalInsulin("PumpInsulin", pumpPeak, pumpDia)
|
||||
selectedProfile = JsonHelper.safeGetString(json, "pumpProfileName", "")
|
||||
val profile = JsonHelper.safeGetJSONObject(json, "pumpProfile", null)?.let { pureProfileFromJson(it, dateUtil) }
|
||||
?:return
|
||||
pumpProfile = ATProfile(ProfileSealed.Pure(profile), localInsulin, injector).also { it.profilename = selectedProfile }
|
||||
val tunedPeak = JsonHelper.safeGetInt(json, "tunedPeak")
|
||||
val tunedDia = JsonHelper.safeGetDouble(json, "tunedDia")
|
||||
localInsulin = LocalInsulin("PumpInsulin", tunedPeak, tunedDia)
|
||||
val tunedProfileName = JsonHelper.safeGetString(json, "tunedProfileName", "")
|
||||
val tuned = JsonHelper.safeGetJSONObject(json, "tunedProfile", null)?.let { pureProfileFromJson(it, dateUtil) }
|
||||
?: return
|
||||
val circadianTuned = JsonHelper.safeGetJSONObject(json, "tunedCircadianProfile", null)?.let { pureProfileFromJson(it, dateUtil) }
|
||||
?: return
|
||||
tunedProfile = ATProfile(ProfileSealed.Pure(tuned), localInsulin, injector).also { atProfile ->
|
||||
atProfile.profilename = tunedProfileName
|
||||
atProfile.circadianProfile = ProfileSealed.Pure(circadianTuned)
|
||||
}
|
||||
result = JsonHelper.safeGetString(json, "result", "")
|
||||
updateButtonVisibility = JsonHelper.safeGetInt(json, "updateButtonVisibility")
|
||||
lastRunSuccess = true
|
||||
}
|
||||
|
||||
fun calcDays(daysBack:Int): Int {
|
||||
var endTime = MidnightTime.calc(dateUtil.now()) + autotuneStartHour * 60 * 60 * 1000L
|
||||
if (endTime > dateUtil.now()) endTime -= T.days(1).msecs() // Check if 4 AM is before now
|
||||
|
|
|
@ -179,7 +179,8 @@
|
|||
android:gravity="start"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:textSize="14sp" />
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/colorCalculatorButton"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
Loading…
Reference in a new issue