From 828d6b41ded11cee9690394a8c02f41e90516e30 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 24 Nov 2022 09:07:44 +0100 Subject: [PATCH] remove :database:impl dependency --- .../configBuilder/ProfileFunctionImpl.kt | 2 +- .../PrepareIobAutosensGraphDataWorker.kt | 2 +- .../PrepareTemporaryTargetDataWorker.kt | 2 +- core/core-main/build.gradle | 1 - .../core/pump/DetailedBolusInfoExtension.kt | 12 ---- .../nightscout/core/wizard/BolusWizard.kt | 17 ++--- .../core/wizard/QuickWizardEntry.kt | 8 +-- .../info/nightscout/database/ValueWrapper.kt | 6 ++ .../nightscout/database/impl/AppRepository.kt | 5 +- .../implementation/LocalAlertUtilsImpl.kt | 4 +- .../implementation/db/PersistenceLayerImpl.kt | 67 +++++++++++++++++++ .../implementation/di/ImplementationModule.kt | 3 + .../overview/OverviewDataImpl.kt | 2 +- .../pump/PumpSyncImplementation.kt | 4 +- .../queue/CommandQueueImplementation.kt | 23 ++----- .../queue/commands/CommandSetProfile.kt | 2 +- .../implementation/stats/TddCalculatorImpl.kt | 2 +- .../queue/CommandQueueImplementationTest.kt | 2 +- .../interfaces/db/PersistenceLayer.kt | 19 ++++++ .../interfaces/pump/DetailedBolusInfo.kt | 8 +-- .../aps/openAPSAMA/OpenAPSAMAPlugin.kt | 2 +- .../aps/openAPSSMB/OpenAPSSMBPlugin.kt | 2 +- .../automation/triggers/TriggerBolusAgo.kt | 2 +- .../automation/triggers/TriggerTempTarget.kt | 5 +- .../triggers/TriggerTempTargetValue.kt | 2 +- .../triggers/TriggerBolusAgoTest.kt | 2 +- .../triggers/TriggerTempTargetValueTest.kt | 2 +- .../nightscout/plugins/aps/loop/LoopPlugin.kt | 4 +- .../objectives/objectives/Objective0.kt | 2 +- .../general/actions/ActionsFragment.kt | 4 +- .../wear/wearintegration/DataHandlerMobile.kt | 2 +- .../IobCobCalculatorPlugin.kt | 2 +- .../iob/iobCobCalculator/IobCobOref1Worker.kt | 2 +- .../DataSyncSelectorImplementation.kt | 2 +- .../plugins/ui/StatusLightHandler.kt | 2 +- .../fragments/TreatmentsTempTargetFragment.kt | 4 +- .../TreatmentsTemporaryBasalsFragment.kt | 4 +- .../nightscout/ui/dialogs/InsulinDialog.kt | 9 +-- .../ui/dialogs/ProfileViewerDialog.kt | 2 +- .../nightscout/ui/dialogs/TempTargetDialog.kt | 4 +- .../nightscout/ui/dialogs/TreatmentDialog.kt | 28 ++------ .../nightscout/ui/dialogs/WizardDialog.kt | 2 +- 42 files changed, 161 insertions(+), 120 deletions(-) create mode 100644 database/entities/src/main/java/info/nightscout/database/ValueWrapper.kt create mode 100644 implementation/src/main/java/info/nightscout/implementation/db/PersistenceLayerImpl.kt create mode 100644 interfaces/src/main/java/info/nightscout/interfaces/db/PersistenceLayer.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt index d28015691f..3a90f95b2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt @@ -4,9 +4,9 @@ import info.nightscout.androidaps.extensions.fromConstant import info.nightscout.core.main.R import info.nightscout.core.profile.ProfileSealed import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.ProfileSwitch import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.InsertOrUpdateProfileSwitch import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt index 0f3feeaf15..4b73b784e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareIobAutosensGraphDataWorker.kt @@ -23,8 +23,8 @@ import info.nightscout.core.iob.combine import info.nightscout.core.iob.copy import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.workflow.CalculationWorkflow +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.AutosensResult import info.nightscout.interfaces.aps.SMBDefaults import info.nightscout.interfaces.iob.IobCobCalculator diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt index e4c1cc275b..073b68b410 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/PrepareTemporaryTargetDataWorker.kt @@ -12,8 +12,8 @@ import info.nightscout.androidaps.extensions.target import info.nightscout.core.graph.OverviewData import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.workflow.CalculationWorkflow +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction diff --git a/core/core-main/build.gradle b/core/core-main/build.gradle index 3eec4adfe2..286ad7d99c 100644 --- a/core/core-main/build.gradle +++ b/core/core-main/build.gradle @@ -17,7 +17,6 @@ dependencies { implementation project(':app-wear-shared:rx') implementation project(':app-wear-shared:shared') implementation project(':database:entities') - implementation project(':database:impl') implementation project(':interfaces') implementation project(':core:graph') implementation project(':core:ui') diff --git a/core/core-main/src/main/java/info/nightscout/core/pump/DetailedBolusInfoExtension.kt b/core/core-main/src/main/java/info/nightscout/core/pump/DetailedBolusInfoExtension.kt index daa6265a7f..d6ae01b023 100644 --- a/core/core-main/src/main/java/info/nightscout/core/pump/DetailedBolusInfoExtension.kt +++ b/core/core-main/src/main/java/info/nightscout/core/pump/DetailedBolusInfoExtension.kt @@ -1,20 +1,8 @@ package info.nightscout.core.pump import com.google.gson.Gson -import info.nightscout.database.impl.transactions.InsertOrUpdateBolusTransaction -import info.nightscout.database.impl.transactions.InsertOrUpdateCarbsTransaction import info.nightscout.interfaces.pump.DetailedBolusInfo -fun DetailedBolusInfo.insertCarbsTransaction(): InsertOrUpdateCarbsTransaction { - if (carbs == 0.0) throw IllegalStateException("carbs == 0.0") - return InsertOrUpdateCarbsTransaction(createCarbs()!!) -} - -fun DetailedBolusInfo.insertBolusTransaction(): InsertOrUpdateBolusTransaction { - if (insulin == 0.0) throw IllegalStateException("insulin == 0.0") - return InsertOrUpdateBolusTransaction(createBolus()!!) -} - fun DetailedBolusInfo.toJsonString(): String = Gson().toJson(this) // Cannot access Companion extension from java so create common diff --git a/core/core-main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt b/core/core-main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt index b6fa428626..015a2b65a7 100644 --- a/core/core-main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt +++ b/core/core-main/src/main/java/info/nightscout/core/wizard/BolusWizard.kt @@ -6,7 +6,6 @@ import com.google.common.base.Joiner import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.highValueToUnitsToString import info.nightscout.androidaps.extensions.lowValueToUnitsToString -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.core.iob.round import info.nightscout.core.main.R @@ -18,16 +17,16 @@ import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit -import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.transactions.InsertOrUpdateBolusCalculatorResultTransaction import info.nightscout.interfaces.BolusTimer import info.nightscout.interfaces.CarbTimer import info.nightscout.interfaces.Config import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints +import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.iob.GlucoseStatus import info.nightscout.interfaces.iob.IobCobCalculator +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.Profile @@ -48,8 +47,6 @@ import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.T -import io.reactivex.rxjava3.disposables.CompositeDisposable -import io.reactivex.rxjava3.kotlin.plusAssign import java.util.LinkedList import javax.inject.Inject import kotlin.math.abs @@ -76,10 +73,9 @@ class BolusWizard @Inject constructor( @Inject lateinit var carbTimer: CarbTimer @Inject lateinit var bolusTimer: BolusTimer @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider - @Inject lateinit var repository: AppRepository @Inject lateinit var activityNames: ActivityNames + @Inject lateinit var persistenceLayer: PersistenceLayer - private val disposable = CompositeDisposable() var timeStamp : Long @@ -495,12 +491,7 @@ class BolusWizard @Inject constructor( } }) } - disposable += repository.runTransactionForResult(InsertOrUpdateBolusCalculatorResultTransaction(bolusCalculatorResult!!)) - .subscribe( - { result -> result.inserted.forEach { inserted -> aapsLogger.debug(LTag.DATABASE, "Inserted bolusCalculatorResult $inserted") } }, - { aapsLogger.error(LTag.DATABASE, "Error while saving bolusCalculatorResult", it) } - ) - + bolusCalculatorResult?.let { persistenceLayer.insertOrUpdate(it) } } if (useAlarm && carbs > 0 && carbTime > 0) { carbTimer.scheduleTimeToEatReminder(T.mins(carbTime.toLong()).secs().toInt()) diff --git a/core/core-main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt b/core/core-main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt index 25f4d1c8fc..bf1660067e 100644 --- a/core/core-main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt +++ b/core/core-main/src/main/java/info/nightscout/core/wizard/QuickWizardEntry.kt @@ -7,10 +7,10 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProv import info.nightscout.core.iob.round import info.nightscout.core.main.R import info.nightscout.core.utils.MidnightUtils +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.GlucoseValue -import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.Loop +import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.Profile @@ -32,7 +32,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var loop: Loop @Inject lateinit var iobCobCalculator: IobCobCalculator - @Inject lateinit var repository: AppRepository + @Inject lateinit var persistenceLayer: PersistenceLayer @Inject lateinit var dateUtil: DateUtil @Inject lateinit var glucoseStatusProvider: GlucoseStatusProvider @@ -109,7 +109,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec fun isActive(): Boolean = time.secondsFromMidnight() >= validFrom() && time.secondsFromMidnight() <= validTo() && forDevice(DEVICE_PHONE) fun doCalc(profile: Profile, profileName: String, lastBG: GlucoseValue, _synchronized: Boolean): BolusWizard { - val dbRecord = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() + val dbRecord = persistenceLayer.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() val tempTarget = if (dbRecord is ValueWrapper.Existing) dbRecord.value else null //BG var bg = 0.0 diff --git a/database/entities/src/main/java/info/nightscout/database/ValueWrapper.kt b/database/entities/src/main/java/info/nightscout/database/ValueWrapper.kt new file mode 100644 index 0000000000..3807d6cf2c --- /dev/null +++ b/database/entities/src/main/java/info/nightscout/database/ValueWrapper.kt @@ -0,0 +1,6 @@ +package info.nightscout.database + +sealed class ValueWrapper { + data class Existing(val value: T) : ValueWrapper() + class Absent : ValueWrapper() +} \ No newline at end of file diff --git a/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt b/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt index 50f724171e..3ac673c6af 100644 --- a/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt +++ b/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt @@ -1,5 +1,6 @@ package info.nightscout.database.impl +import info.nightscout.database.ValueWrapper import info.nightscout.database.annotations.DbOpenForTesting import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.BolusCalculatorResult @@ -949,7 +950,3 @@ inline fun Maybe.toWrappedSingle(): Single> .switchIfEmpty(Maybe.just(ValueWrapper.Absent())) .toSingle() -sealed class ValueWrapper { - data class Existing(val value: T) : ValueWrapper() - class Absent : ValueWrapper() -} \ No newline at end of file diff --git a/implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt b/implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt index 9ab577fdee..5cb4d8fbfd 100644 --- a/implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt @@ -1,17 +1,17 @@ package info.nightscout.implementation -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.events.EventNewNotification +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants import info.nightscout.interfaces.LocalAlertUtils +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction diff --git a/implementation/src/main/java/info/nightscout/implementation/db/PersistenceLayerImpl.kt b/implementation/src/main/java/info/nightscout/implementation/db/PersistenceLayerImpl.kt new file mode 100644 index 0000000000..b0523e3245 --- /dev/null +++ b/implementation/src/main/java/info/nightscout/implementation/db/PersistenceLayerImpl.kt @@ -0,0 +1,67 @@ +package info.nightscout.implementation.db + +import dagger.Reusable +import dagger.android.HasAndroidInjector +import info.nightscout.database.ValueWrapper +import info.nightscout.database.entities.Bolus +import info.nightscout.database.entities.BolusCalculatorResult +import info.nightscout.database.entities.Carbs +import info.nightscout.database.entities.TemporaryTarget +import info.nightscout.database.impl.AppRepository +import info.nightscout.database.impl.transactions.InsertOrUpdateBolusCalculatorResultTransaction +import info.nightscout.database.impl.transactions.InsertOrUpdateBolusTransaction +import info.nightscout.database.impl.transactions.InsertOrUpdateCarbsTransaction +import info.nightscout.interfaces.db.PersistenceLayer +import info.nightscout.interfaces.pump.PumpEnactResult +import info.nightscout.interfaces.queue.Callback +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.rx.logging.LTag +import io.reactivex.rxjava3.core.Single +import io.reactivex.rxjava3.disposables.CompositeDisposable +import io.reactivex.rxjava3.kotlin.plusAssign +import javax.inject.Inject + +@Reusable +class PersistenceLayerImpl @Inject constructor( + private val aapsLogger: AAPSLogger, + private val repository: AppRepository +) : PersistenceLayer { + + private val disposable = CompositeDisposable() + + override fun insertOrUpdate(bolusCalculatorResult: BolusCalculatorResult) { + disposable += repository.runTransactionForResult(InsertOrUpdateBolusCalculatorResultTransaction(bolusCalculatorResult)) + .subscribe( + { result -> result.inserted.forEach { inserted -> aapsLogger.debug(LTag.DATABASE, "Inserted bolusCalculatorResult $inserted") } }, + { aapsLogger.error(LTag.DATABASE, "Error while saving bolusCalculatorResult", it) } + ) + } + + override fun insertOrUpdateBolus(bolus: Bolus) { + disposable += repository.runTransactionForResult(InsertOrUpdateBolusTransaction(bolus)) + .subscribe( + { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } }, + { aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) } + ) + } + + override fun insertOrUpdateCarbs(carbs: Carbs, callback: Callback?, injector: HasAndroidInjector?) { + disposable += repository.runTransactionForResult(InsertOrUpdateCarbsTransaction(carbs)) + .subscribe( + { result -> + result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") } + injector?.let { injector -> + callback?.result(PumpEnactResult(injector).enacted(false).success(true))?.run() + } + + }, { + aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) + injector?.let { injector -> + callback?.result(PumpEnactResult(injector).enacted(false).success(false))?.run() + } + } + ) + } + + override fun getTemporaryTargetActiveAt(timestamp: Long): Single> = repository.getTemporaryTargetActiveAt(timestamp) +} diff --git a/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt b/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt index 99768edd2c..00e7354886 100644 --- a/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt +++ b/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt @@ -14,6 +14,7 @@ import info.nightscout.implementation.TrendCalculatorImpl import info.nightscout.implementation.UserEntryLoggerImpl import info.nightscout.implementation.XDripBroadcastImpl import info.nightscout.implementation.androidNotification.NotificationHolderImpl +import info.nightscout.implementation.db.PersistenceLayerImpl import info.nightscout.implementation.logging.LoggerUtilsImpl import info.nightscout.implementation.maintenance.PrefFileListProviderImpl import info.nightscout.implementation.overview.OverviewDataImpl @@ -38,6 +39,7 @@ import info.nightscout.interfaces.LocalAlertUtils import info.nightscout.interfaces.NotificationHolder import info.nightscout.interfaces.Translator import info.nightscout.interfaces.XDripBroadcast +import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.logging.LoggerUtils import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.maintenance.PrefFileListProvider @@ -70,6 +72,7 @@ open class ImplementationModule { @Module interface Bindings { + @Binds fun bindPersistenceLayer(persistenceLayerImpl: PersistenceLayerImpl): PersistenceLayer @Binds fun bindActivePlugin(pluginStore: PluginStore): ActivePlugin @Binds fun bindPrefFileListProvider(prefFileListProviderImpl: PrefFileListProviderImpl): PrefFileListProvider @Binds fun bindOverviewData(overviewData: OverviewDataImpl): OverviewData diff --git a/implementation/src/main/java/info/nightscout/implementation/overview/OverviewDataImpl.kt b/implementation/src/main/java/info/nightscout/implementation/overview/OverviewDataImpl.kt index 7b97d2bb2e..f74af7fc9f 100644 --- a/implementation/src/main/java/info/nightscout/implementation/overview/OverviewDataImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/overview/OverviewDataImpl.kt @@ -21,10 +21,10 @@ import info.nightscout.core.graph.data.Scale import info.nightscout.core.graph.data.ScaledDataPoint import info.nightscout.core.iob.round import info.nightscout.core.main.R +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.AutosensData import info.nightscout.interfaces.iob.CobInfo import info.nightscout.interfaces.iob.IobCobCalculator diff --git a/implementation/src/main/java/info/nightscout/implementation/pump/PumpSyncImplementation.kt b/implementation/src/main/java/info/nightscout/implementation/pump/PumpSyncImplementation.kt index 3c25cd2c24..4b1af19865 100644 --- a/implementation/src/main/java/info/nightscout/implementation/pump/PumpSyncImplementation.kt +++ b/implementation/src/main/java/info/nightscout/implementation/pump/PumpSyncImplementation.kt @@ -1,11 +1,11 @@ package info.nightscout.implementation.pump -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.events.EventNewNotification import info.nightscout.core.main.R import info.nightscout.core.pump.fromDbPumpType import info.nightscout.core.pump.toDbPumpType import info.nightscout.core.pump.toDbSource +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.Carbs import info.nightscout.database.entities.ExtendedBolus @@ -16,7 +16,6 @@ import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.InsertBolusWithTempIdTransaction import info.nightscout.database.impl.transactions.InsertIfNewByTimestampCarbsTransaction import info.nightscout.database.impl.transactions.InsertIfNewByTimestampTherapyEventTransaction @@ -33,6 +32,7 @@ import info.nightscout.database.impl.transactions.SyncPumpExtendedBolusTransacti import info.nightscout.database.impl.transactions.SyncPumpTemporaryBasalTransaction import info.nightscout.database.impl.transactions.SyncPumpTotalDailyDoseTransaction import info.nightscout.database.impl.transactions.SyncTemporaryBasalWithTempIdTransaction +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction diff --git a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt index 6d5da88f4a..7962ee7e9e 100644 --- a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt @@ -12,13 +12,12 @@ import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.extensions.getCustomizedName import info.nightscout.core.events.EventNewNotification import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.pump.insertCarbsTransaction import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.EffectiveProfileSwitch import info.nightscout.database.entities.ProfileSwitch import info.nightscout.database.entities.interfaces.end import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.implementation.R import info.nightscout.implementation.queue.commands.CommandBolus import info.nightscout.implementation.queue.commands.CommandCancelExtendedBolus @@ -41,6 +40,7 @@ import info.nightscout.interfaces.AndroidPermission import info.nightscout.interfaces.Config import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints +import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.Profile @@ -68,7 +68,6 @@ import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign -import io.reactivex.rxjava3.kotlin.subscribeBy import java.util.LinkedList import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -92,7 +91,8 @@ class CommandQueueImplementation @Inject constructor( private val repository: AppRepository, private val fabricPrivacy: FabricPrivacy, private val androidPermission: AndroidPermission, - private val activityNames: ActivityNames + private val activityNames: ActivityNames, + private val persistenceLayer: PersistenceLayer ) : CommandQueue { private val disposable = CompositeDisposable() @@ -230,7 +230,7 @@ class CommandQueueImplementation @Inject constructor( val tempCommandQueue = CommandQueueImplementation( injector, aapsLogger, rxBus, aapsSchedulers, rh, constraintChecker, profileFunction, activePlugin, context, sp, - config, dateUtil, repository, fabricPrivacy, androidPermission, activityNames + config, dateUtil, repository, fabricPrivacy, androidPermission, activityNames, persistenceLayer ) tempCommandQueue.readStatus(reason, callback) tempCommandQueue.disposable.clear() @@ -266,18 +266,7 @@ class CommandQueueImplementation @Inject constructor( carbsRunnable = Runnable { aapsLogger.debug(LTag.PUMPQUEUE, "Going to store carbs") detailedBolusInfo.carbs = originalCarbs - disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction()) - .subscribeBy( - onSuccess = { result -> - result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") } - callback?.result(PumpEnactResult(injector).enacted(false).success(true))?.run() - - }, - onError = { - aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) - callback?.result(PumpEnactResult(injector).enacted(false).success(false))?.run() - } - ) + persistenceLayer.insertOrUpdateCarbs(detailedBolusInfo.createCarbs(), callback, injector) } // Do not process carbs anymore detailedBolusInfo.carbs = 0.0 diff --git a/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt index 20a5a414dc..98eb3c1b9c 100644 --- a/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt @@ -1,8 +1,8 @@ package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.implementation.R import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/implementation/src/main/java/info/nightscout/implementation/stats/TddCalculatorImpl.kt b/implementation/src/main/java/info/nightscout/implementation/stats/TddCalculatorImpl.kt index dc608d3af2..3908b9b07b 100644 --- a/implementation/src/main/java/info/nightscout/implementation/stats/TddCalculatorImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/stats/TddCalculatorImpl.kt @@ -8,11 +8,11 @@ import android.view.ViewGroup import android.widget.TableLayout import android.widget.TableRow import android.widget.TextView +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.TotalDailyDose import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.implementation.R import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt index 104a131d68..b7c68016a8 100644 --- a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt @@ -8,9 +8,9 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.implementation.R import info.nightscout.implementation.queue.commands.CommandBolus import info.nightscout.implementation.queue.commands.CommandCustomCommand diff --git a/interfaces/src/main/java/info/nightscout/interfaces/db/PersistenceLayer.kt b/interfaces/src/main/java/info/nightscout/interfaces/db/PersistenceLayer.kt new file mode 100644 index 0000000000..216384ce5a --- /dev/null +++ b/interfaces/src/main/java/info/nightscout/interfaces/db/PersistenceLayer.kt @@ -0,0 +1,19 @@ +package info.nightscout.interfaces.db + +import dagger.android.HasAndroidInjector +import info.nightscout.database.ValueWrapper +import info.nightscout.database.entities.Bolus +import info.nightscout.database.entities.BolusCalculatorResult +import info.nightscout.database.entities.Carbs +import info.nightscout.database.entities.TemporaryTarget +import info.nightscout.interfaces.queue.Callback +import io.reactivex.rxjava3.core.Single + +interface PersistenceLayer { + + fun insertOrUpdate(bolusCalculatorResult: BolusCalculatorResult) + fun insertOrUpdateCarbs(carbs: Carbs, callback: Callback? = null, injector: HasAndroidInjector? = null) + fun insertOrUpdateBolus(bolus: Bolus) + + fun getTemporaryTargetActiveAt(timestamp: Long): Single> +} \ No newline at end of file diff --git a/interfaces/src/main/java/info/nightscout/interfaces/pump/DetailedBolusInfo.kt b/interfaces/src/main/java/info/nightscout/interfaces/pump/DetailedBolusInfo.kt index 2b00ecaa18..a79a7a2fda 100644 --- a/interfaces/src/main/java/info/nightscout/interfaces/pump/DetailedBolusInfo.kt +++ b/interfaces/src/main/java/info/nightscout/interfaces/pump/DetailedBolusInfo.kt @@ -97,7 +97,7 @@ class DetailedBolusInfo { glucoseType = glucoseType?.toDbMeterType() ) - fun createBolus(): Bolus? = + fun createBolus(): Bolus = if (insulin != 0.0) Bolus( timestamp = bolusTimestamp ?: timestamp, @@ -105,9 +105,9 @@ class DetailedBolusInfo { type = bolusType.toDBbBolusType(), notes = notes, ) - else null + else throw IllegalStateException("insulin == 0.0") - fun createCarbs(): Carbs? = + fun createCarbs(): Carbs = if (carbs != 0.0) Carbs( timestamp = carbsTimestamp ?: timestamp, @@ -115,7 +115,7 @@ class DetailedBolusInfo { duration = carbsDuration, notes = notes, ) - else null + else throw IllegalStateException("carbs == 0.0") fun copy(): DetailedBolusInfo { val n = DetailedBolusInfo() diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt index 8158fcf37b..06be926563 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt @@ -7,8 +7,8 @@ import info.nightscout.androidaps.extensions.target import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.core.utils.MidnightUtils import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.APS import info.nightscout.interfaces.aps.AutosensResult import info.nightscout.interfaces.aps.DetermineBasalAdapter diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt index 85aa475426..d669a6c74a 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt @@ -8,8 +8,8 @@ import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.extensions.target import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.core.utils.MidnightUtils +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.APS import info.nightscout.interfaces.aps.AutosensResult import info.nightscout.interfaces.aps.DetermineBasalAdapter diff --git a/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerBolusAgo.kt b/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerBolusAgo.kt index a9c2f57870..3e45998f27 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerBolusAgo.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerBolusAgo.kt @@ -3,13 +3,13 @@ package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.database.impl.ValueWrapper import info.nightscout.automation.R import info.nightscout.automation.elements.Comparator import info.nightscout.automation.elements.InputDuration import info.nightscout.automation.elements.LabelWithElement import info.nightscout.automation.elements.LayoutBuilder import info.nightscout.automation.elements.StaticLabel +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.interfaces.utils.JsonHelper.safeGetString diff --git a/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTarget.kt b/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTarget.kt index ef4d1fbb3b..41134d428c 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTarget.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTarget.kt @@ -3,14 +3,13 @@ package info.nightscout.automation.triggers import android.widget.LinearLayout import com.google.common.base.Optional import dagger.android.HasAndroidInjector -import info.nightscout.database.impl.ValueWrapper -import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.automation.R import info.nightscout.automation.elements.ComparatorExists import info.nightscout.automation.elements.LayoutBuilder import info.nightscout.automation.elements.StaticLabel +import info.nightscout.database.ValueWrapper +import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.rx.logging.LTag - import org.json.JSONObject class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) { diff --git a/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTargetValue.kt b/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTargetValue.kt index e341d07fb1..722e5d17af 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTargetValue.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/triggers/TriggerTempTargetValue.kt @@ -9,7 +9,7 @@ import info.nightscout.automation.elements.InputBg import info.nightscout.automation.elements.LabelWithElement import info.nightscout.automation.elements.LayoutBuilder import info.nightscout.automation.elements.StaticLabel -import info.nightscout.database.impl.ValueWrapper +import info.nightscout.database.ValueWrapper import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.profile.Profile diff --git a/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerBolusAgoTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerBolusAgoTest.kt index 78e69b7322..4676677a3f 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerBolusAgoTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerBolusAgoTest.kt @@ -1,8 +1,8 @@ package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.database.impl.ValueWrapper import info.nightscout.automation.elements.Comparator +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import io.reactivex.rxjava3.core.Single import org.json.JSONException diff --git a/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetValueTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetValueTest.kt index 393e231a47..575f196eaf 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetValueTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTempTargetValueTest.kt @@ -1,9 +1,9 @@ package info.nightscout.automation.triggers import com.google.common.base.Optional -import info.nightscout.database.impl.ValueWrapper import info.nightscout.automation.R import info.nightscout.automation.elements.Comparator +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.TemporaryTarget import info.nightscout.interfaces.GlucoseUnit import io.reactivex.rxjava3.core.Single diff --git a/plugins/main/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt index 86c9b77692..5daf1cd392 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/aps/loop/LoopPlugin.kt @@ -16,16 +16,15 @@ import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.extensions.convertedToAbsolute import info.nightscout.androidaps.extensions.convertedToPercent import info.nightscout.androidaps.extensions.plannedRemainingMinutes -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.events.EventNewNotification import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.ReceiverStatusStore +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.OfflineEvent import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.InsertAndCancelCurrentOfflineEventTransaction import info.nightscout.database.impl.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.interfaces.Config @@ -36,6 +35,7 @@ import info.nightscout.interfaces.aps.Loop.LastRun import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.iob.IobCobCalculator +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective0.kt b/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective0.kt index 6d083155f3..a368c1f107 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective0.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/constraints/objectives/objectives/Objective0.kt @@ -1,8 +1,8 @@ package info.nightscout.plugins.constraints.objectives.objectives import dagger.android.HasAndroidInjector +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt index a10ba59a73..8da106bd0a 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/actions/ActionsFragment.kt @@ -12,18 +12,18 @@ import androidx.core.content.ContextCompat import dagger.android.support.DaggerFragment import info.nightscout.androidaps.extensions.toStringMedium import info.nightscout.androidaps.extensions.toStringShort -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.ui.UIRunnable import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.elements.SingleClickButton import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Config import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.iob.IobCobCalculator +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.protection.ProtectionCheck diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt index 34a51b1066..fe8421b89c 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt @@ -18,6 +18,7 @@ import info.nightscout.core.utils.receivers.ReceiverStatusStore import info.nightscout.core.wizard.BolusWizard import info.nightscout.core.wizard.QuickWizard import info.nightscout.core.wizard.QuickWizardEntry +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.TemporaryBasal @@ -27,7 +28,6 @@ import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.interfaces.end import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction import info.nightscout.interfaces.Config diff --git a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt index a54cbc0f68..4287537360 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt @@ -15,12 +15,12 @@ import info.nightscout.core.iob.plus import info.nightscout.core.iob.round import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.workflow.CalculationWorkflow +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.ExtendedBolus import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.interfaces.end import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Constants import info.nightscout.interfaces.aps.AutosensData import info.nightscout.interfaces.aps.AutosensDataStore diff --git a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt index b76a1e5211..1fd1a04986 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/iob/iobCobCalculator/IobCobOref1Worker.kt @@ -12,8 +12,8 @@ import info.nightscout.core.events.EventNewNotification import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.workflow.CalculationWorkflow +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants import info.nightscout.interfaces.aps.AutosensData diff --git a/plugins/main/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt b/plugins/main/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt index 2438f6d854..d48dca3dcf 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt @@ -1,6 +1,7 @@ package info.nightscout.plugins.sync.nsclient import info.nightscout.androidaps.extensions.toJson +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.BolusCalculatorResult import info.nightscout.database.entities.Carbs @@ -15,7 +16,6 @@ import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.sync.DataSyncSelector diff --git a/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt b/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt index 95aa14d5ba..c37cd0d20a 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/ui/StatusLightHandler.kt @@ -2,9 +2,9 @@ package info.nightscout.plugins.ui import android.widget.TextView import androidx.annotation.StringRes +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.pump.WarnColors diff --git a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTempTargetFragment.kt b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTempTargetFragment.kt index 2f3f259974..0fa21322f2 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTempTargetFragment.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTempTargetFragment.kt @@ -18,21 +18,21 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.extensions.friendlyDescription import info.nightscout.androidaps.extensions.highValueToUnitsToString import info.nightscout.androidaps.extensions.lowValueToUnitsToString -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.ActionModeHelper import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.interfaces.end import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.InvalidateTemporaryTargetTransaction import info.nightscout.interfaces.Config import info.nightscout.interfaces.Translator +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus diff --git a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTemporaryBasalsFragment.kt b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTemporaryBasalsFragment.kt index d6532d0239..b0aa63f105 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTemporaryBasalsFragment.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsTemporaryBasalsFragment.kt @@ -18,11 +18,11 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.extensions.iobCalc import info.nightscout.androidaps.extensions.toStringFull import info.nightscout.androidaps.extensions.toTemporaryBasal -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.ActionModeHelper import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.ExtendedBolus import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.UserEntry.Action @@ -30,10 +30,10 @@ import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.entities.interfaces.end import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.InvalidateExtendedBolusTransaction import info.nightscout.database.impl.transactions.InvalidateTemporaryBasalTransaction import info.nightscout.interfaces.iob.IobTotal +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.rx.AapsSchedulers diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt index 9e08a52c88..bfee100162 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/InsulinDialog.kt @@ -8,7 +8,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.google.common.base.Joiner -import info.nightscout.core.pump.insertBolusTransaction import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.extensions.formatColor @@ -25,6 +24,7 @@ import info.nightscout.interfaces.Constants.INSULIN_PLUS3_DEFAULT import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints +import info.nightscout.interfaces.db.PersistenceLayer import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.DefaultValueHelper @@ -69,6 +69,7 @@ class InsulinDialog : DialogFragmentWithDate() { @Inject lateinit var uel: UserEntryLogger @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var activityNames: ActivityNames + @Inject lateinit var persistenceLayer: PersistenceLayer private var queryingProtection = false private val disposable = CompositeDisposable() @@ -253,11 +254,7 @@ class InsulinDialog : DialogFragmentWithDate() { ValueWithUnit.SimpleString(rh.gsNotLocalised(R.string.record)), ValueWithUnit.Insulin(insulinAfterConstraints), ValueWithUnit.Minute(timeOffset).takeIf { timeOffset != 0 }) - disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction()) - .subscribe( - { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } }, - { aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) } - ) + persistenceLayer.insertOrUpdateBolus(detailedBolusInfo.createBolus()) if (timeOffset == 0) bolusTimer.removeAutomationEventBolusReminder() } else { diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/ProfileViewerDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/ProfileViewerDialog.kt index 185102e925..f61f5be40e 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/ProfileViewerDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/ProfileViewerDialog.kt @@ -13,8 +13,8 @@ import info.nightscout.androidaps.extensions.getCustomizedName import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.main.R import info.nightscout.core.profile.ProfileSealed +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/TempTargetDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/TempTargetDialog.kt index 45976d6af0..ac412d699f 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/TempTargetDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/TempTargetDialog.kt @@ -8,19 +8,19 @@ import android.view.ViewGroup import android.widget.ArrayAdapter import com.google.common.base.Joiner import com.google.common.collect.Lists -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.toast.ToastUtils +import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.database.impl.transactions.CancelCurrentTemporaryTargetIfAnyTransaction import info.nightscout.database.impl.transactions.InsertAndCancelCurrentTemporaryTargetTransaction import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.constraints.Constraints +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.profile.DefaultValueHelper import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt index a42480bc2c..e23990ec7e 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/TreatmentDialog.kt @@ -8,9 +8,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.google.common.base.Joiner -import info.nightscout.interfaces.logging.UserEntryLogger -import info.nightscout.core.pump.insertBolusTransaction -import info.nightscout.core.pump.insertCarbsTransaction import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.extensions.formatColor @@ -20,6 +17,8 @@ import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints +import info.nightscout.interfaces.db.PersistenceLayer +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.protection.ProtectionCheck import info.nightscout.interfaces.pump.DetailedBolusInfo @@ -34,7 +33,6 @@ import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.ui.R import info.nightscout.ui.databinding.DialogTreatmentBinding import io.reactivex.rxjava3.disposables.CompositeDisposable -import io.reactivex.rxjava3.kotlin.plusAssign import java.text.DecimalFormat import java.util.LinkedList import javax.inject.Inject @@ -52,6 +50,7 @@ class TreatmentDialog : DialogFragmentWithDate() { @Inject lateinit var repository: AppRepository @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var activityNames: ActivityNames + @Inject lateinit var persistenceLayer: PersistenceLayer private var queryingProtection = false private val disposable = CompositeDisposable() @@ -167,17 +166,9 @@ class TreatmentDialog : DialogFragmentWithDate() { ValueWithUnit.Insulin(insulinAfterConstraints).takeIf { insulinAfterConstraints != 0.0 }, ValueWithUnit.Gram(carbsAfterConstraints).takeIf { carbsAfterConstraints != 0 }) if (detailedBolusInfo.insulin > 0) - disposable += repository.runTransactionForResult(detailedBolusInfo.insertBolusTransaction()) - .subscribe( - { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") } }, - { aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) } - ) + persistenceLayer.insertOrUpdateBolus(detailedBolusInfo.createBolus()) if (detailedBolusInfo.carbs > 0) - disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction()) - .subscribe( - { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") } }, - { aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) } - ) + persistenceLayer.insertOrUpdateCarbs(detailedBolusInfo.createCarbs()) } else { if (detailedBolusInfo.insulin > 0) { uel.log(action, UserEntry.Sources.TreatmentDialog, @@ -193,13 +184,8 @@ class TreatmentDialog : DialogFragmentWithDate() { } else { uel.log(action, UserEntry.Sources.TreatmentDialog, ValueWithUnit.Gram(carbsAfterConstraints).takeIf { carbsAfterConstraints != 0 }) - if (detailedBolusInfo.carbs > 0) { - disposable += repository.runTransactionForResult(detailedBolusInfo.insertCarbsTransaction()) - .subscribe( - { result -> result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") } }, - { aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) } - ) - } + if (detailedBolusInfo.carbs > 0) + persistenceLayer.insertOrUpdateCarbs(detailedBolusInfo.createCarbs()) } } }) diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt index 20ae4eb429..ea7dafbb05 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/WizardDialog.kt @@ -25,8 +25,8 @@ import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.extensions.formatColor import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.wizard.BolusWizard +import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.constraints.Constraint