From ee89687653ab53b756425ba87af8ac2514f83b8b Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 20 Aug 2021 09:00:51 +0200 Subject: [PATCH 1/2] Fix Basal Sum But sum is only upated when profile is saved --- .../plugins/profile/local/LocalProfileFragment.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index 1d2eb8f84e..0542c9d0f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -55,7 +55,7 @@ class LocalProfileFragment : DaggerFragment() { private val save = Runnable { doEdit() - basalView?.updateLabel(resourceHelper.gs(R.string.basal_label) + ": " + sumLabel()) + basalView?.updateLabel(resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(spinner?.selectedItem.toString())) localProfilePlugin.profile?.getSpecificProfile(spinner?.selectedItem.toString())?.let { binding.basalGraph.show(ProfileSealed.Pure(it)) } @@ -71,8 +71,8 @@ class LocalProfileFragment : DaggerFragment() { } } - private fun sumLabel(): String { - val profile = localProfilePlugin.profile?.getDefaultProfile() + private fun sumLabel(profileName: String?): String { + val profile = profileName?.let { localProfilePlugin.profile?.getSpecificProfile(profileName) } val sum = profile?.let { ProfileSealed.Pure(profile).baseBasalSum() } ?: 0.0 return " ∑" + DecimalFormatter.to2Decimal(sum) + resourceHelper.gs(R.string.insulin_unit_shortname) } @@ -129,7 +129,7 @@ class LocalProfileFragment : DaggerFragment() { binding.dia.setParams(currentProfile.dia, hardLimits.minDia(), hardLimits.maxDia(), 0.1, DecimalFormat("0.0"), false, binding.save, textWatch) binding.dia.tag = "LP_DIA" TimeListEdit(context, aapsLogger, dateUtil, view, R.id.ic, "IC", resourceHelper.gs(R.string.ic_label), currentProfile.ic, null, hardLimits.minIC(), hardLimits.maxIC(), 0.1, DecimalFormat("0.0"), save) - basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.basal_holder, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), currentProfile.basal, null, pumpDescription.basalMinimumRate, pumpDescription.basalMaximumRate, 0.01, DecimalFormat("0.00"), save) + basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.basal_holder, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(currentProfile.name), currentProfile.basal, null, pumpDescription.basalMinimumRate, pumpDescription.basalMaximumRate, 0.01, DecimalFormat("0.00"), save) if (units == Constants.MGDL) { TimeListEdit(context, aapsLogger, dateUtil, view, R.id.isf, "ISF", resourceHelper.gs(R.string.isf_label), currentProfile.isf, null, HardLimits.MIN_ISF, HardLimits.MAX_ISF, 1.0, DecimalFormat("0"), save) TimeListEdit(context, aapsLogger, dateUtil, view, R.id.target, "TARGET", resourceHelper.gs(R.string.target_label), currentProfile.targetLow, currentProfile.targetHigh, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save) From 45f576b838221229e3e5ddbeed1ca4e58ee82844 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 18 Sep 2021 21:54:29 +0200 Subject: [PATCH 2/2] Add getEditProfile function to calculate SumLabel --- .../profile/local/LocalProfileFragment.kt | 8 ++++---- .../profile/local/LocalProfilePlugin.kt | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index 0542c9d0f6..d166348713 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -55,7 +55,7 @@ class LocalProfileFragment : DaggerFragment() { private val save = Runnable { doEdit() - basalView?.updateLabel(resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(spinner?.selectedItem.toString())) + basalView?.updateLabel(resourceHelper.gs(R.string.basal_label) + ": " + sumLabel()) localProfilePlugin.profile?.getSpecificProfile(spinner?.selectedItem.toString())?.let { binding.basalGraph.show(ProfileSealed.Pure(it)) } @@ -71,8 +71,8 @@ class LocalProfileFragment : DaggerFragment() { } } - private fun sumLabel(profileName: String?): String { - val profile = profileName?.let { localProfilePlugin.profile?.getSpecificProfile(profileName) } + private fun sumLabel(): String { + val profile = localProfilePlugin.getEditProfile() val sum = profile?.let { ProfileSealed.Pure(profile).baseBasalSum() } ?: 0.0 return " ∑" + DecimalFormatter.to2Decimal(sum) + resourceHelper.gs(R.string.insulin_unit_shortname) } @@ -129,7 +129,7 @@ class LocalProfileFragment : DaggerFragment() { binding.dia.setParams(currentProfile.dia, hardLimits.minDia(), hardLimits.maxDia(), 0.1, DecimalFormat("0.0"), false, binding.save, textWatch) binding.dia.tag = "LP_DIA" TimeListEdit(context, aapsLogger, dateUtil, view, R.id.ic, "IC", resourceHelper.gs(R.string.ic_label), currentProfile.ic, null, hardLimits.minIC(), hardLimits.maxIC(), 0.1, DecimalFormat("0.0"), save) - basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.basal_holder, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(currentProfile.name), currentProfile.basal, null, pumpDescription.basalMinimumRate, pumpDescription.basalMaximumRate, 0.01, DecimalFormat("0.00"), save) + basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.basal_holder, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), currentProfile.basal, null, pumpDescription.basalMinimumRate, pumpDescription.basalMaximumRate, 0.01, DecimalFormat("0.00"), save) if (units == Constants.MGDL) { TimeListEdit(context, aapsLogger, dateUtil, view, R.id.isf, "ISF", resourceHelper.gs(R.string.isf_label), currentProfile.isf, null, HardLimits.MIN_ISF, HardLimits.MAX_ISF, 1.0, DecimalFormat("0"), save) TimeListEdit(context, aapsLogger, dateUtil, view, R.id.target, "TARGET", resourceHelper.gs(R.string.target_label), currentProfile.targetLow, currentProfile.targetHigh, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index 8b74f760cc..519c283f94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -12,6 +12,7 @@ import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.events.EventProfileStoreChanged import info.nightscout.androidaps.extensions.blockFromJsonArray +import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -21,6 +22,7 @@ import info.nightscout.androidaps.receivers.DataWorker import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HardLimits +import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -123,6 +125,23 @@ class LocalProfilePlugin @Inject constructor( return true } + @Synchronized + fun getEditProfile(): PureProfile? { + val profile = JSONObject() + with(profiles[currentProfileIndex]) { + profile.put("dia", dia) + profile.put("carbratio", ic) + profile.put("sens", isf) + profile.put("basal", basal) + profile.put("target_low", targetLow) + profile.put("target_high", targetHigh) + profile.put("units", if (mgdl) Constants.MGDL else Constants.MMOL) + profile.put("timezone", TimeZone.getDefault().id) + } + val defaultUnits = JsonHelper.safeGetStringAllowNull(profile, "units", null) + return pureProfileFromJson(profile, dateUtil, defaultUnits) + } + @Synchronized fun storeSettings(activity: FragmentActivity? = null) { for (i in 0 until numOfProfiles) {