Profile: fix graphs

This commit is contained in:
Milos Kozak 2022-02-26 21:02:06 +01:00
parent fe4fbbf21e
commit bbe6248f81
2 changed files with 5 additions and 8 deletions

View file

@ -61,7 +61,7 @@ class LocalProfileFragment : DaggerFragment() {
private val save = Runnable { private val save = Runnable {
doEdit() doEdit()
basalView?.updateLabel(rh.gs(R.string.basal_label) + ": " + sumLabel()) basalView?.updateLabel(rh.gs(R.string.basal_label) + ": " + sumLabel())
localProfilePlugin.profile?.getSpecificProfile(binding.profileList.text.toString())?.let { localProfilePlugin.getEditedProfile()?.let {
binding.basalGraph.show(ProfileSealed.Pure(it)) binding.basalGraph.show(ProfileSealed.Pure(it))
binding.icGraph.show(ProfileSealed.Pure(it)) binding.icGraph.show(ProfileSealed.Pure(it))
binding.isfGraph.show(ProfileSealed.Pure(it)) binding.isfGraph.show(ProfileSealed.Pure(it))
@ -81,7 +81,7 @@ class LocalProfileFragment : DaggerFragment() {
} }
private fun sumLabel(): String { private fun sumLabel(): String {
val profile = localProfilePlugin.getEditProfile() val profile = localProfilePlugin.getEditedProfile()
val sum = profile?.let { ProfileSealed.Pure(profile).baseBasalSum() } ?: 0.0 val sum = profile?.let { ProfileSealed.Pure(profile).baseBasalSum() } ?: 0.0
return "" + DecimalFormatter.to2Decimal(sum) + rh.gs(R.string.insulin_unit_shortname) return "" + DecimalFormatter.to2Decimal(sum) + rh.gs(R.string.insulin_unit_shortname)
} }
@ -237,10 +237,7 @@ class LocalProfileFragment : DaggerFragment() {
localProfilePlugin.currentProfileIndex = position localProfilePlugin.currentProfileIndex = position
localProfilePlugin.isEdited = false localProfilePlugin.isEdited = false
build() build()
}, { }, null
val selection = localProfilePlugin.currentProfileIndex
if (selection in 0 until (binding.profileList.adapter?.count ?: -1)) binding.profileList.setSelection(selection)
}
) )
} }
} else { } else {
@ -248,7 +245,7 @@ class LocalProfileFragment : DaggerFragment() {
build() build()
} }
} }
localProfilePlugin.profile?.getSpecificProfile(binding.profileList.text.toString())?.let { localProfilePlugin.getEditedProfile()?.let {
binding.basalGraph.show(ProfileSealed.Pure(it)) binding.basalGraph.show(ProfileSealed.Pure(it))
binding.icGraph.show(ProfileSealed.Pure(it)) binding.icGraph.show(ProfileSealed.Pure(it))
binding.isfGraph.show(ProfileSealed.Pure(it)) binding.isfGraph.show(ProfileSealed.Pure(it))

View file

@ -170,7 +170,7 @@ class LocalProfilePlugin @Inject constructor(
} }
@Synchronized @Synchronized
fun getEditProfile(): PureProfile? { fun getEditedProfile(): PureProfile? {
val profile = JSONObject() val profile = JSONObject()
with(profiles[currentProfileIndex]) { with(profiles[currentProfileIndex]) {
profile.put("dia", dia) profile.put("dia", dia)