do not cache TBE and EB for displaying

This commit is contained in:
Milos Kozak 2021-11-07 23:02:38 +01:00
parent 8f3f9a7a65
commit 5d3035c09c
3 changed files with 17 additions and 37 deletions

View file

@ -76,8 +76,6 @@ class OverviewData @Inject constructor(
pumpStatus = ""
calcProgress = ""
lastBg = null
temporaryBasal = null
extendedBolus = null
bolusIob = null
basalIob = null
cobInfo = null
@ -161,11 +159,10 @@ class OverviewData @Inject constructor(
* TEMPORARY BASAL
*/
var temporaryBasal: TemporaryBasal? = null
val temporaryBasalText: String
get() =
profileFunction.getProfile()?.let { profile ->
var temporaryBasal = iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now())
if (temporaryBasal?.isInProgress == false) temporaryBasal = null
temporaryBasal?.let { "T:" + it.toStringShort() }
?: rh.gs(R.string.pump_basebasalrate, profile.getBasal())
@ -173,7 +170,7 @@ class OverviewData @Inject constructor(
val temporaryBasalDialogText: String
get() = profileFunction.getProfile()?.let { profile ->
temporaryBasal?.let { temporaryBasal ->
iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now())?.let { temporaryBasal ->
"${rh.gs(R.string.basebasalrate_label)}: ${rh.gs(R.string.pump_basebasalrate, profile.getBasal())}" +
"\n" + rh.gs(R.string.tempbasal_label) + ": " + temporaryBasal.toStringFull(profile, dateUtil)
}
@ -183,7 +180,7 @@ class OverviewData @Inject constructor(
val temporaryBasalIcon: Int
get() =
profileFunction.getProfile()?.let { profile ->
temporaryBasal?.let { temporaryBasal ->
iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now())?.let { temporaryBasal ->
val percentRate = temporaryBasal.convertedToPercent(dateUtil.now(), profile)
when {
percentRate > 100 -> R.drawable.ic_cp_basal_tbr_high
@ -194,27 +191,23 @@ class OverviewData @Inject constructor(
} ?: R.drawable.ic_cp_basal_no_tbr
val temporaryBasalColor: Int
get() = temporaryBasal?.let { rh.gc(R.color.basal) }
get() = iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now())?.let { rh.gc(R.color.basal) }
?: rh.gc(R.color.defaulttextcolor)
/*
* EXTENDED BOLUS
*/
var extendedBolus: ExtendedBolus? = null
val extendedBolusText: String
get() =
extendedBolus?.let { extendedBolus ->
if (!extendedBolus.isInProgress(dateUtil)) {
this@OverviewData.extendedBolus = null
""
} else if (!activePlugin.activePump.isFakingTempsByExtendedBoluses) rh.gs(R.string.pump_basebasalrate, extendedBolus.rate)
iobCobCalculator.getExtendedBolus(dateUtil.now())?.let { extendedBolus ->
if (!extendedBolus.isInProgress(dateUtil)) ""
else if (!activePlugin.activePump.isFakingTempsByExtendedBoluses) rh.gs(R.string.pump_basebasalrate, extendedBolus.rate)
else ""
} ?: ""
val extendedBolusDialogText: String
get() = extendedBolus?.toStringFull(dateUtil) ?: ""
get() = iobCobCalculator.getExtendedBolus(dateUtil.now())?.toStringFull(dateUtil) ?: ""
/*
* IOB, COB
@ -555,7 +548,14 @@ class OverviewData @Inject constructor(
// OfflineEvent
repository.getOfflineEventDataFromTimeToTime(fromTime, endTime, true).blockingGet()
.map { TherapyEventDataPoint(TherapyEvent(timestamp = it.timestamp, duration = it.duration, type = TherapyEvent.Type.APS_OFFLINE, glucoseUnit = TherapyEvent.GlucoseUnit.MMOL), rh, profileFunction, translator) }
.map {
TherapyEventDataPoint(
TherapyEvent(timestamp = it.timestamp, duration = it.duration, type = TherapyEvent.Type.APS_OFFLINE, glucoseUnit = TherapyEvent.GlucoseUnit.MMOL),
rh,
profileFunction,
translator
)
}
.forEach(filteredTreatments::add)
// Extended bolus

View file

@ -722,7 +722,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
binding.infoLayout.extendedLayout.setOnClickListener {
activity?.let { OKDialog.show(it, rh.gs(R.string.extended_bolus), overviewData.extendedBolusDialogText) }
}
binding.infoLayout.extendedLayout.visibility = (overviewData.extendedBolus != null && !pump.isFakingTempsByExtendedBoluses).toVisibility()
binding.infoLayout.extendedLayout.visibility = (iobCobCalculator.getExtendedBolus(dateUtil.now()) != null && !pump.isFakingTempsByExtendedBoluses).toVisibility()
}

View file

@ -91,14 +91,6 @@ class OverviewPlugin @Inject constructor(
.toObservable(EventIobCalculationProgress::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ overviewData.calcProgress = it.progress; overviewBus.send(EventUpdateOverview("EventIobCalculationProgress", OverviewData.Property.CALC_PROGRESS)) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ loadTemporaryBasal("EventTempBasalChange") }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ loadExtendedBolus("EventExtendedBolusChange") }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNewBG::class.java)
.observeOn(aapsSchedulers.io)
@ -272,8 +264,6 @@ class OverviewPlugin @Inject constructor(
private fun loadAll(from: String) {
loadBg(from)
loadProfile(from)
loadTemporaryBasal(from)
loadExtendedBolus(from)
loadTemporaryTarget(from)
loadIobCobResults(from)
loadAsData(from)
@ -290,16 +280,6 @@ class OverviewPlugin @Inject constructor(
overviewBus.send(EventUpdateOverview(from, OverviewData.Property.PROFILE))
}
private fun loadTemporaryBasal(from: String) {
overviewData.temporaryBasal = iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now())
overviewBus.send(EventUpdateOverview(from, OverviewData.Property.TEMPORARY_BASAL))
}
private fun loadExtendedBolus(from: String) {
overviewData.extendedBolus = iobCobCalculator.getExtendedBolus(dateUtil.now())
overviewBus.send(EventUpdateOverview(from, OverviewData.Property.EXTENDED_BOLUS))
}
private fun loadTemporaryTarget(from: String) {
val tempTarget = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet()
if (tempTarget is ValueWrapper.Existing) overviewData.temporaryTarget = tempTarget.value