From e24af3934fd9eb44bd1ec35733f539ef67e2e7e4 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Mon, 24 May 2021 16:57:54 +0100 Subject: [PATCH] - refactorings kotlin !! - moved 2 filed into pump-common module (newly created) --- app/build.gradle | 1 + .../dependencyInjection/AppModule.kt | 29 +++++--- .../pump/common/defs/PumpHistoryEntryGroup.kt | 5 +- medtronic/build.gradle | 1 + .../pump/medtronic/MedtronicPumpPlugin.kt | 67 ++++++++++--------- .../comm/MedtronicCommunicationManager.kt | 8 ++- .../pump/MedtronicPumpHistoryDecoder.kt | 4 +- .../comm/ui/MedtronicUIPostprocessor.kt | 2 +- .../medtronic/data/MedtronicHistoryData.kt | 26 +++---- .../pump/medtronic/data/dto/BolusDTO.kt | 9 --- .../pump/medtronic/data/dto/DailyTotalsDTO.kt | 4 +- .../medtronic/defs/MedtronicCommandType.kt | 4 +- .../defs/MedtronicStatusRefreshType.kt | 2 +- .../dialog/MedtronicHistoryActivity.kt | 34 +++++----- .../medtronic/driver/MedtronicPumpStatus.kt | 4 +- pump-common/.gitignore | 1 + pump-common/build.gradle | 24 +++++++ pump-common/consumer-rules.pro | 0 pump-common/proguard-rules.pro | 21 ++++++ pump-common/src/main/AndroidManifest.xml | 7 ++ .../plugins/pump/common/PumpPluginAbstract.kt | 19 ++---- .../plugins/pump/common/data/PumpStatus.kt | 0 .../plugins/pump/common/sync/PumpDbEntry.kt | 21 +++--- .../common/sync/PumpSyncEntriesCreator.java | 0 .../pump/common/sync/PumpSyncStorage.kt | 34 +++------- pump-common/src/main/res/values/strings.xml | 4 ++ settings.gradle | 4 +- 27 files changed, 187 insertions(+), 148 deletions(-) create mode 100644 pump-common/.gitignore create mode 100644 pump-common/build.gradle create mode 100644 pump-common/consumer-rules.pro create mode 100644 pump-common/proguard-rules.pro create mode 100644 pump-common/src/main/AndroidManifest.xml rename {core => pump-common}/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt (96%) rename {core => pump-common}/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.kt (100%) rename {core => pump-common}/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt (78%) rename {core => pump-common}/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncEntriesCreator.java (100%) rename {core => pump-common}/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt (90%) create mode 100644 pump-common/src/main/res/values/strings.xml diff --git a/app/build.gradle b/app/build.gradle index ccf044fa41..faaa85cae6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -186,6 +186,7 @@ dependencies { implementation project(':danars') implementation project(':danar') implementation project(':insight') + implementation project(':pump-common') implementation project(':rileylink') implementation project(':medtronic') implementation project(':omnipod-common') diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 1266f526fe..9946d55cd0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -77,27 +77,36 @@ open class AppModule { pumpSync: PumpSync, sp: SP, aapsLogger: AAPSLogger - ): PumpSyncStorage { - return PumpSyncStorage(pumpSync, sp, aapsLogger) + ): info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage { + return info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage(pumpSync, sp, aapsLogger) } @Module interface AppBindings { + @Binds fun bindContext(mainApp: MainApp): Context @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector @Binds fun bindActivePluginProvider(pluginStore: PluginStore): ActivePlugin @Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider @Binds fun bindConfigInterface(config: ConfigImpl): Config - @Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder + @Binds + fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder @Binds fun bindTreatmentsInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface - @Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface - @Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder - @Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefsImpl): ImportExportPrefs - @Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider + @Binds + fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface + @Binds + fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder + @Binds + fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefsImpl): ImportExportPrefs + @Binds + fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider @Binds fun bindLoopInterface(loopPlugin: LoopPlugin): LoopInterface - @Binds fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculator - @Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator - @Binds fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector + @Binds + fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculator + @Binds + fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator + @Binds + fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector @Binds fun bindPumpSync(pumpSyncImplementation: PumpSyncImplementation): PumpSync } diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpHistoryEntryGroup.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpHistoryEntryGroup.kt index 8c7cbafada..38fca57a8e 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpHistoryEntryGroup.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpHistoryEntryGroup.kt @@ -32,6 +32,7 @@ enum class PumpHistoryEntryGroup(val resourceId: Int) { } companion object { + private var translatedList: MutableList? = null private fun doTranslation(resourceHelper: ResourceHelper) { @@ -43,9 +44,9 @@ enum class PumpHistoryEntryGroup(val resourceId: Int) { } @JvmStatic - fun getTranslatedList(resourceHelper: ResourceHelper): List? { + fun getTranslatedList(resourceHelper: ResourceHelper): List { if (translatedList == null) doTranslation(resourceHelper) - return translatedList + return translatedList!! } } diff --git a/medtronic/build.gradle b/medtronic/build.gradle index a3cb9f789e..4c3af48c8a 100644 --- a/medtronic/build.gradle +++ b/medtronic/build.gradle @@ -16,5 +16,6 @@ android { dependencies { implementation project(':core') + implementation project(':pump-common') implementation project(':rileylink') } diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt index a77cee4a57..a0649be977 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt @@ -90,8 +90,8 @@ class MedtronicPumpPlugin @Inject constructor( dateUtil: DateUtil, aapsSchedulers: AapsSchedulers, pumpSync: PumpSync, - pumpSyncStorage: PumpSyncStorage -) : PumpPluginAbstract(PluginDescription() // + pumpSyncStorage: info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage +) : info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract(PluginDescription() // .mainType(PluginType.PUMP) // .fragmentClass(MedtronicFragment::class.java.name) // .pluginIcon(R.drawable.ic_veo_128) @@ -101,7 +101,7 @@ class MedtronicPumpPlugin @Inject constructor( .description(R.string.description_pump_medtronic), // PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil, aapsSchedulers, pumpSync, pumpSyncStorage -), Pump, RileyLinkPumpDevice, PumpSyncEntriesCreator { +), Pump, RileyLinkPumpDevice, info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator { private lateinit var rileyLinkMedtronicService: RileyLinkMedtronicService @@ -199,7 +199,7 @@ class MedtronicPumpPlugin @Inject constructor( SystemClock.sleep(60000) if (this.isInitialized) { val statusRefresh = workWithStatusRefresh( - StatusRefreshAction.GetData, null, null) + StatusRefreshAction.GetData, null, null)!! if (doWeHaveAnyStatusNeededRefereshing(statusRefresh)) { if (!commandQueue.statusInQueue()) { commandQueue.readStatus("Scheduled Status Refresh", null) @@ -214,7 +214,7 @@ class MedtronicPumpPlugin @Inject constructor( override val serviceClass: Class<*> get() = RileyLinkMedtronicService::class.java - override val pumpStatusData: PumpStatus + override val pumpStatusData: info.nightscout.androidaps.plugins.pump.common.data.PumpStatus get() = medtronicPumpStatus override fun deviceID(): String { @@ -334,7 +334,7 @@ class MedtronicPumpPlugin @Inject constructor( private fun refreshAnyStatusThatNeedsToBeRefreshed() { val statusRefresh = workWithStatusRefresh(StatusRefreshAction.GetData, null, - null) + null)!! if (!doWeHaveAnyStatusNeededRefereshing(statusRefresh)) { return } @@ -354,7 +354,7 @@ class MedtronicPumpPlugin @Inject constructor( // execute val refreshTypesNeededToReschedule: MutableSet = mutableSetOf() - for ((key, value) in statusRefresh!!) { + for ((key, value) in statusRefresh) { if (value > 0 && System.currentTimeMillis() > value) { when (key) { MedtronicStatusRefreshType.PumpHistory -> { @@ -389,8 +389,8 @@ class MedtronicPumpPlugin @Inject constructor( if (resetTime) medtronicPumpStatus.setLastCommunicationToNow() } - private fun doWeHaveAnyStatusNeededRefereshing(statusRefresh: Map?): Boolean { - for ((_, value) in statusRefresh!!) { + private fun doWeHaveAnyStatusNeededRefereshing(statusRefresh: Map): Boolean { + for ((_, value) in statusRefresh) { if (value > 0 && System.currentTimeMillis() > value) { return true } @@ -583,10 +583,10 @@ class MedtronicPumpPlugin @Inject constructor( scheduleNextRefresh(MedtronicStatusRefreshType.PumpTime, 0) } - override fun deliverBolus(detailedBolusInfo: DetailedBolusInfo?): PumpEnactResult { + override fun deliverBolus(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { aapsLogger.info(LTag.PUMP, "MedtronicPumpPlugin::deliverBolus - " + BolusDeliveryType.DeliveryPrepared) setRefreshButtonEnabled(false) - if (detailedBolusInfo!!.insulin > medtronicPumpStatus.reservoirRemainingUnits) { + if (detailedBolusInfo.insulin > medtronicPumpStatus.reservoirRemainingUnits) { return PumpEnactResult(injector) // .success(false) // .enacted(false) // @@ -621,7 +621,12 @@ class MedtronicPumpPlugin @Inject constructor( setRefreshButtonEnabled(true) // LOG.debug("MedtronicPumpPlugin::deliverBolus - Response: {}", response); - if (response!!) { + return if (response == null || !response) { + PumpEnactResult(injector) // + .success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) // + .enacted(false) // + .comment(R.string.medtronic_cmd_bolus_could_not_be_delivered) + } else { if (bolusDeliveryType == BolusDeliveryType.CancelDelivery) { // LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled after Bolus started."); Thread(Runnable { @@ -648,11 +653,6 @@ class MedtronicPumpPlugin @Inject constructor( .enacted(true) // .bolusDelivered(detailedBolusInfo.insulin) // .carbsDelivered(detailedBolusInfo.carbs) - } else { - PumpEnactResult(injector) // - .success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) // - .enacted(false) // - .comment(R.string.medtronic_cmd_bolus_could_not_be_delivered) } } finally { finishAction("Bolus") @@ -739,13 +739,13 @@ class MedtronicPumpPlugin @Inject constructor( // CANCEL val responseTask2 = rileyLinkMedtronicService.medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR) val response = responseTask2.result as Boolean? - if (response!!) { - aapsLogger.info(LTag.PUMP, logPrefix + "setTempBasalAbsolute - Current TBR cancelled.") - } else { + if (response == null || !response) { aapsLogger.error(logPrefix + "setTempBasalAbsolute - Cancel TBR failed.") finishAction("TBR") return PumpEnactResult(injector).success(false).enacted(false) .comment(R.string.medtronic_cmd_cant_cancel_tbr_stop_op) + } else { + aapsLogger.info(LTag.PUMP, logPrefix + "setTempBasalAbsolute - Current TBR cancelled.") } } @@ -763,7 +763,7 @@ class MedtronicPumpPlugin @Inject constructor( medtronicPumpStatus.tempBasalAmount = absoluteRate medtronicPumpStatus.tempBasalLength = durationInMinutes - val tempData = PumpDbEntryTBR(absoluteRate, true, durationInMinutes, tbrType) + val tempData = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(absoluteRate, true, durationInMinutes, tbrType) pumpSyncStorage.addTemporaryBasalRateWithTempId(tempData, true, this) @@ -956,10 +956,13 @@ class MedtronicPumpPlugin @Inject constructor( val tbr = responseTask.result as TempBasalPair? // we sometimes get rate returned even if TBR is no longer running - if (tbr!!.durationMinutes == 0) { - tbr.insulinRate = 0.0 - } - tbr + if (tbr != null) { + if (tbr.durationMinutes == 0) { + tbr.insulinRate = 0.0 + } + tbr + } else + null } else { null } @@ -992,7 +995,11 @@ class MedtronicPumpPlugin @Inject constructor( val responseTask2 = rileyLinkMedtronicService.medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR) val response = responseTask2.result as Boolean? finishAction("TBR") - return if (response!!) { + return if (response == null || !response) { + aapsLogger.info(LTag.PUMP, logPrefix + "cancelTempBasal - Cancel TBR failed.") + PumpEnactResult(injector).success(false).enacted(false) // + .comment(R.string.medtronic_cmd_cant_cancel_tbr) + } else { aapsLogger.info(LTag.PUMP, logPrefix + "cancelTempBasal - Cancel TBR successful.") val runningTBR = medtronicPumpStatus.runningTBR @@ -1022,19 +1029,13 @@ class MedtronicPumpPlugin @Inject constructor( } } - //pumpSyncStorage.addTemporaryBasalRateWithTempId(tempData, true, this) - PumpEnactResult(injector).success(true).enacted(true) // .isTempCancel(true) - } else { - aapsLogger.info(LTag.PUMP, logPrefix + "cancelTempBasal - Cancel TBR failed.") - PumpEnactResult(injector).success(response).enacted(response) // - .comment(R.string.medtronic_cmd_cant_cancel_tbr) } } override fun manufacturer(): ManufacturerType { - return pumpDescription.pumpType.manufacturer!! + return ManufacturerType.Medtronic } override fun model(): PumpType { diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt index cde2df1c2b..2a9dc6bf66 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.kt @@ -140,7 +140,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth medtronicUtil.medtronicPumpModel = pumpModel!! medtronicUtil.isModelSet = true } - aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "isDeviceReachable. PumpModel is %s - Valid: %b (rssi=%d)", pumpModel!!.name, valid, + aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "isDeviceReachable. PumpModel is %s - Valid: %b (rssi=%d)", medtronicUtil.medtronicPumpModel, valid, radioResponse.rssi)) if (valid) { if (state === PumpDeviceState.PumpUnreachable) @@ -313,7 +313,9 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Problem acknowledging frame response. (retry=%d)", retries)) } } - if (nextMsg != null) currentResponse = GetHistoryPageCarelinkMessageBody(nextMsg.messageBody!!.txData) else { + if (nextMsg != null) + currentResponse = GetHistoryPageCarelinkMessageBody(nextMsg.messageBody!!.txData) + else { aapsLogger.error(LTag.PUMPCOMM, "We couldn't acknowledge frame from pump, aborting operation.") } } @@ -602,7 +604,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth fun getTemporaryBasal(): TempBasalPair? { return sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal) { _, _, rawContent -> - TempBasalPair(aapsLogger, rawContent!!) + TempBasalPair(aapsLogger, rawContent) } } diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.kt index 697e8ca417..3152c423da 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.kt @@ -117,7 +117,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor( if (decoded === RecordDecodeStatus.OK || decoded === RecordDecodeStatus.Ignored) { //Log.i(TAG, "#" + record + " " + decoded.getDescription() + " " + pe); } else { - aapsLogger.warn(LTag.PUMPBTCOMM, "#" + record + " " + decoded!!.description + " " + pe) + aapsLogger.warn(LTag.PUMPBTCOMM, "#" + record + " " + decoded.description + " " + pe) } addToStatistics(pe, decoded, null) record++ @@ -130,7 +130,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor( return outList } - override fun decodeRecord(record: PumpHistoryEntry): RecordDecodeStatus? { + override fun decodeRecord(record: PumpHistoryEntry): RecordDecodeStatus { return try { decodeRecordInternal(record) } catch (ex: Exception) { diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt index 7bb6ff8c74..9ad461c0d6 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIPostprocessor.kt @@ -39,7 +39,7 @@ class MedtronicUIPostprocessor @Inject constructor( when (uiTask.commandType) { MedtronicCommandType.SetBasalProfileSTD -> { val response = uiTask.result as Boolean? - if (response!!) { + if (response != null && response) { val basalProfile = uiTask.getParameter(0) as BasalProfile aapsLogger.debug("D: basal profile returned after set: $basalProfile") diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index 6a227c7c98..3f828417a8 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -55,7 +55,7 @@ class MedtronicHistoryData @Inject constructor( val medtronicPumpStatus: MedtronicPumpStatus, val databaseHelper: DatabaseHelperInterface, val pumpSync: PumpSync, - val pumpSyncStorage: PumpSyncStorage + val pumpSyncStorage: info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage ) { val allHistory: MutableList = mutableListOf() @@ -381,12 +381,12 @@ class MedtronicHistoryData @Inject constructor( } } - private fun processPrime(primeRecords: List) { + private fun processPrime(primeRecords: List) { val maxAllowedTimeInPast = DateTimeUtil.getATDWithAddedMinutes(GregorianCalendar(), -30) var lastPrimeRecordTime = 0L var lastPrimeRecord: PumpHistoryEntry? = null for (primeRecord in primeRecords) { - val fixedAmount = primeRecord!!.getDecodedDataEntry("FixedAmount") + val fixedAmount = primeRecord.getDecodedDataEntry("FixedAmount") if (fixedAmount != null && fixedAmount as Float == 0.0f) { // non-fixed primes are used to prime the tubing // fixed primes are used to prime the cannula @@ -456,7 +456,7 @@ class MedtronicHistoryData @Inject constructor( pumpSync.createOrUpdateTotalDailyDose( DateTimeUtil.toMillisFromATD(tdd.atechDateTime), totalsDTO.insulinBolus, - totalsDTO.insulinBasal!!, + totalsDTO.insulinBasal, totalsDTO.insulinTotal, tdd.pumpId, medtronicPumpStatus.pumpType, @@ -559,7 +559,7 @@ class MedtronicHistoryData @Inject constructor( if (bolus.containsDecodedData("Estimate")) { val bolusWizard = bolus.decodedData["Estimate"] as BolusWizardDTO - pumpSyncStorage.addCarbs(PumpDbEntryCarbs( + pumpSyncStorage.addCarbs(info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryCarbs( tryToGetByLocalTime(bolus.atechDateTime), bolusWizard.carbs.toDouble(), medtronicPumpStatus.pumpType, @@ -571,9 +571,9 @@ class MedtronicHistoryData @Inject constructor( private fun processTBREntries(entryList: MutableList) { Collections.reverse(entryList) - val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair? + val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair var readOldItem = false - if (tbr!!.isCancelTBR) { + if (tbr.isCancelTBR) { val oneMoreEntryFromHistory = getOneMoreEntryFromHistory(PumpHistoryEntryType.TempBasalCombined) if (oneMoreEntryFromHistory != null) { entryList.add(0, oneMoreEntryFromHistory) @@ -679,12 +679,12 @@ class MedtronicHistoryData @Inject constructor( if (isTBRActive(tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tempBasalProcessDTO.duration)) { if (medtronicPumpStatus.runningTBR == null) { - medtronicPumpStatus.runningTBR = PumpDbEntry(0L, + medtronicPumpStatus.runningTBR = info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry(0L, tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber, null, - PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL), + info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR(tbrEntry.insulinRate, !tbrEntry.isPercent, tempBasalProcessDTO.duration, PumpSync.TemporaryBasalType.NORMAL), tempBasalProcessDTO.pumpId) } } @@ -693,7 +693,7 @@ class MedtronicHistoryData @Inject constructor( } // collection } - fun isTBRActive(dbEntry: PumpDbEntry): Boolean { + fun isTBRActive(dbEntry: info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry): Boolean { return isTBRActive(dbEntry.date, dbEntry.tbrData!!.durationInMinutes) } @@ -716,7 +716,7 @@ class MedtronicHistoryData @Inject constructor( /** * Looks at all boluses that have temporaryId and find one that is correct for us (if such entry exists) */ - private fun findDbEntry(treatment: PumpHistoryEntry, temporaryEntries: MutableList): PumpDbEntry? { + private fun findDbEntry(treatment: PumpHistoryEntry, temporaryEntries: MutableList): info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry? { if (temporaryEntries.isEmpty()) { return null @@ -728,7 +728,7 @@ class MedtronicHistoryData @Inject constructor( this.pumpTime?.let { proposedTime += (it.timeDifference * 1000) } val proposedTimeDiff: LongArray = longArrayOf(proposedTime - (2 * 60 * 1000), proposedTime + (2L * 60L * 1000L)) - val tempEntriesList: MutableList = mutableListOf() + val tempEntriesList: MutableList = mutableListOf() for (temporaryEntry in temporaryEntries) { if (temporaryEntry.date > proposedTimeDiff[0] && temporaryEntry.date < proposedTimeDiff[1]) { @@ -750,7 +750,7 @@ class MedtronicHistoryData @Inject constructor( sec = 59 } val diff = sec * 1000 - val outList: MutableList = mutableListOf() + val outList: MutableList = mutableListOf() for (treatment1 in tempEntriesList) { if (treatment1.date > proposedTime - diff && treatment1.date < proposedTime + diff) { outList.add(treatment1) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BolusDTO.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BolusDTO.kt index e2793cf597..2b738c34f0 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BolusDTO.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BolusDTO.kt @@ -36,18 +36,9 @@ class BolusDTO constructor(atechDateTime: Long, @Expose var duration: Int = 0 ) : PumpTimeStampedRecord(atechDateTime) { - // @Expose - // var requestedAmount: Double? = null - // - // @Expose - // var deliveredAmount: Double? = null - @Expose var immediateAmount: Double? = null // when Multiwave this is used - // @Expose - // var duration: Int? = null - @Expose lateinit var bolusType: PumpBolusType diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.kt index ab480bbe54..a295c76aff 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/DailyTotalsDTO.kt @@ -36,7 +36,7 @@ class DailyTotalsDTO(var entry: PumpHistoryEntry) { var insulinTotal = 0.0 @Expose - var insulinBasal: Double? = 0.0 + var insulinBasal: Double = 0.0 @Expose var insulinBolus = 0.0 @@ -55,7 +55,7 @@ class DailyTotalsDTO(var entry: PumpHistoryEntry) { private var bolusCountFood: Int? = null private var bolusCountCorr: Int? = null private fun setDisplayable() { - if (insulinBasal == null) { + if (insulinBasal == 0.0) { entry.displayableValue = "Total Insulin: " + StringUtil.getFormatedValueUS(insulinTotal, 2) } else { entry.displayableValue = ("Basal Insulin: " + StringUtil.getFormatedValueUS(insulinBasal, 2) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicCommandType.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicCommandType.kt index 07cf7bbe89..77772a867f 100755 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicCommandType.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicCommandType.kt @@ -157,8 +157,8 @@ enum class MedtronicCommandType { } @JvmStatic - fun getSettings(medtronicPumpModel: MedtronicDeviceType?): MedtronicCommandType { - return if (isSameDevice(medtronicPumpModel!!, MedtronicDeviceType.Medtronic_512_712)) + fun getSettings(medtronicPumpModel: MedtronicDeviceType): MedtronicCommandType { + return if (isSameDevice(medtronicPumpModel, MedtronicDeviceType.Medtronic_512_712)) Settings_512 else Settings diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.kt index 5a416b80a8..3185212739 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicStatusRefreshType.kt @@ -13,7 +13,7 @@ enum class MedtronicStatusRefreshType(val refreshTime: Int, PumpTime(60, MedtronicCommandType.GetRealTimeClock // ); - fun getCommandType(medtronicDeviceType: MedtronicDeviceType?): MedtronicCommandType? { + fun getCommandType(medtronicDeviceType: MedtronicDeviceType): MedtronicCommandType? { return if (this == Configuration) { MedtronicCommandType.getSettings(medtronicDeviceType) } else diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.kt index 75a399f1eb..6257099574 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/dialog/MedtronicHistoryActivity.kt @@ -22,8 +22,8 @@ import javax.inject.Inject class MedtronicHistoryActivity : DaggerActivity() { - @Inject lateinit var medtronicHistoryData: MedtronicHistoryData - @Inject lateinit var resourceHelper: ResourceHelper + @Inject lateinit var medtronicHistoryData: MedtronicHistoryData + @Inject lateinit var resourceHelper: ResourceHelper lateinit var historyTypeSpinner: Spinner lateinit var statusView: TextView @@ -33,7 +33,7 @@ class MedtronicHistoryActivity : DaggerActivity() { var filteredHistoryList: MutableList = ArrayList() var manualChange = false - var typeListFull: List? = null + lateinit var typeListFull: List //private var _binding: MedtronicHistoryActivityBinding? = null @@ -60,8 +60,8 @@ class MedtronicHistoryActivity : DaggerActivity() { } } - recyclerViewAdapter.setHistoryListInternal(filteredHistoryList) - recyclerViewAdapter.notifyDataSetChanged() + recyclerViewAdapter.setHistoryListInternal(filteredHistoryList) + recyclerViewAdapter.notifyDataSetChanged() //LOG.debug("Items on filtered list: {}", filteredHistoryList.size()); } @@ -74,8 +74,8 @@ class MedtronicHistoryActivity : DaggerActivity() { private fun setHistoryTypeSpinner() { manualChange = true - for (i in typeListFull!!.indices) { - if (typeListFull!![i].entryGroup === selectedGroup) { + for (i in typeListFull.indices) { + if (typeListFull[i].entryGroup === selectedGroup) { historyTypeSpinner.setSelection(i) break } @@ -119,15 +119,16 @@ class MedtronicHistoryActivity : DaggerActivity() { }) } - private fun getTypeList(list: List?): List { + private fun getTypeList(list: List): List { val typeList = ArrayList() - for (pumpHistoryEntryGroup in list!!) { + for (pumpHistoryEntryGroup in list) { typeList.add(TypeList(pumpHistoryEntryGroup)) } return typeList } class TypeList internal constructor(var entryGroup: PumpHistoryEntryGroup) { + var name: String override fun toString(): String { return name @@ -140,7 +141,6 @@ class MedtronicHistoryActivity : DaggerActivity() { class RecyclerViewAdapter internal constructor(var historyList: List) : RecyclerView.Adapter() { - fun setHistoryListInternal(historyList: List) { // this.historyList.clear(); // this.historyList.addAll(historyList); @@ -157,22 +157,17 @@ class MedtronicHistoryActivity : DaggerActivity() { override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) { val record = historyList[position] - //if (record != null) { - holder.timeView.text = record.dateTimeString - holder.typeView.text = record.entryType.description - holder.valueView.text = record.displayableValue - //} + holder.timeView.text = record.dateTimeString + holder.typeView.text = record.entryType.description + holder.valueView.text = record.displayableValue } override fun getItemCount(): Int { return historyList.size } - override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { - super.onAttachedToRecyclerView(recyclerView) - } - class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + var timeView: TextView var typeView: TextView var valueView: TextView @@ -188,6 +183,7 @@ class MedtronicHistoryActivity : DaggerActivity() { } companion object { + var showingType: TypeList? = null var selectedGroup = PumpHistoryEntryGroup.All } diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt index c5122ca1e8..e659db4962 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.kt @@ -27,14 +27,14 @@ class MedtronicPumpStatus @Inject constructor(private val resourceHelper: Resour private val sp: SP, private val rxBus: RxBusWrapper, private val rileyLinkUtil: RileyLinkUtil -) : PumpStatus(PumpType.MEDTRONIC_522_722) { +) : info.nightscout.androidaps.plugins.pump.common.data.PumpStatus(PumpType.MEDTRONIC_522_722) { var errorDescription: String? = null lateinit var serialNumber: String //? = null var pumpFrequency: String? = null var maxBolus: Double? = null var maxBasal: Double? = null - var runningTBR: PumpDbEntry? = null + var runningTBR: info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry? = null // statuses var pumpDeviceState = PumpDeviceState.NeverContacted diff --git a/pump-common/.gitignore b/pump-common/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/pump-common/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/pump-common/build.gradle b/pump-common/build.gradle new file mode 100644 index 0000000000..996daf31dd --- /dev/null +++ b/pump-common/build.gradle @@ -0,0 +1,24 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' +apply plugin: 'com.hiya.jacoco-android' + +apply from: "${project.rootDir}/gradle/android_dependencies.gradle" +apply from: "${project.rootDir}/gradle/android_module_dependencies.gradle" +apply from: "${project.rootDir}/gradle/test_dependencies.gradle" + +android { + defaultConfig { + versionCode 1 + versionName "1.0" + } +} + +dependencies { + implementation project(':core') + //implementation project(':database') + + implementation('com.thoughtworks.xstream:xstream:1.4.7') { + exclude group: 'xmlpull', module: 'xmlpull' + } +} diff --git a/pump-common/consumer-rules.pro b/pump-common/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pump-common/proguard-rules.pro b/pump-common/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/pump-common/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/pump-common/src/main/AndroidManifest.xml b/pump-common/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..d4055a4210 --- /dev/null +++ b/pump-common/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt similarity index 96% rename from core/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt rename to pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt index b2462ade1f..a9a871f0b5 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.kt @@ -24,9 +24,6 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewB import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState import info.nightscout.androidaps.plugins.pump.common.defs.PumpType -import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryCarbs -import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator -import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter.to0Decimal import info.nightscout.androidaps.utils.DecimalFormatter.to2Decimal @@ -38,7 +35,6 @@ import io.reactivex.disposables.CompositeDisposable import org.json.JSONException import org.json.JSONObject - /** * Created by andy on 23.04.18. */ @@ -58,14 +54,14 @@ abstract class PumpPluginAbstract protected constructor( var dateUtil: DateUtil, var aapsSchedulers: AapsSchedulers, var pumpSync: PumpSync, - var pumpSyncStorage: PumpSyncStorage -) : PumpPluginBase(pluginDescription!!, injector!!, aapsLogger, resourceHelper, commandQueue), Pump, Constraints, PumpSyncEntriesCreator { + var pumpSyncStorage: info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage +) : PumpPluginBase(pluginDescription!!, injector!!, aapsLogger, resourceHelper, commandQueue), Pump, Constraints, info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator { private val disposable = CompositeDisposable() // Pump capabilities final override var pumpDescription = PumpDescription() - //protected set + //protected set @JvmField protected var serviceConnection: ServiceConnection? = null @JvmField protected var serviceRunning = false @@ -79,7 +75,6 @@ abstract class PumpPluginAbstract protected constructor( pumpDescription.fillFor(value) } - protected var gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() abstract fun initPumpStatusData() @@ -282,7 +277,7 @@ abstract class PumpPluginAbstract protected constructor( override fun shortStatus(veryShort: Boolean): String { var ret = "" - if (pumpStatusData.lastConnection==0L) { + if (pumpStatusData.lastConnection == 0L) { ret += "LastConn: never\n" } else { val agoMsec = System.currentTimeMillis() - pumpStatusData.lastConnection @@ -343,7 +338,7 @@ abstract class PumpPluginAbstract protected constructor( detailedBolusInfo.timestamp = System.currentTimeMillis() // no bolus required, carb only treatment - pumpSyncStorage.addCarbs(PumpDbEntryCarbs(detailedBolusInfo, this)) + pumpSyncStorage.addCarbs(info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryCarbs(detailedBolusInfo, this)) val bolusingEvent = EventOverviewBolusProgress bolusingEvent.t = EventOverviewBolusProgress.Treatment(0.0, detailedBolusInfo.carbs.toInt(), detailedBolusInfo.bolusType === DetailedBolusInfo.BolusType.SMB) @@ -370,12 +365,11 @@ abstract class PumpPluginAbstract protected constructor( return pumpType } - override fun canHandleDST(): Boolean { return false } - protected abstract fun deliverBolus(detailedBolusInfo: DetailedBolusInfo?): PumpEnactResult + protected abstract fun deliverBolus(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult protected abstract fun triggerUIChange() @@ -383,7 +377,6 @@ abstract class PumpPluginAbstract protected constructor( return PumpEnactResult(injector).success(false).enacted(false).comment(resourceId) } - init { pumpDescription.fillFor(pumpType) this.pumpType = pumpType diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.kt similarity index 100% rename from core/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.kt rename to pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.kt diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt similarity index 78% rename from core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt rename to pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt index c84312cebc..e1b734b048 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpDbEntry.kt @@ -4,14 +4,13 @@ import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.plugins.pump.common.defs.PumpType - data class PumpDbEntry constructor(var temporaryId: Long, - var date: Long, - var pumpType: PumpType, - var serialNumber: String, - var bolusData: PumpDbEntryBolus? = null, - var tbrData: PumpDbEntryTBR? = null, - var pumpId: Long? = null) { + var date: Long, + var pumpType: PumpType, + var serialNumber: String, + var bolusData: PumpDbEntryBolus? = null, + var tbrData: PumpDbEntryTBR? = null, + var pumpId: Long? = null) { constructor(temporaryId: Long, date: Long, @@ -41,7 +40,6 @@ data class PumpDbEntry constructor(var temporaryId: Long, } - data class PumpDbEntryBolus(var insulin: Double, var carbs: Double, var bolusType: DetailedBolusInfo.BolusType) @@ -51,11 +49,12 @@ data class PumpDbEntryCarbs(var date: Long, var pumpType: PumpType, var serialNumber: String, var pumpId: Long? = null) { + constructor(detailedBolusInfo: DetailedBolusInfo, creator: PumpSyncEntriesCreator) : this(detailedBolusInfo.timestamp, - detailedBolusInfo.carbs, - creator.model(), - creator.serialNumber()) + detailedBolusInfo.carbs, + creator.model(), + creator.serialNumber()) } data class PumpDbEntryTBR(var rate: Double, diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncEntriesCreator.java b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncEntriesCreator.java similarity index 100% rename from core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncEntriesCreator.java rename to pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncEntriesCreator.java diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt similarity index 90% rename from core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt rename to pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt index 99903e73cb..8084d52cd6 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt +++ b/pump-common/src/main/java/info/nightscout/androidaps/plugins/pump/common/sync/PumpSyncStorage.kt @@ -2,14 +2,12 @@ package info.nightscout.androidaps.plugins.pump.common.sync import com.google.gson.Gson import com.google.gson.GsonBuilder -import com.google.gson.reflect.TypeToken import com.thoughtworks.xstream.XStream import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.utils.sharedPreferences.SP -import java.lang.reflect.Type import java.util.* import javax.inject.Inject import javax.inject.Singleton @@ -25,19 +23,17 @@ class PumpSyncStorage @Inject constructor( ) { val pumpSyncStorageKey: String = "pump_sync_storage_xstream" - var pumpSyncStorage: MutableMap> = mutableMapOf() + var pumpSyncStorage: MutableMap> = mutableMapOf() var TBR: String = "TBR" var BOLUS: String = "BOLUS" var storageInitialized: Boolean = false var gson: Gson = GsonBuilder().create() var xstream: XStream = XStream() - init { initStorage() } - fun initStorage() { if (storageInitialized) return @@ -61,7 +57,6 @@ class PumpSyncStorage @Inject constructor( } } - fun saveStorage() { if (!isStorageEmpty()) { sp.putString(pumpSyncStorageKey, xstream.toXML(pumpSyncStorage)) @@ -69,22 +64,18 @@ class PumpSyncStorage @Inject constructor( } } - - fun isStorageEmpty() : Boolean { + fun isStorageEmpty(): Boolean { return pumpSyncStorage[BOLUS]!!.isEmpty() && pumpSyncStorage[TBR]!!.isEmpty() } - - fun getBoluses() : MutableList { + fun getBoluses(): MutableList { return pumpSyncStorage[BOLUS]!!; } - - fun getTBRs() : MutableList { + fun getTBRs(): MutableList { return pumpSyncStorage[TBR]!!; } - fun addBolusWithTempId(detailedBolusInfo: DetailedBolusInfo, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean { val temporaryId = creator.generateTempId(detailedBolusInfo.timestamp) val result = pumpSync.addBolusWithTempId( @@ -99,12 +90,12 @@ class PumpSyncStorage @Inject constructor( detailedBolusInfo.timestamp, temporaryId, detailedBolusInfo.insulin, detailedBolusInfo.bolusType, creator.serialNumber(), result)) - if (detailedBolusInfo.carbs>0.0) { + if (detailedBolusInfo.carbs > 0.0) { addCarbs(PumpDbEntryCarbs(detailedBolusInfo, creator)) } if (result && writeToInternalHistory) { - var innerList: MutableList = pumpSyncStorage[BOLUS]!! + val innerList: MutableList = pumpSyncStorage[BOLUS]!! innerList.add(PumpDbEntry(temporaryId, detailedBolusInfo.timestamp, creator.model(), creator.serialNumber(), detailedBolusInfo)) pumpSyncStorage[BOLUS] = innerList @@ -113,7 +104,6 @@ class PumpSyncStorage @Inject constructor( return result } - fun addCarbs(carbsDto: PumpDbEntryCarbs) { val result = pumpSync.syncCarbsWithTimestamp( carbsDto.date, @@ -126,9 +116,8 @@ class PumpSyncStorage @Inject constructor( carbsDto.date, carbsDto.carbs, carbsDto.serialNumber, result)) } - - fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator) : Boolean { - val timenow : Long = System.currentTimeMillis() + fun addTemporaryBasalRateWithTempId(temporaryBasal: PumpDbEntryTBR, writeToInternalHistory: Boolean, creator: PumpSyncEntriesCreator): Boolean { + val timenow: Long = System.currentTimeMillis() val temporaryId = creator.generateTempId(timenow) val response = pumpSync.addTemporaryBasalWithTempId( @@ -142,7 +131,7 @@ class PumpSyncStorage @Inject constructor( creator.serialNumber()) if (response && writeToInternalHistory) { - var innerList: MutableList = pumpSyncStorage[TBR]!! + val innerList: MutableList = pumpSyncStorage[TBR]!! innerList.add(PumpDbEntry(temporaryId, timenow, creator.model(), creator.serialNumber(), null, temporaryBasal)) pumpSyncStorage[BOLUS] = innerList @@ -152,21 +141,18 @@ class PumpSyncStorage @Inject constructor( return response; } - fun removeBolusWithTemporaryId(temporaryId: Long) { val bolusList = removeTemporaryId(temporaryId, pumpSyncStorage[BOLUS]!!) pumpSyncStorage[BOLUS] = bolusList saveStorage() } - fun removeTemporaryBasalWithTemporaryId(temporaryId: Long) { val tbrList = removeTemporaryId(temporaryId, pumpSyncStorage[TBR]!!) pumpSyncStorage[TBR] = tbrList saveStorage() } - private fun removeTemporaryId(temporaryId: Long, list: MutableList): MutableList { var dbEntry: PumpDbEntry? = null @@ -176,7 +162,7 @@ class PumpSyncStorage @Inject constructor( } } - if (dbEntry!=null) { + if (dbEntry != null) { list.remove(dbEntry) } diff --git a/pump-common/src/main/res/values/strings.xml b/pump-common/src/main/res/values/strings.xml new file mode 100644 index 0000000000..0d2c4cc409 --- /dev/null +++ b/pump-common/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index a35251b846..15a8fcf539 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,8 +8,10 @@ include ':combo' include ':dana' include ':danar' include ':danars' +include ':pump-common' include ':rileylink' include ':medtronic' include ':omnipod-common' include ':omnipod-eros' -include ':omnipod-dash' \ No newline at end of file +include ':omnipod-dash' +