Merge pull request #523 from Philoul/FIX_Extended_Remove
Fix FakeExtended TBR removal from TreatmentTemporaryBasalsFragment
This commit is contained in:
commit
328ec9a9ff
3 changed files with 41 additions and 11 deletions
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.receivers.DataWorker
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.JsonHelper
|
import info.nightscout.androidaps.utils.JsonHelper
|
||||||
import info.nightscout.androidaps.utils.JsonHelper.safeGetLong
|
import info.nightscout.androidaps.utils.JsonHelper.safeGetLong
|
||||||
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
@ -287,7 +288,7 @@ class NSClientAddUpdateWorker(
|
||||||
result.inserted.forEach {
|
result.inserted.forEach {
|
||||||
uel.log(Action.TEMP_BASAL, Sources.NSClient,
|
uel.log(Action.TEMP_BASAL, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.UnitPerHour(it.rate),
|
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it")
|
aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it")
|
||||||
|
@ -295,7 +296,7 @@ class NSClientAddUpdateWorker(
|
||||||
result.invalidated.forEach {
|
result.invalidated.forEach {
|
||||||
uel.log(Action.TEMP_BASAL_REMOVED, Sources.NSClient,
|
uel.log(Action.TEMP_BASAL_REMOVED, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.UnitPerHour(it.rate),
|
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it")
|
aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it")
|
||||||
|
@ -303,7 +304,7 @@ class NSClientAddUpdateWorker(
|
||||||
result.ended.forEach {
|
result.ended.forEach {
|
||||||
uel.log(Action.CANCEL_TEMP_BASAL, Sources.NSClient,
|
uel.log(Action.CANCEL_TEMP_BASAL, Sources.NSClient,
|
||||||
ValueWithUnit.Timestamp(it.timestamp),
|
ValueWithUnit.Timestamp(it.timestamp),
|
||||||
ValueWithUnit.UnitPerHour(it.rate),
|
if (it.isAbsolute) ValueWithUnit.UnitPerHour(it.rate) else ValueWithUnit.Percent(it.rate.toInt()),
|
||||||
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt())
|
||||||
)
|
)
|
||||||
aapsLogger.debug(LTag.DATABASE, "Ended TemporaryBasal $it")
|
aapsLogger.debug(LTag.DATABASE, "Ended TemporaryBasal $it")
|
||||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.ExtendedBolus
|
import info.nightscout.androidaps.database.entities.ExtendedBolus
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
|
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||||
import info.nightscout.androidaps.database.interfaces.end
|
import info.nightscout.androidaps.database.interfaces.end
|
||||||
import info.nightscout.androidaps.database.transactions.InvalidateExtendedBolusTransaction
|
import info.nightscout.androidaps.database.transactions.InvalidateExtendedBolusTransaction
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusFragmentBinding
|
import info.nightscout.androidaps.databinding.TreatmentsExtendedbolusFragmentBinding
|
||||||
|
@ -157,7 +158,11 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
||||||
${resourceHelper.gs(R.string.extended_bolus)}
|
${resourceHelper.gs(R.string.extended_bolus)}
|
||||||
${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(extendedBolus.timestamp)}
|
${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(extendedBolus.timestamp)}
|
||||||
""".trimIndent(), { _: DialogInterface, _: Int ->
|
""".trimIndent(), { _: DialogInterface, _: Int ->
|
||||||
uel.log(Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments)
|
uel.log(Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments,
|
||||||
|
ValueWithUnit.Timestamp(extendedBolus.timestamp),
|
||||||
|
ValueWithUnit.Insulin(extendedBolus.amount),
|
||||||
|
ValueWithUnit.UnitPerHour(extendedBolus.rate),
|
||||||
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(extendedBolus.duration).toInt()))
|
||||||
disposable += repository.runTransactionForResult(InvalidateExtendedBolusTransaction(extendedBolus.id))
|
disposable += repository.runTransactionForResult(InvalidateExtendedBolusTransaction(extendedBolus.id))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{ aapsLogger.debug(LTag.DATABASE, "Removed extended bolus $extendedBolus") },
|
{ aapsLogger.debug(LTag.DATABASE, "Removed extended bolus $extendedBolus") },
|
||||||
|
|
|
@ -12,12 +12,15 @@ import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.IobTotal
|
import info.nightscout.androidaps.data.IobTotal
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
|
import info.nightscout.androidaps.database.ValueWrapper
|
||||||
|
import info.nightscout.androidaps.database.entities.ExtendedBolus
|
||||||
import info.nightscout.androidaps.database.entities.TemporaryBasal
|
import info.nightscout.androidaps.database.entities.TemporaryBasal
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.*
|
import info.nightscout.androidaps.database.entities.UserEntry.*
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||||
import info.nightscout.androidaps.database.interfaces.end
|
import info.nightscout.androidaps.database.interfaces.end
|
||||||
|
import info.nightscout.androidaps.database.transactions.InvalidateExtendedBolusTransaction
|
||||||
import info.nightscout.androidaps.database.transactions.InvalidateTemporaryBasalTransaction
|
import info.nightscout.androidaps.database.transactions.InvalidateTemporaryBasalTransaction
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsFragmentBinding
|
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsFragmentBinding
|
||||||
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsItemBinding
|
import info.nightscout.androidaps.databinding.TreatmentsTempbasalsItemBinding
|
||||||
|
@ -42,6 +45,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
@ -194,21 +198,41 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
||||||
init {
|
init {
|
||||||
binding.remove.setOnClickListener { v: View ->
|
binding.remove.setOnClickListener { v: View ->
|
||||||
val tempBasal = v.tag as TemporaryBasal
|
val tempBasal = v.tag as TemporaryBasal
|
||||||
|
var extendedBolus: ExtendedBolus? = null
|
||||||
|
val isFakeExtended = tempBasal.type == TemporaryBasal.Type.FAKE_EXTENDED
|
||||||
|
if (isFakeExtended) {
|
||||||
|
val eb = repository.getExtendedBolusActiveAt(tempBasal.timestamp).blockingGet()
|
||||||
|
extendedBolus = if (eb is ValueWrapper.Existing) eb.value else null
|
||||||
|
}
|
||||||
val profile = profileFunction.getProfile(dateUtil.now())
|
val profile = profileFunction.getProfile(dateUtil.now())
|
||||||
?: return@setOnClickListener
|
?: return@setOnClickListener
|
||||||
context?.let {
|
context?.let {
|
||||||
OKDialog.showConfirmation(it, resourceHelper.gs(R.string.removerecord),
|
OKDialog.showConfirmation(it, resourceHelper.gs(R.string.removerecord),
|
||||||
"""
|
"""
|
||||||
${resourceHelper.gs(R.string.tempbasal_label)}: ${tempBasal.toStringFull(profile, dateUtil)}
|
${if (isFakeExtended) resourceHelper.gs(R.string.extended_bolus) else resourceHelper.gs(R.string.tempbasal_label)}: ${tempBasal.toStringFull(profile, dateUtil)}
|
||||||
${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(tempBasal.timestamp)}
|
${resourceHelper.gs(R.string.date)}: ${dateUtil.dateAndTimeString(tempBasal.timestamp)}
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
{ _: DialogInterface?, _: Int ->
|
{ _: DialogInterface?, _: Int ->
|
||||||
|
if (isFakeExtended && extendedBolus != null) {
|
||||||
|
uel.log(Action.EXTENDED_BOLUS_REMOVED, Sources.Treatments,
|
||||||
|
ValueWithUnit.Timestamp(extendedBolus.timestamp),
|
||||||
|
ValueWithUnit.Insulin(extendedBolus.amount),
|
||||||
|
ValueWithUnit.UnitPerHour(extendedBolus.rate),
|
||||||
|
ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(extendedBolus.duration).toInt()))
|
||||||
|
disposable += repository.runTransactionForResult(InvalidateExtendedBolusTransaction(extendedBolus.id))
|
||||||
|
.subscribe(
|
||||||
|
{ aapsLogger.debug(LTag.DATABASE, "Removed extended bolus $extendedBolus") },
|
||||||
|
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating extended bolus", it) })
|
||||||
|
} else if (!isFakeExtended) {
|
||||||
uel.log(Action.TEMP_BASAL_REMOVED, Sources.Treatments,
|
uel.log(Action.TEMP_BASAL_REMOVED, Sources.Treatments,
|
||||||
ValueWithUnit.Timestamp(tempBasal.timestamp))
|
ValueWithUnit.Timestamp(tempBasal.timestamp),
|
||||||
|
if (tempBasal.isAbsolute) ValueWithUnit.UnitPerHour(tempBasal.rate) else ValueWithUnit.Percent(tempBasal.rate.toInt()),
|
||||||
|
ValueWithUnit.Minute(T.msecs(tempBasal.duration).mins().toInt()))
|
||||||
disposable += repository.runTransactionForResult(InvalidateTemporaryBasalTransaction(tempBasal.id))
|
disposable += repository.runTransactionForResult(InvalidateTemporaryBasalTransaction(tempBasal.id))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{ aapsLogger.debug(LTag.DATABASE, "Removed temporary basal $tempBasal") },
|
{ aapsLogger.debug(LTag.DATABASE, "Removed temporary basal $tempBasal") },
|
||||||
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary basal", it) })
|
{ aapsLogger.error(LTag.DATABASE, "Error while invalidating temporary basal", it) })
|
||||||
|
}
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue