2021-02-06 00:30:27 +01:00
|
|
|
package info.nightscout.androidaps.db
|
|
|
|
|
|
|
|
import info.nightscout.androidaps.database.AppRepository
|
2021-03-25 17:48:07 +01:00
|
|
|
import info.nightscout.androidaps.database.entities.*
|
2021-04-01 23:46:21 +02:00
|
|
|
import info.nightscout.androidaps.database.entities.ExtendedBolus
|
|
|
|
import info.nightscout.androidaps.database.entities.TemporaryBasal
|
|
|
|
import info.nightscout.androidaps.events.*
|
2021-02-06 00:30:27 +01:00
|
|
|
import info.nightscout.androidaps.logging.AAPSLogger
|
|
|
|
import info.nightscout.androidaps.logging.LTag
|
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|
|
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
|
|
|
import io.reactivex.disposables.Disposable
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Singleton
|
|
|
|
|
|
|
|
@Singleton
|
|
|
|
class CompatDBHelper @Inject constructor(
|
|
|
|
val aapsLogger: AAPSLogger,
|
|
|
|
val repository: AppRepository,
|
|
|
|
val rxBus: RxBusWrapper
|
|
|
|
) {
|
|
|
|
|
|
|
|
fun dbChangeDisposable(): Disposable = repository
|
|
|
|
.changeObservable()
|
|
|
|
.doOnSubscribe {
|
|
|
|
rxBus.send(EventNewBG(null))
|
|
|
|
}
|
|
|
|
.subscribe {
|
|
|
|
it.filterIsInstance<GlucoseValue>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData")
|
|
|
|
rxBus.send(EventNewHistoryData(it.timestamp))
|
|
|
|
}
|
|
|
|
it.filterIsInstance<GlucoseValue>().lastOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg")
|
|
|
|
rxBus.send(EventNewBG(it))
|
|
|
|
}
|
|
|
|
it.filterIsInstance<TemporaryTarget>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventTempTargetChange")
|
|
|
|
rxBus.send(EventTempTargetChange())
|
|
|
|
}
|
2021-03-08 20:10:02 +01:00
|
|
|
it.filterIsInstance<TherapyEvent>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventTherapyEventChange")
|
|
|
|
rxBus.send(EventTherapyEventChange())
|
|
|
|
}
|
2021-03-19 18:49:34 +01:00
|
|
|
it.filterIsInstance<Food>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged")
|
|
|
|
rxBus.send(EventFoodDatabaseChanged())
|
|
|
|
}
|
2021-03-25 17:48:07 +01:00
|
|
|
it.filterIsInstance<Carbs>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged")
|
2021-03-30 19:37:26 +02:00
|
|
|
rxBus.send(EventTreatmentChange())
|
2021-03-25 17:48:07 +01:00
|
|
|
}
|
|
|
|
it.filterIsInstance<Bolus>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged")
|
2021-03-30 19:37:26 +02:00
|
|
|
rxBus.send(EventTreatmentChange())
|
2021-03-25 17:48:07 +01:00
|
|
|
}
|
2021-04-01 23:46:21 +02:00
|
|
|
it.filterIsInstance<TemporaryBasal>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventTempBasalChange")
|
|
|
|
rxBus.send(EventTempBasalChange())
|
|
|
|
}
|
|
|
|
it.filterIsInstance<ExtendedBolus>().firstOrNull()?.let {
|
|
|
|
aapsLogger.debug(LTag.DATABASE, "Firing EventExtendedBolusChange")
|
|
|
|
rxBus.send(EventExtendedBolusChange())
|
|
|
|
}
|
2021-02-06 00:30:27 +01:00
|
|
|
}
|
|
|
|
}
|