From 97433c7ace6e9684ce70acadd44de2b8d300c893 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 25 Nov 2022 21:08:03 +0100 Subject: [PATCH] Dana: remove core dependency --- .../nightscout/androidaps/di/AppComponent.kt | 4 +- .../maintenance/MaintenanceFragment.kt | 2 +- .../general/overview/OverviewFragment.kt | 4 +- .../androidaps/TestBaseWithProfile.kt | 2 +- .../interfaces/ConstraintsCheckerTest.kt | 15 ++- .../userEntry/UserEntryPresentationHelper.kt | 2 +- .../core/di/CoreDataClassesModule.kt | 2 - .../core/profile/ProfileStoreObject.kt | 104 ----------------- .../core-main/src/main/res/values/strings.xml | 11 -- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 1 - .../data/PointsWithLabelGraphSeries.java | 1 + .../src/main/res/drawable/ic_local_save.xml | 0 .../src/main/res/drawable/ic_pump_history.xml | 0 .../src/main/res/drawable/ic_stats.xml} | 0 .../main/res/drawable/ic_user_options.xml} | 0 .../src/main/res/layout/spinner_centered.xml | 0 core/ui/src/main/res/values/strings.xml | 11 ++ .../implementation/di/ImplementationModule.kt | 9 +- .../profile/ProfileInstantiatorImpl.kt | 17 +++ .../profile/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 2 +- .../interfaces/profile/ProfileInstantiator.kt | 7 ++ .../general/autotune/AutotuneFragment.kt | 9 +- .../general/autotune/AutotunePlugin.kt | 9 +- .../general/autotune/data/ATProfile.kt | 5 +- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 1 - .../automation/AutomationFragment.kt | 4 +- .../res/layout/automation_dialog_event.xml | 2 +- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 1 - .../plugins/profile/ProfilePlugin.kt | 14 ++- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 1 - pump/combov2/src/main/res/values/strings.xml | 2 +- pump/dana/build.gradle | 8 +- .../1.json | 93 +++++++++++++++ pump/dana/src/main/AndroidManifest.xml | 8 +- .../androidaps/dana/di/DanaModule.kt | 22 ---- .../{androidaps => pump}/dana/DanaFragment.kt | 26 ++--- .../{androidaps => pump}/dana/DanaPump.kt | 9 +- .../dana/activities/DanaHistoryActivity.kt | 25 ++-- .../activities/DanaUserOptionsActivity.kt | 60 +++++----- .../dana/comm/RecordTypes.kt | 2 +- .../dana/database/DanaHistoryDatabase.kt | 3 +- .../dana/database/DanaHistoryRecord.kt | 4 +- .../dana/database/DanaHistoryRecordDao.kt | 2 +- .../dana/di/DanaHistoryModule.kt | 6 +- .../nightscout/pump/dana/di/DanaModule.kt | 17 +++ .../dana/events/EventDanaRNewStatus.kt | 2 +- .../src/main/res/drawable/ic_dana_profile.xml | 0 .../src/main/res/layout/danar_fragment.xml | 26 ++--- .../res/layout/danar_history_activity.xml | 6 +- .../layout/danar_user_options_activity.xml | 46 ++++---- pump/dana/src/main/res/values/strings.xml | 28 ++--- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 6 - .../androidaps/dana/DanaPumpTest.kt | 5 +- .../danaRKorean/DanaRKoreanPlugin.kt | 2 +- .../danaRKorean/comm/MsgCheckValue_k.kt | 3 +- .../services/DanaRKoreanExecutionService.java | 4 +- .../androidaps/danaRv2/DanaRv2Plugin.java | 2 +- .../danaRv2/comm/MsgCheckValue_v2.kt | 2 +- .../danaRv2/comm/MsgHistoryEventsV2.kt | 2 +- .../services/DanaRv2ExecutionService.java | 4 +- .../androidaps/danar/AbstractDanaRPlugin.java | 6 +- .../androidaps/danar/DanaRPlugin.java | 2 +- .../androidaps/danar/SerialIOThread.java | 2 +- .../androidaps/danar/comm/MessageBase.kt | 4 +- .../androidaps/danar/comm/MsgCheckValue.kt | 2 +- .../androidaps/danar/comm/MsgHistoryAll.kt | 6 +- .../danar/comm/MsgInitConnStatusBasic.kt | 9 +- .../androidaps/danar/comm/MsgSetCarbsEntry.kt | 3 +- .../danar/comm/MsgSettingGlucose.kt | 2 +- .../danar/comm/MsgSettingProfileRatios.kt | 2 +- .../danar/comm/MsgSettingProfileRatiosAll.kt | 2 +- .../androidaps/danar/comm/MsgStatusProfile.kt | 2 +- .../AbstractDanaRExecutionService.java | 4 +- .../danar/services/DanaRExecutionService.java | 4 +- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 1 - .../plugins/pump/danaR/DanaRPluginTest.kt | 6 +- .../plugins/pump/danaR/comm/DanaRTestBase.kt | 8 +- .../pump/danaR/comm/MsgCheckValueTest.kt | 2 +- .../comm/MsgSettingProfileRatiosAllTest.kt | 2 +- .../danaR/comm/MsgSettingProfileRatiosTest.kt | 2 +- .../pump/danaR/comm/MsgSettingPumpTimeTest.kt | 2 +- .../danaR/comm/MsgSettingShippingInfoTest.kt | 2 +- .../danaR/comm/MsgSettingUserOptionsTest.kt | 2 +- .../pump/danaR/comm/MsgStatusProfileTest.kt | 2 +- .../pump/danaR/comm/RecordTypesTest.kt | 3 +- .../pump/danaRKorean/DanaRKoreanPluginTest.kt | 6 +- .../plugins/pump/danaRv2/DanaRv2PluginTest.kt | 6 +- .../pump/danaRv2/comm/MsgCheckValueRv2Test.kt | 2 +- .../androidaps/danars/DanaRSPlugin.kt | 6 +- .../comm/DanaRSPacketAPSHistoryEvents.kt | 2 +- .../comm/DanaRSPacketAPSSetEventHistory.kt | 3 +- .../comm/DanaRSPacketBasalGetBasalRate.kt | 2 +- .../comm/DanaRSPacketBasalGetProfileNumber.kt | 2 +- .../comm/DanaRSPacketBolusGet24CIRCFArray.kt | 3 +- .../comm/DanaRSPacketBolusGetBolusOption.kt | 2 +- .../comm/DanaRSPacketBolusGetCIRCFArray.kt | 2 +- ...aRSPacketBolusGetCalculationInformation.kt | 2 +- ...anaRSPacketBolusGetStepBolusInformation.kt | 3 +- .../comm/DanaRSPacketBolusSet24CIRCFArray.kt | 3 +- .../DanaRSPacketBolusSetStepBolusStart.kt | 2 +- .../comm/DanaRSPacketBolusSetStepBolusStop.kt | 6 +- .../comm/DanaRSPacketGeneralGetPumpCheck.kt | 2 +- ...naRSPacketGeneralGetShippingInformation.kt | 2 +- .../DanaRSPacketGeneralGetShippingVersion.kt | 2 +- ...RSPacketGeneralInitialScreenInformation.kt | 2 +- .../danars/comm/DanaRSPacketHistory.kt | 8 +- .../danars/comm/DanaRSPacketNotifyAlarm.kt | 2 +- .../DanaRSPacketNotifyDeliveryComplete.kt | 6 +- .../DanaRSPacketNotifyDeliveryRateDisplay.kt | 6 +- .../comm/DanaRSPacketOptionGetPumpTime.kt | 2 +- ...DanaRSPacketOptionGetPumpUTCAndTimeZone.kt | 2 +- .../comm/DanaRSPacketOptionGetUserOption.kt | 2 +- .../comm/DanaRSPacketOptionSetUserOption.kt | 2 +- .../comm/DanaRSPacketReviewGetPumpDecRatio.kt | 2 +- .../androidaps/danars/services/BLEComm.kt | 2 +- .../danars/services/DanaRSService.kt | 6 +- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 1 - .../androidaps/danars/DanaRSTestBase.kt | 6 +- .../comm/DanaRSPacketHistoryAlarmTest.kt | 6 +- .../danars/comm/DanaRsMessageHashTableTest.kt | 2 +- .../DanaRsPacketApsSetEventHistoryTest.kt | 2 +- .../DanaRsPacketBolusGetCirCfArrayTest.kt | 2 +- .../androidaps/diaconn/DiaconnG8Fragment.kt | 4 +- .../main/res/layout/diaconn_g8_fragment.xml | 8 +- .../layout/diaconn_g8_history_activity.xml | 4 +- .../diaconn_g8_user_options_activity.xml | 2 +- .../pump/medtronic/MedtronicFragment.kt | 2 +- .../main/res/layout/medtronic_fragment.xml | 4 +- .../ui/activities/ProfileHelperActivity.kt | 10 +- .../ui/activities/SurveyActivity.kt | 2 +- .../fragments/TreatmentsCareportalFragment.kt | 4 +- .../ui/defaultProfile/DefaultProfile.kt | 8 +- .../ui/defaultProfile/DefaultProfileDPV.kt | 8 +- .../main/res/layout/treatments_fragment.xml | 2 +- ui/src/main/res/values/strings.xml | 6 +- .../androidaps/ProfileStoreObject.kt | 107 ++++++++++++++++++ .../androidaps/TestBaseWithProfile.kt | 2 +- .../ui/defaultProfile/DefaultProfileTest.kt | 6 +- 146 files changed, 1448 insertions(+), 453 deletions(-) create mode 100644 core/core-main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt rename core/{core-main => ui}/src/main/res/drawable/ic_local_save.xml (100%) rename core/{core-main => ui}/src/main/res/drawable/ic_pump_history.xml (100%) rename core/{core-main/src/main/res/drawable/ic_danarstats.xml => ui/src/main/res/drawable/ic_stats.xml} (100%) rename core/{core-main/src/main/res/drawable/ic_danar_useropt.xml => ui/src/main/res/drawable/ic_user_options.xml} (100%) rename core/{core-main => ui}/src/main/res/layout/spinner_centered.xml (100%) create mode 100644 implementation/src/main/java/info/nightscout/implementation/profile/ProfileInstantiatorImpl.kt create mode 100644 implementation/src/main/java/info/nightscout/implementation/profile/ProfileStoreObject.kt create mode 100644 interfaces/src/main/java/info/nightscout/interfaces/profile/ProfileInstantiator.kt create mode 100644 plugins/aps/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt create mode 100644 plugins/automation/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt create mode 100644 plugins/main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt create mode 100644 pump/dana/schemas/info.nightscout.pump.dana.database.DanaHistoryDatabase/1.json delete mode 100644 pump/dana/src/main/java/info/nightscout/androidaps/dana/di/DanaModule.kt rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/DanaFragment.kt (92%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/DanaPump.kt (98%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/activities/DanaHistoryActivity.kt (94%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/activities/DanaUserOptionsActivity.kt (74%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/comm/RecordTypes.kt (93%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/database/DanaHistoryDatabase.kt (89%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/database/DanaHistoryRecord.kt (82%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/database/DanaHistoryRecordDao.kt (91%) rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/di/DanaHistoryModule.kt (72%) create mode 100644 pump/dana/src/main/java/info/nightscout/pump/dana/di/DanaModule.kt rename pump/dana/src/main/java/info/nightscout/{androidaps => pump}/dana/events/EventDanaRNewStatus.kt (62%) rename core/core-main/src/main/res/drawable/ic_danarprofile.xml => pump/dana/src/main/res/drawable/ic_dana_profile.xml (100%) create mode 100644 pump/dana/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt create mode 100644 pump/danar/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt create mode 100644 pump/danars/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt create mode 100644 ui/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt diff --git a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt index 8da6a46fc8..c3265444c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt @@ -5,8 +5,6 @@ import dagger.Component import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjector import info.nightscout.androidaps.MainApp -import info.nightscout.androidaps.dana.di.DanaHistoryModule -import info.nightscout.androidaps.dana.di.DanaModule import info.nightscout.androidaps.danar.di.DanaRModule import info.nightscout.androidaps.danars.di.DanaRSModule import info.nightscout.androidaps.diaconn.di.DiaconnG8Module @@ -28,6 +26,8 @@ import info.nightscout.plugins.aps.di.ApsModule import info.nightscout.plugins.di.PluginsModule import info.nightscout.pump.combo.di.ComboModule import info.nightscout.pump.combov2.di.ComboV2Module +import info.nightscout.pump.dana.di.DanaHistoryModule +import info.nightscout.pump.dana.di.DanaModule import info.nightscout.rx.di.RxModule import info.nightscout.shared.di.SharedModule import info.nightscout.shared.impl.di.SharedImplModule diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt index 658119193b..12ce85f1d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt @@ -8,7 +8,6 @@ import android.view.ViewGroup import androidx.core.text.toSpanned import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R -import info.nightscout.androidaps.dana.database.DanaHistoryDatabase import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding import info.nightscout.androidaps.diaconn.database.DiaconnHistoryDatabase import info.nightscout.androidaps.insight.database.InsightDatabase @@ -29,6 +28,7 @@ import info.nightscout.interfaces.protection.ProtectionCheck.Protection.PREFEREN import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.sync.DataSyncSelector import info.nightscout.interfaces.utils.HtmlHelper +import info.nightscout.pump.dana.database.DanaHistoryDatabase import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventPreferenceChange diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 98043b9b8a..1fde1860c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -30,7 +30,6 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R import info.nightscout.androidaps.extensions.directionToIcon import info.nightscout.androidaps.extensions.valueToUnitsString -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewCalcProgress import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph @@ -60,6 +59,7 @@ import info.nightscout.interfaces.aps.Loop 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.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.DefaultValueHelper @@ -621,7 +621,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList it.layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 0.5f).also { l -> l.setMargins(0, 0, rh.dpToPx(-4), 0) } - it.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_danar_useropt), null, null) + it.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_user_options), null, null) it.text = event.title it.setOnClickListener { diff --git a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 0cd5f61864..c61c03d0c6 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -5,10 +5,10 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.entities.EffectiveProfileSwitch import info.nightscout.database.entities.embedments.InsulinConfiguration +import info.nightscout.implementation.profile.ProfileStoreObject import info.nightscout.interfaces.Config import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index d7351fd18e..111357c571 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -5,7 +5,6 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.HardLimitsMock import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.DanaRPlugin import info.nightscout.androidaps.danars.DanaRSPlugin import info.nightscout.androidaps.implementations.ConfigImpl @@ -22,6 +21,7 @@ import info.nightscout.interfaces.maintenance.PrefFileListProvider import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginType +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.profiling.Profiler import info.nightscout.interfaces.pump.DetailedBolusInfoStorage import info.nightscout.interfaces.pump.PumpEnactResult @@ -31,6 +31,9 @@ import info.nightscout.interfaces.pump.defs.PumpDescription import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.plugins.aps.openAPSAMA.OpenAPSAMAPlugin +import info.nightscout.plugins.aps.openAPSSMB.OpenAPSSMBPlugin +import info.nightscout.plugins.aps.openAPSSMBDynamicISF.OpenAPSSMBDynamicISFPlugin import info.nightscout.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.plugins.constraints.objectives.objectives.Objective import info.nightscout.plugins.constraints.safety.SafetyPlugin @@ -38,6 +41,7 @@ import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.plugins.source.GlimpPlugin import info.nightscout.pump.combo.ComboPlugin import info.nightscout.pump.combo.ruffyscripter.RuffyScripter +import info.nightscout.pump.dana.DanaPump import info.nightscout.shared.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -64,6 +68,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { @Mock lateinit var insightDatabaseDao: InsightDatabaseDao @Mock lateinit var ruffyScripter: RuffyScripter @Mock lateinit var activityNames: ActivityNames + @Mock lateinit var profileInstantiator: ProfileInstantiator private lateinit var hardLimits: HardLimits private lateinit var danaPump: DanaPump @@ -75,9 +80,9 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { private lateinit var danaRPlugin: DanaRPlugin private lateinit var danaRSPlugin: DanaRSPlugin private lateinit var insightPlugin: LocalInsightPlugin - private lateinit var openAPSSMBPlugin: info.nightscout.plugins.aps.openAPSSMB.OpenAPSSMBPlugin - private lateinit var openAPSAMAPlugin: info.nightscout.plugins.aps.openAPSAMA.OpenAPSAMAPlugin - private lateinit var openAPSSMBDynamicISFPlugin: info.nightscout.plugins.aps.openAPSSMBDynamicISF.OpenAPSSMBDynamicISFPlugin + private lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin + private lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin + private lateinit var openAPSSMBDynamicISFPlugin: OpenAPSSMBDynamicISFPlugin private val injector = HasAndroidInjector { AndroidInjector { @@ -132,7 +137,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { hardLimits = HardLimitsMock(sp, rh) insightDbHelper = InsightDbHelper(insightDatabaseDao) - danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) + danaPump = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator) objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, rh, activePlugin, sp, config) comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, rh, profileFunction, sp, commandQueue, pumpSync, dateUtil, ruffyScripter, activityNames) danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync) diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt b/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt index 80a710d867..7e50e62764 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt +++ b/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt @@ -157,7 +157,7 @@ class UserEntryPresentationHelper @Inject constructor( csvString(R.string.date), csvString(R.string.ue_utc_offset), csvString(R.string.ue_action), - csvString(R.string.eventtype), + csvString(R.string.event_type), csvString(R.string.ue_source), csvString(R.string.careportal_note), csvString(R.string.ue_string), diff --git a/core/core-main/src/main/java/info/nightscout/core/di/CoreDataClassesModule.kt b/core/core-main/src/main/java/info/nightscout/core/di/CoreDataClassesModule.kt index d7486ed806..109830f222 100644 --- a/core/core-main/src/main/java/info/nightscout/core/di/CoreDataClassesModule.kt +++ b/core/core-main/src/main/java/info/nightscout/core/di/CoreDataClassesModule.kt @@ -4,7 +4,6 @@ import dagger.Module import dagger.android.ContributesAndroidInjector import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensDataObject import info.nightscout.core.aps.APSResultObject -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.wizard.BolusWizard import info.nightscout.core.wizard.QuickWizardEntry import info.nightscout.interfaces.pump.PumpEnactResult @@ -16,7 +15,6 @@ abstract class CoreDataClassesModule { @ContributesAndroidInjector abstract fun pumpEnactResultInjector(): PumpEnactResult @ContributesAndroidInjector abstract fun apsResultInjector(): APSResultObject @ContributesAndroidInjector abstract fun autosensDataInjector(): AutosensDataObject - @ContributesAndroidInjector abstract fun profileStoreInjector(): ProfileStoreObject @ContributesAndroidInjector abstract fun bolusWizardInjector(): BolusWizard @ContributesAndroidInjector abstract fun quickWizardEntryInjector(): QuickWizardEntry } diff --git a/core/core-main/src/main/java/info/nightscout/core/profile/ProfileStoreObject.kt b/core/core-main/src/main/java/info/nightscout/core/profile/ProfileStoreObject.kt index 8b0cccbe02..d857c4eab2 100644 --- a/core/core-main/src/main/java/info/nightscout/core/profile/ProfileStoreObject.kt +++ b/core/core-main/src/main/java/info/nightscout/core/profile/ProfileStoreObject.kt @@ -1,106 +1,2 @@ package info.nightscout.core.profile -import androidx.collection.ArrayMap -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.extensions.pureProfileFromJson -import info.nightscout.interfaces.Config -import info.nightscout.interfaces.plugin.ActivePlugin -import info.nightscout.interfaces.profile.ProfileStore -import info.nightscout.interfaces.profile.PureProfile -import info.nightscout.interfaces.utils.HardLimits -import info.nightscout.interfaces.utils.JsonHelper -import info.nightscout.rx.bus.RxBus -import info.nightscout.rx.logging.AAPSLogger -import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.shared.utils.DateUtil -import org.json.JSONException -import org.json.JSONObject -import javax.inject.Inject - -class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { - - @Inject lateinit var aapsLogger: AAPSLogger - @Inject lateinit var activePlugin: ActivePlugin - @Inject lateinit var config: Config - @Inject lateinit var rh: ResourceHelper - @Inject lateinit var rxBus: RxBus - @Inject lateinit var hardLimits: HardLimits - - init { - injector.androidInjector().inject(this) - } - - private val cachedObjects = ArrayMap() - - private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) - - private fun getStore(): JSONObject? { - try { - if (data.has("store")) return data.getJSONObject("store") - } catch (e: JSONException) { - aapsLogger.error("Unhandled exception", e) - } - return null - } - - override fun getStartDate(): Long { - val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 - return try { - dateUtil.fromISODateString(iso) - } catch (e: Exception) { - 0 - } - } - - override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } - override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } - - override fun getDefaultProfileName(): String? { - val defaultProfileName = data.optString("defaultProfile") - return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null - } - - override fun getProfileList(): ArrayList { - val ret = ArrayList() - getStore()?.keys()?.let { keys -> - while (keys.hasNext()) { - val profileName = keys.next() as String - ret.add(profileName) - } - } - return ret - } - - @Synchronized - override fun getSpecificProfile(profileName: String): PureProfile? { - var profile: PureProfile? = null - val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) - getStore()?.let { store -> - if (store.has(profileName)) { - profile = cachedObjects[profileName] - if (profile == null) { - JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> - profile = pureProfileFromJson(profileObject, dateUtil, units) - profile?.let { cachedObjects[profileName] = profile } - } - } - } - } - return profile - } - - private fun getSpecificProfileJson(profileName: String): JSONObject? { - getStore()?.let { store -> - if (store.has(profileName)) - return JsonHelper.safeGetJSONObject(store, profileName, null) - } - return null - } - - override val allProfilesValid: Boolean - get() = getProfileList() - .asSequence() - .map { profileName -> getSpecificProfile(profileName.toString()) } - .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } - .all { it?.isValid == true } -} diff --git a/core/core-main/src/main/res/values/strings.xml b/core/core-main/src/main/res/values/strings.xml index b248088562..87652abd9c 100644 --- a/core/core-main/src/main/res/values/strings.xml +++ b/core/core-main/src/main/res/values/strings.xml @@ -9,7 +9,6 @@ AAPS started %1$+.2f U %1$d g - %1$.0f / %2$d U %1$.2f h %1$d mins Pump is busy @@ -17,7 +16,6 @@ Objectives Please wait… Mute - Reload Stop Carbs Invalid profile! @@ -36,12 +34,6 @@ Basal rate Blood Glucose Target Initializing ... - Daily units - Pump history - View profile - Event type - mg/dl - mmol/l g % Advanced Settings @@ -228,7 +220,6 @@ NS Record Reading pump history - Pump icon Connection timed out @@ -247,7 +238,6 @@ %1$d g additional carbs required within %2$d minutes - Stats Cumulative TDD Exponentially Weighted TDD Basal @@ -436,7 +426,6 @@ KeepAlive. Status outdated. KeepAlive. Basal outdated. SMS - Clicked connect to pump Pump driver change. Device changed Clicked refresh diff --git a/core/core-main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt b/core/core-main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt new file mode 100644 index 0000000000..297ebcc121 --- /dev/null +++ b/core/core-main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.androidaps + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/core/core-main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/core/core-main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 2497976c0c..04782b3361 100644 --- a/core/core-main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/core/core-main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -5,7 +5,6 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.DefaultValueHelper diff --git a/core/graph/src/main/java/info/nightscout/core/graph/data/PointsWithLabelGraphSeries.java b/core/graph/src/main/java/info/nightscout/core/graph/data/PointsWithLabelGraphSeries.java index 95e98a1226..0446f19113 100644 --- a/core/graph/src/main/java/info/nightscout/core/graph/data/PointsWithLabelGraphSeries.java +++ b/core/graph/src/main/java/info/nightscout/core/graph/data/PointsWithLabelGraphSeries.java @@ -95,6 +95,7 @@ public class PointsWithLabelGraphSeries e * @param canvas canvas to draw on * @param isSecondScale whether it is the second scale */ + @SuppressWarnings({"deprecation"}) @Override public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) { // Convert the sp to pixels diff --git a/core/core-main/src/main/res/drawable/ic_local_save.xml b/core/ui/src/main/res/drawable/ic_local_save.xml similarity index 100% rename from core/core-main/src/main/res/drawable/ic_local_save.xml rename to core/ui/src/main/res/drawable/ic_local_save.xml diff --git a/core/core-main/src/main/res/drawable/ic_pump_history.xml b/core/ui/src/main/res/drawable/ic_pump_history.xml similarity index 100% rename from core/core-main/src/main/res/drawable/ic_pump_history.xml rename to core/ui/src/main/res/drawable/ic_pump_history.xml diff --git a/core/core-main/src/main/res/drawable/ic_danarstats.xml b/core/ui/src/main/res/drawable/ic_stats.xml similarity index 100% rename from core/core-main/src/main/res/drawable/ic_danarstats.xml rename to core/ui/src/main/res/drawable/ic_stats.xml diff --git a/core/core-main/src/main/res/drawable/ic_danar_useropt.xml b/core/ui/src/main/res/drawable/ic_user_options.xml similarity index 100% rename from core/core-main/src/main/res/drawable/ic_danar_useropt.xml rename to core/ui/src/main/res/drawable/ic_user_options.xml diff --git a/core/core-main/src/main/res/layout/spinner_centered.xml b/core/ui/src/main/res/layout/spinner_centered.xml similarity index 100% rename from core/core-main/src/main/res/layout/spinner_centered.xml rename to core/ui/src/main/res/layout/spinner_centered.xml diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 5e5177ca9f..1c6cc3c3ed 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -18,6 +18,10 @@ No valid basal rate read from pump Limiting IOB to %1$.1f U because of %2$s LOOP DISABLED BY CONSTRAINTS + Event type + Reload + mg/dl + mmol/l Battery @@ -30,6 +34,13 @@ Serial number Disconnected Connecting + Clicked connect to pump + %1$.0f / %2$d U + Daily units + Pump icon + View profile + Pump history + Stats language 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 00e7354886..c98f9f50a1 100644 --- a/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt +++ b/implementation/src/main/java/info/nightscout/implementation/di/ImplementationModule.kt @@ -2,6 +2,7 @@ package info.nightscout.implementation.di import dagger.Binds import dagger.Module +import dagger.android.ContributesAndroidInjector import info.nightscout.core.graph.OverviewData import info.nightscout.implementation.AndroidPermissionImpl import info.nightscout.implementation.BolusTimerImpl @@ -19,6 +20,8 @@ import info.nightscout.implementation.logging.LoggerUtilsImpl import info.nightscout.implementation.maintenance.PrefFileListProviderImpl import info.nightscout.implementation.overview.OverviewDataImpl import info.nightscout.implementation.plugin.PluginStore +import info.nightscout.implementation.profile.ProfileInstantiatorImpl +import info.nightscout.implementation.profile.ProfileStoreObject import info.nightscout.implementation.profiling.ProfilerImpl import info.nightscout.implementation.protection.PasswordCheckImpl import info.nightscout.implementation.protection.ProtectionCheckImpl @@ -45,6 +48,7 @@ import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.maintenance.PrefFileListProvider import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.DefaultValueHelper +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.profiling.Profiler import info.nightscout.interfaces.protection.PasswordCheck import info.nightscout.interfaces.protection.ProtectionCheck @@ -68,7 +72,9 @@ import info.nightscout.shared.interfaces.ResourceHelper ) @Suppress("unused") -open class ImplementationModule { +abstract class ImplementationModule { + + @ContributesAndroidInjector abstract fun profileStoreInjector(): ProfileStoreObject @Module interface Bindings { @@ -88,6 +94,7 @@ open class ImplementationModule { @Binds fun bindWarnColors(warnColorsImpl: WarnColorsImpl): WarnColors @Binds fun bindHardLimits(hardLimitsImpl: HardLimitsImpl): HardLimits @Binds fun bindResourceHelper(resourceHelperImpl: ResourceHelperImpl): ResourceHelper + @Binds fun bindProfileStoreInstantiator(profileStoreInstantiatorImpl: ProfileInstantiatorImpl): ProfileInstantiator @Binds fun bindTrendCalculatorInterface(trendCalculator: TrendCalculatorImpl): TrendCalculator @Binds fun bindTddCalculatorInterface(tddCalculator: TddCalculatorImpl): TddCalculator diff --git a/implementation/src/main/java/info/nightscout/implementation/profile/ProfileInstantiatorImpl.kt b/implementation/src/main/java/info/nightscout/implementation/profile/ProfileInstantiatorImpl.kt new file mode 100644 index 0000000000..e801af2193 --- /dev/null +++ b/implementation/src/main/java/info/nightscout/implementation/profile/ProfileInstantiatorImpl.kt @@ -0,0 +1,17 @@ +package info.nightscout.implementation.profile + +import dagger.android.HasAndroidInjector +import info.nightscout.interfaces.profile.ProfileInstantiator +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.shared.utils.DateUtil +import org.json.JSONObject +import javax.inject.Inject + +class ProfileInstantiatorImpl @Inject constructor( + private val injector: HasAndroidInjector, + private val dateUtil: DateUtil +): ProfileInstantiator { + + override fun storeInstance(jsonObject: JSONObject): ProfileStore = + ProfileStoreObject(injector, jsonObject, dateUtil) +} \ No newline at end of file diff --git a/implementation/src/main/java/info/nightscout/implementation/profile/ProfileStoreObject.kt b/implementation/src/main/java/info/nightscout/implementation/profile/ProfileStoreObject.kt new file mode 100644 index 0000000000..df1e0e2321 --- /dev/null +++ b/implementation/src/main/java/info/nightscout/implementation/profile/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.implementation.profile + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 0cd5f61864..c61c03d0c6 100644 --- a/implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -5,10 +5,10 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.entities.EffectiveProfileSwitch import info.nightscout.database.entities.embedments.InsulinConfiguration +import info.nightscout.implementation.profile.ProfileStoreObject import info.nightscout.interfaces.Config import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/interfaces/src/main/java/info/nightscout/interfaces/profile/ProfileInstantiator.kt b/interfaces/src/main/java/info/nightscout/interfaces/profile/ProfileInstantiator.kt new file mode 100644 index 0000000000..6537cb1862 --- /dev/null +++ b/interfaces/src/main/java/info/nightscout/interfaces/profile/ProfileInstantiator.kt @@ -0,0 +1,7 @@ +package info.nightscout.interfaces.profile + +import org.json.JSONObject + +interface ProfileInstantiator { + fun storeInstance(jsonObject: JSONObject): ProfileStore +} \ No newline at end of file diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt index 930fa4a179..bc1e5d7fc8 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt @@ -19,18 +19,18 @@ import android.widget.TableRow import android.widget.TextView import dagger.android.HasAndroidInjector import dagger.android.support.DaggerFragment -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.profile.ProfileStore import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.interfaces.utils.MidnightTime @@ -70,6 +70,7 @@ class AutotuneFragment : DaggerFragment() { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var activityNames: ActivityNames + @Inject lateinit var profileInstantiator: ProfileInstantiator private var disposable: CompositeDisposable = CompositeDisposable() private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) @@ -96,7 +97,7 @@ class AutotuneFragment : DaggerFragment() { if (autotunePlugin.lastNbDays.isEmpty()) autotunePlugin.lastNbDays = sp.getInt(R.string.key_autotune_default_tune_days, 5).toString() val defaultValue = sp.getInt(R.string.key_autotune_default_tune_days, 5).toDouble() - profileStore = activePlugin.activeProfileSource.profile ?: ProfileStoreObject(injector, JSONObject(), dateUtil) + profileStore = activePlugin.activeProfileSource.profile ?: profileInstantiator.storeInstance(JSONObject()) profileName = if (binding.profileList.text.toString() == rh.gs(R.string.active)) "" else binding.profileList.text.toString() profileFunction.getProfile()?.let { currentProfile -> profile = ATProfile(profileStore.getSpecificProfile(profileName)?.let { ProfileSealed.Pure(it) } ?: currentProfile, LocalInsulin(""), injector) @@ -294,7 +295,7 @@ class AutotuneFragment : DaggerFragment() { @Synchronized private fun updateGui() { _binding ?: return - profileStore = activePlugin.activeProfileSource.profile ?: ProfileStoreObject(injector, JSONObject(), dateUtil) + profileStore = activePlugin.activeProfileSource.profile ?: profileInstantiator.storeInstance(JSONObject()) profileName = if (binding.profileList.text.toString() == rh.gs(R.string.active)) "" else binding.profileList.text.toString() profileFunction.getProfile()?.let { currentProfile -> profile = ATProfile(profileStore.getSpecificProfile(profileName)?.let { ProfileSealed.Pure(it) } ?: currentProfile, LocalInsulin(""), injector) diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt index cdd63c04f4..8c7516a613 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt @@ -3,20 +3,20 @@ package info.nightscout.plugins.general.autotune import android.view.View import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.ValueWithUnit import info.nightscout.interfaces.Config import info.nightscout.interfaces.autotune.Autotune import info.nightscout.interfaces.insulin.Insulin +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.interfaces.utils.MidnightTime import info.nightscout.plugins.aps.R @@ -60,7 +60,8 @@ class AutotunePlugin @Inject constructor( private val autotuneCore: AutotuneCore, private val config: Config, private val uel: UserEntryLogger, - aapsLogger: AAPSLogger + aapsLogger: AAPSLogger, + private val profileInstantiator: ProfileInstantiator ) : PluginBase( PluginDescription() .mainType(PluginType.GENERAL) @@ -324,7 +325,7 @@ class AutotunePlugin @Inject constructor( if (newProfile == null) return val profilePlugin = activePlugin.activeProfileSource val circadian = sp.getBoolean(R.string.key_autotune_circadian_ic_isf, false) - val profileStore = activePlugin.activeProfileSource.profile ?: ProfileStoreObject(injector, JSONObject(), dateUtil) + val profileStore = activePlugin.activeProfileSource.profile ?: profileInstantiator.storeInstance(JSONObject()) val profileList: ArrayList = profileStore.getProfileList() var indexLocalProfile = -1 for (p in profileList.indices) diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt index 2e3cd7a423..e4e649d41d 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt @@ -5,7 +5,6 @@ import info.nightscout.androidaps.extensions.blockValueBySeconds import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.main.R import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.MidnightUtils import info.nightscout.database.entities.data.Block import info.nightscout.interfaces.Config @@ -14,6 +13,7 @@ import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.profile.ProfileStore import info.nightscout.interfaces.profile.PureProfile import info.nightscout.interfaces.utils.Round @@ -39,6 +39,7 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: @Inject lateinit var config: Config @Inject lateinit var rxBus: RxBus @Inject lateinit var rh: ResourceHelper + @Inject lateinit var profileInstantiator: ProfileInstantiator var profile: ProfileSealed var circadianProfile: ProfileSealed @@ -179,7 +180,7 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: json.put("defaultProfile", profilename) json.put("store", store) json.put("startDate", dateUtil.toISOAsUTC(dateUtil.now())) - profileStore = ProfileStoreObject(injector, json, dateUtil) + profileStore = profileInstantiator.storeInstance(json) } catch (e: JSONException) { } return profileStore diff --git a/plugins/aps/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt b/plugins/aps/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt new file mode 100644 index 0000000000..297ebcc121 --- /dev/null +++ b/plugins/aps/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.androidaps + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/plugins/aps/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/plugins/aps/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 0cd5f61864..89a2d04cf7 100644 --- a/plugins/aps/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/plugins/aps/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -5,7 +5,6 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.entities.EffectiveProfileSwitch import info.nightscout.database.entities.embedments.InsulinConfiguration diff --git a/plugins/automation/src/main/java/info/nightscout/automation/AutomationFragment.kt b/plugins/automation/src/main/java/info/nightscout/automation/AutomationFragment.kt index 5e5f05a236..9e75ca7226 100644 --- a/plugins/automation/src/main/java/info/nightscout/automation/AutomationFragment.kt +++ b/plugins/automation/src/main/java/info/nightscout/automation/AutomationFragment.kt @@ -23,7 +23,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.android.HasAndroidInjector import dagger.android.support.DaggerFragment -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.automation.databinding.AutomationEventItemBinding import info.nightscout.automation.databinding.AutomationFragmentBinding import info.nightscout.automation.dialogs.EditEventDialog @@ -38,6 +37,7 @@ import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.interfaces.dragHelpers.ItemTouchHelperAdapter import info.nightscout.interfaces.dragHelpers.OnStartDragListener import info.nightscout.interfaces.dragHelpers.SimpleItemTouchHelperCallback +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.utils.HtmlHelper import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus @@ -212,7 +212,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener, MenuProvider { holder.binding.iconLayout.removeAllViews() // trigger icons val triggerIcons = HashSet() - if (automation.userAction) triggerIcons.add(R.drawable.ic_danar_useropt) + if (automation.userAction) triggerIcons.add(R.drawable.ic_user_options) fillIconSet(automation.trigger, triggerIcons) for (res in triggerIcons) { addImage(res, holder.context, holder.binding.iconLayout) diff --git a/plugins/automation/src/main/res/layout/automation_dialog_event.xml b/plugins/automation/src/main/res/layout/automation_dialog_event.xml index fb968f318c..92c7f1c12e 100644 --- a/plugins/automation/src/main/res/layout/automation_dialog_event.xml +++ b/plugins/automation/src/main/res/layout/automation_dialog_event.xml @@ -69,7 +69,7 @@ android:importantForAccessibility="no" android:scaleX="0.7" android:scaleY="0.7" - android:src="@drawable/ic_danar_useropt" /> + android:src="@drawable/ic_user_options" /> () + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/plugins/automation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/plugins/automation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 8c6455d623..4a848379cd 100644 --- a/plugins/automation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/plugins/automation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -4,7 +4,6 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config diff --git a/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt index 6e834fa254..792bd8dbb6 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt @@ -10,7 +10,6 @@ import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.extensions.blockFromJsonArray import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.receivers.DataWorkerStorage @@ -25,6 +24,7 @@ import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.profile.ProfileSource import info.nightscout.interfaces.profile.ProfileStore import info.nightscout.interfaces.profile.PureProfile @@ -59,7 +59,8 @@ class ProfilePlugin @Inject constructor( private val activePlugin: ActivePlugin, private val hardLimits: HardLimits, private val dateUtil: DateUtil, - private val config: Config + private val config: Config, + private val profileInstantiator: ProfileInstantiator ) : PluginBase( PluginDescription() .mainType(PluginType.PROFILE) @@ -73,7 +74,7 @@ class ProfilePlugin @Inject constructor( aapsLogger, rh, injector ), ProfileSource { - private var rawProfile: ProfileStoreObject? = null + private var rawProfile: ProfileStore? = null private val defaultArray = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]" @@ -389,7 +390,7 @@ class ProfilePlugin @Inject constructor( isEdited = false } - fun createProfileStore(): ProfileStoreObject { + fun createProfileStore(): ProfileStore { val json = JSONObject() val store = JSONObject() @@ -418,7 +419,7 @@ class ProfilePlugin @Inject constructor( aapsLogger.error("Unhandled exception", e) } - return ProfileStoreObject(injector, json, dateUtil) + return profileInstantiator.storeInstance(json) } override val profile: ProfileStore? @@ -444,6 +445,7 @@ class ProfilePlugin @Inject constructor( @Inject lateinit var config: Config @Inject lateinit var profilePlugin: ProfilePlugin @Inject lateinit var xDripBroadcast: XDripBroadcast + @Inject lateinit var profileInstantiator: ProfileInstantiator init { (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) @@ -454,7 +456,7 @@ class ProfilePlugin @Inject constructor( ?: return Result.failure(workDataOf("Error" to "missing input data")) xDripBroadcast.sendProfile(profileJson) if (sp.getBoolean(R.string.key_ns_receive_profile_store, true) || config.NSCLIENT) { - val store = ProfileStoreObject(injector, profileJson, dateUtil) + val store = profileInstantiator.storeInstance(profileJson) val createdAt = store.getStartDate() val lastLocalChange = sp.getLong(R.string.key_local_profile_last_change, 0) aapsLogger.debug(LTag.PROFILE, "Received profileStore: createdAt: $createdAt Local last modification: $lastLocalChange") diff --git a/plugins/main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt b/plugins/main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt new file mode 100644 index 0000000000..297ebcc121 --- /dev/null +++ b/plugins/main/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.androidaps + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/plugins/main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/plugins/main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 0cd5f61864..89a2d04cf7 100644 --- a/plugins/main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/plugins/main/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -5,7 +5,6 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.entities.EffectiveProfileSwitch import info.nightscout.database.entities.embedments.InsulinConfiguration diff --git a/pump/combov2/src/main/res/values/strings.xml b/pump/combov2/src/main/res/values/strings.xml index ac2ce2e97e..8f4fa37aaa 100644 --- a/pump/combov2/src/main/res/values/strings.xml +++ b/pump/combov2/src/main/res/values/strings.xml @@ -21,7 +21,7 @@ Reservoir error Infusion set not primed Extended bolus is not supported - Accu-Check Combo + Accu-Check Combo v2 Pair with pump Unpair pump Driver state diff --git a/pump/dana/build.gradle b/pump/dana/build.gradle index b5ce512315..f9a8287262 100644 --- a/pump/dana/build.gradle +++ b/pump/dana/build.gradle @@ -14,7 +14,7 @@ apply from: "${project.rootDir}/core/core-main/jacoco_global.gradle" android { - namespace 'info.nightscout.androidaps.dana' + namespace 'info.nightscout.pump.dana' defaultConfig { kapt { arguments { @@ -27,7 +27,7 @@ android { dependencies { implementation project(':libraries') - implementation project(':core:core-main') + implementation project(':core:ui') implementation project(':core:utils') implementation project(':app-wear-shared:rx') implementation project(':app-wear-shared:shared') @@ -36,7 +36,7 @@ dependencies { api "androidx.room:room-ktx:$room_version" api "androidx.room:room-runtime:$room_version" api "androidx.room:room-rxjava3:$room_version" - implementation project(path: ':core:ui') - implementation project(path: ':core:ui') kapt "androidx.room:room-compiler:$room_version" + + testImplementation project(':core:core-main') // create profile from json } \ No newline at end of file diff --git a/pump/dana/schemas/info.nightscout.pump.dana.database.DanaHistoryDatabase/1.json b/pump/dana/schemas/info.nightscout.pump.dana.database.DanaHistoryDatabase/1.json new file mode 100644 index 0000000000..e26c6961a5 --- /dev/null +++ b/pump/dana/schemas/info.nightscout.pump.dana.database.DanaHistoryDatabase/1.json @@ -0,0 +1,93 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "04f2e440fae2d62ca4e4a38840b5cf2f", + "entities": [ + { + "tableName": "danaHistory", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timestamp` INTEGER NOT NULL, `code` INTEGER NOT NULL, `value` REAL NOT NULL, `bolusType` TEXT NOT NULL, `stringValue` TEXT NOT NULL, `duration` INTEGER NOT NULL, `dailyBasal` REAL NOT NULL, `dailyBolus` REAL NOT NULL, `alarm` TEXT NOT NULL, PRIMARY KEY(`timestamp`))", + "fields": [ + { + "fieldPath": "timestamp", + "columnName": "timestamp", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "code", + "columnName": "code", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "bolusType", + "columnName": "bolusType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "stringValue", + "columnName": "stringValue", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "duration", + "columnName": "duration", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "dailyBasal", + "columnName": "dailyBasal", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "dailyBolus", + "columnName": "dailyBolus", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "alarm", + "columnName": "alarm", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "timestamp" + ], + "autoGenerate": false + }, + "indices": [ + { + "name": "index_danaHistory_code_timestamp", + "unique": false, + "columnNames": [ + "code", + "timestamp" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_danaHistory_code_timestamp` ON `${TABLE_NAME}` (`code`, `timestamp`)" + } + ], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '04f2e440fae2d62ca4e4a38840b5cf2f')" + ] + } +} \ No newline at end of file diff --git a/pump/dana/src/main/AndroidManifest.xml b/pump/dana/src/main/AndroidManifest.xml index 3960154ebf..75a041fc7a 100644 --- a/pump/dana/src/main/AndroidManifest.xml +++ b/pump/dana/src/main/AndroidManifest.xml @@ -2,12 +2,12 @@ + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/di/DanaModule.kt b/pump/dana/src/main/java/info/nightscout/androidaps/dana/di/DanaModule.kt deleted file mode 100644 index 472feef422..0000000000 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/di/DanaModule.kt +++ /dev/null @@ -1,22 +0,0 @@ -package info.nightscout.androidaps.dana.di - -import android.content.Context -import dagger.Module -import dagger.Provides -import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.dana.DanaFragment -import info.nightscout.androidaps.dana.activities.DanaHistoryActivity -import info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity -import info.nightscout.androidaps.dana.database.DanaHistoryDatabase -import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao -import javax.inject.Singleton - -@Module -@Suppress("unused") -abstract class DanaModule { - - @ContributesAndroidInjector abstract fun contributesDanaRFragment(): DanaFragment - @ContributesAndroidInjector abstract fun contributeDanaRHistoryActivity(): DanaHistoryActivity - @ContributesAndroidInjector abstract fun contributeDanaRUserOptionsActivity(): DanaUserOptionsActivity - -} \ No newline at end of file diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/DanaFragment.kt similarity index 92% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/DanaFragment.kt index afa433ac1c..79513653ac 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/DanaFragment.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dana +package info.nightscout.pump.dana import android.annotation.SuppressLint import android.content.Intent @@ -10,10 +10,6 @@ import android.view.View import android.view.ViewGroup import androidx.core.content.ContextCompat import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.dana.activities.DanaHistoryActivity -import info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity -import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding -import info.nightscout.androidaps.dana.events.EventDanaRNewStatus import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.logging.UserEntryLogger @@ -26,6 +22,10 @@ import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.interfaces.userEntry.UserEntryMapper.Action import info.nightscout.interfaces.userEntry.UserEntryMapper.Sources +import info.nightscout.pump.dana.activities.DanaHistoryActivity +import info.nightscout.pump.dana.activities.DanaUserOptionsActivity +import info.nightscout.pump.dana.databinding.DanarFragmentBinding +import info.nightscout.pump.dana.events.EventDanaRNewStatus import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventExtendedBolusChange @@ -207,26 +207,26 @@ class DanaFragment : DaggerFragment() { if (pump.lastConnection != 0L) { val agoMilliseconds = System.currentTimeMillis() - pump.lastConnection val agoMin = (agoMilliseconds.toDouble() / 60.0 / 1000.0).toInt() - binding.lastconnection.text = dateUtil.timeString(pump.lastConnection) + " (" + rh.gs(R.string.minago, agoMin) + ")" - warnColors.setColor(binding.lastconnection, agoMin.toDouble(), 16.0, 31.0) + binding.lastConnection.text = dateUtil.timeString(pump.lastConnection) + " (" + rh.gs(R.string.minago, agoMin) + ")" + warnColors.setColor(binding.lastConnection, agoMin.toDouble(), 16.0, 31.0) } if (pump.lastBolusTime != 0L) { val agoMilliseconds = System.currentTimeMillis() - pump.lastBolusTime val agoHours = agoMilliseconds.toDouble() / 60.0 / 60.0 / 1000.0 if (agoHours < 6) // max 6h back - binding.lastbolus.text = dateUtil.timeString(pump.lastBolusTime) + " " + dateUtil.sinceString(pump.lastBolusTime, rh) + " " + rh.gs(R.string.format_insulin_units, pump.lastBolusAmount) + binding.lastBolus.text = dateUtil.timeString(pump.lastBolusTime) + " " + dateUtil.sinceString(pump.lastBolusTime, rh) + " " + rh.gs(R.string.format_insulin_units, pump.lastBolusAmount) else - binding.lastbolus.text = "" + binding.lastBolus.text = "" } - binding.dailyunits.text = rh.gs(R.string.reservoirvalue, pump.dailyTotalUnits, pump.maxDailyTotalUnits) - warnColors.setColor(binding.dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9) - binding.basabasalrate.text = "( " + (pump.activeProfile + 1) + " ) " + rh.gs(R.string.pump_base_basal_rate, plugin.baseBasalRate) + binding.dailyUnits.text = rh.gs(R.string.reservoir_value, pump.dailyTotalUnits, pump.maxDailyTotalUnits) + warnColors.setColor(binding.dailyUnits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9) + binding.baseBasalRate.text = "( " + (pump.activeProfile + 1) + " ) " + rh.gs(R.string.pump_base_basal_rate, plugin.baseBasalRate) // DanaRPlugin, DanaRKoreanPlugin binding.tempbasal.text = danaPump.temporaryBasalToString() binding.extendedbolus.text = danaPump.extendedBolusToString() - binding.reservoir.text = rh.gs(R.string.reservoirvalue, pump.reservoirRemainingUnits, 300) + binding.reservoir.text = rh.gs(R.string.reservoir_value, pump.reservoirRemainingUnits, 300) warnColors.setColorInverse(binding.reservoir, pump.reservoirRemainingUnits, 50.0, 20.0) binding.battery.text = "{fa-battery-" + pump.batteryRemaining / 25 + "}" warnColors.setColorInverse(binding.battery, pump.batteryRemaining.toDouble(), 51.0, 26.0) diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaPump.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/DanaPump.kt similarity index 98% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaPump.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/DanaPump.kt index feff80d8fd..d4a6fb50d0 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaPump.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/DanaPump.kt @@ -1,9 +1,8 @@ -package info.nightscout.androidaps.dana +package info.nightscout.pump.dana -import dagger.android.HasAndroidInjector -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.interfaces.Constants import info.nightscout.interfaces.profile.Profile +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.profile.ProfileStore import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.defs.PumpType @@ -34,7 +33,7 @@ class DanaPump @Inject constructor( private val aapsLogger: AAPSLogger, private val sp: SP, private val dateUtil: DateUtil, - private val injector: HasAndroidInjector + private val profileInstantiator: ProfileInstantiator ) { @Suppress("unused") @@ -381,7 +380,7 @@ class DanaPump @Inject constructor( } catch (e: Exception) { return null } - return ProfileStoreObject(injector, json, dateUtil) + return profileInstantiator.storeInstance(json) } return null } diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaHistoryActivity.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/activities/DanaHistoryActivity.kt similarity index 94% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaHistoryActivity.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/activities/DanaHistoryActivity.kt index 5e1b85e9d3..869edf5538 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaHistoryActivity.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/activities/DanaHistoryActivity.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dana.activities +package info.nightscout.pump.dana.activities import android.os.Bundle import android.view.LayoutInflater @@ -8,13 +8,7 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import info.nightscout.androidaps.dana.R -import info.nightscout.androidaps.dana.comm.RecordTypes -import info.nightscout.androidaps.dana.database.DanaHistoryRecord -import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao -import info.nightscout.androidaps.dana.databinding.DanarHistoryActivityBinding -import info.nightscout.androidaps.dana.databinding.DanarHistoryItemBinding -import info.nightscout.core.activities.NoSplashAppCompatActivity +import dagger.android.support.DaggerAppCompatActivity import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Constants import info.nightscout.interfaces.plugin.ActivePlugin @@ -24,18 +18,30 @@ import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.utils.DecimalFormatter +import info.nightscout.pump.dana.R +import info.nightscout.pump.dana.comm.RecordTypes +import info.nightscout.pump.dana.database.DanaHistoryRecord +import info.nightscout.pump.dana.database.DanaHistoryRecordDao +import info.nightscout.pump.dana.databinding.DanarHistoryActivityBinding +import info.nightscout.pump.dana.databinding.DanarHistoryItemBinding import info.nightscout.rx.AapsSchedulers +import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventDanaRSyncStatus import info.nightscout.rx.events.EventPumpStatusChanged +import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag +import info.nightscout.shared.interfaces.ResourceHelper 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 javax.inject.Inject -class DanaHistoryActivity : NoSplashAppCompatActivity() { +class DanaHistoryActivity : DaggerAppCompatActivity() { + @Inject lateinit var rxBus: RxBus + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var activePlugin: ActivePlugin @@ -80,7 +86,6 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() { super.onCreate(savedInstanceState) binding = DanarHistoryActivityBinding.inflate(layoutInflater) setContentView(binding.root) - setTheme(R.style.AppTheme) binding.recyclerview.setHasFixedSize(true) binding.recyclerview.layoutManager = LinearLayoutManager(this) diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/activities/DanaUserOptionsActivity.kt similarity index 74% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/activities/DanaUserOptionsActivity.kt index 8e03f3ad4f..0126e80289 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/activities/DanaUserOptionsActivity.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/activities/DanaUserOptionsActivity.kt @@ -1,11 +1,8 @@ -package info.nightscout.androidaps.dana.activities +package info.nightscout.pump.dana.activities import android.content.Context import android.os.Bundle -import info.nightscout.androidaps.dana.DanaPump -import info.nightscout.androidaps.dana.R -import info.nightscout.androidaps.dana.databinding.DanarUserOptionsActivityBinding -import info.nightscout.core.activities.NoSplashAppCompatActivity +import dagger.android.support.DaggerAppCompatActivity import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Constants import info.nightscout.interfaces.plugin.ActivePlugin @@ -13,9 +10,15 @@ import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.ui.ActivityNames +import info.nightscout.pump.dana.DanaPump +import info.nightscout.pump.dana.R +import info.nightscout.pump.dana.databinding.DanarUserOptionsActivityBinding import info.nightscout.rx.AapsSchedulers +import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventInitializationChanged +import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag +import info.nightscout.shared.interfaces.ResourceHelper import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.text.DecimalFormat @@ -23,8 +26,11 @@ import javax.inject.Inject import kotlin.math.max import kotlin.math.min -class DanaUserOptionsActivity : NoSplashAppCompatActivity() { +class DanaUserOptionsActivity : DaggerAppCompatActivity() { + @Inject lateinit var rxBus: RxBus + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var rh: ResourceHelper @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var context: Context @Inject lateinit var danaPump: DanaPump @@ -40,7 +46,7 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { private fun isDanaR() = activePlugin.activePump.pumpDescription.pumpType == PumpType.DANA_R private fun isDanaRv2() = activePlugin.activePump.pumpDescription.pumpType == PumpType.DANA_RV2 - var minBacklight = 1 + private var minBacklight = 1 private lateinit var binding: DanarUserOptionsActivityBinding @@ -80,27 +86,27 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { + "\nlowReservoir:" + danaPump.lowReservoirRate ) - binding.screentimeout.setParams(danaPump.lcdOnTimeSec.toDouble(), 5.0, 240.0, 5.0, DecimalFormat("1"), false, binding.saveUserOptions) + binding.screenTimeout.setParams(danaPump.lcdOnTimeSec.toDouble(), 5.0, 240.0, 5.0, DecimalFormat("1"), false, binding.saveUserOptions) binding.backlight.setParams(danaPump.backlightOnTimeSec.toDouble(), minBacklight.toDouble(), 60.0, 1.0, DecimalFormat("1"), false, binding.saveUserOptions) binding.shutdown.setParams(danaPump.shutdownHour.toDouble(), 0.0, 24.0, 1.0, DecimalFormat("1"), true, binding.saveUserOptions) - binding.lowreservoir.setParams(danaPump.lowReservoirRate.toDouble(), 10.0, 50.0, 10.0, DecimalFormat("10"), false, binding.saveUserOptions) + binding.lowReservoir.setParams(danaPump.lowReservoirRate.toDouble(), 10.0, 50.0, 10.0, DecimalFormat("10"), false, binding.saveUserOptions) when (danaPump.beepAndAlarm) { - 0b01 -> binding.pumpalarmSound.isChecked = true - 0b10 -> binding.pumpalarmVibrate.isChecked = true - 0b11 -> binding.pumpalarmBoth.isChecked = true + 0b01 -> binding.pumpAlarmSound.isChecked = true + 0b10 -> binding.pumpAlarmVibrate.isChecked = true + 0b11 -> binding.pumpAlarmBoth.isChecked = true 0b101 -> { - binding.pumpalarmSound.isChecked = true + binding.pumpAlarmSound.isChecked = true binding.beep.isChecked = true } 0b110 -> { - binding.pumpalarmVibrate.isChecked = true + binding.pumpAlarmVibrate.isChecked = true binding.beep.isChecked = true } 0b111 -> { - binding.pumpalarmBoth.isChecked = true + binding.pumpAlarmBoth.isChecked = true binding.beep.isChecked = true } } @@ -110,35 +116,35 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { setData() } - fun setData() { + private fun setData() { // in DanaRS timeDisplay values are reversed - binding.timeformat.isChecked = danaPump.timeDisplayType24 - binding.buttonscroll.isChecked = danaPump.buttonScrollOnOff + binding.timeFormat.isChecked = danaPump.timeDisplayType24 + binding.buttonScroll.isChecked = danaPump.buttonScrollOnOff binding.beep.isChecked = danaPump.beepAndAlarm > 4 - binding.screentimeout.value = danaPump.lcdOnTimeSec.toDouble() + binding.screenTimeout.value = danaPump.lcdOnTimeSec.toDouble() binding.backlight.value = danaPump.backlightOnTimeSec.toDouble() binding.units.isChecked = danaPump.getUnits() == Constants.MMOL binding.shutdown.value = danaPump.shutdownHour.toDouble() - binding.lowreservoir.value = danaPump.lowReservoirRate.toDouble() + binding.lowReservoir.value = danaPump.lowReservoirRate.toDouble() } private fun onSaveClick() { //exit if pump is not DanaRS, DanaR, or DanaR with upgraded firmware if (!isRS() && !isDanaR() && !isDanaRv2()) return - danaPump.timeDisplayType24 = binding.timeformat.isChecked + danaPump.timeDisplayType24 = binding.timeFormat.isChecked - danaPump.buttonScrollOnOff = binding.buttonscroll.isChecked + danaPump.buttonScrollOnOff = binding.buttonScroll.isChecked danaPump.beepAndAlarm = when { - binding.pumpalarmSound.isChecked -> 1 - binding.pumpalarmVibrate.isChecked -> 2 - binding.pumpalarmBoth.isChecked -> 3 + binding.pumpAlarmSound.isChecked -> 1 + binding.pumpAlarmVibrate.isChecked -> 2 + binding.pumpAlarmBoth.isChecked -> 3 else -> 1 } if (binding.beep.isChecked) danaPump.beepAndAlarm += 4 // step is 5 seconds, 5 to 240 - danaPump.lcdOnTimeSec = min(max(binding.screentimeout.value.toInt() / 5 * 5, 5), 240) + danaPump.lcdOnTimeSec = min(max(binding.screenTimeout.value.toInt() / 5 * 5, 5), 240) // 1 to 60 danaPump.backlightOnTimeSec = min(max(binding.backlight.value.toInt(), minBacklight), 60) @@ -147,7 +153,7 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() { danaPump.shutdownHour = min(binding.shutdown.value.toInt(), 24) // 10 to 50 - danaPump.lowReservoirRate = min(max(binding.lowreservoir.value.toInt() * 10 / 10, 10), 50) + danaPump.lowReservoirRate = min(max(binding.lowReservoir.value.toInt() * 10 / 10, 10), 50) commandQueue.setUserOptions(object : Callback() { override fun run() { diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/comm/RecordTypes.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/comm/RecordTypes.kt similarity index 93% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/comm/RecordTypes.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/comm/RecordTypes.kt index 30ba45483e..6916807174 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/comm/RecordTypes.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/comm/RecordTypes.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dana.comm +package info.nightscout.pump.dana.comm object RecordTypes { const val RECORD_TYPE_BOLUS = 0x01.toByte() diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryDatabase.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryDatabase.kt similarity index 89% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryDatabase.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryDatabase.kt index f04779c4ec..51d3fd4ae5 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryDatabase.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryDatabase.kt @@ -1,10 +1,9 @@ -package info.nightscout.androidaps.dana.database +package info.nightscout.pump.dana.database import android.content.Context import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase -import androidx.room.TypeConverters const val TABLE_DANA_HISTORY = "danaHistory" diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryRecord.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryRecord.kt similarity index 82% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryRecord.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryRecord.kt index 8aaf3e32f4..525c26f064 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryRecord.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryRecord.kt @@ -1,11 +1,11 @@ -package info.nightscout.androidaps.dana.database +package info.nightscout.pump.dana.database import androidx.room.Entity import androidx.room.Index import androidx.room.PrimaryKey @Entity(tableName = TABLE_DANA_HISTORY, - indices = [Index("code", "timestamp")]) + indices = [Index("code", "timestamp")]) data class DanaHistoryRecord( @PrimaryKey var timestamp: Long, var code: Byte = 0x0F, diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryRecordDao.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryRecordDao.kt similarity index 91% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryRecordDao.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryRecordDao.kt index d7773b56c6..6a4f1ec1c5 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/database/DanaHistoryRecordDao.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/database/DanaHistoryRecordDao.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dana.database +package info.nightscout.pump.dana.database import androidx.room.Dao import androidx.room.Insert diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/di/DanaHistoryModule.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/di/DanaHistoryModule.kt similarity index 72% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/di/DanaHistoryModule.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/di/DanaHistoryModule.kt index 1d52df3139..1c63597a1c 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/di/DanaHistoryModule.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/di/DanaHistoryModule.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.dana.di +package info.nightscout.pump.dana.di import android.content.Context import dagger.Module import dagger.Provides -import info.nightscout.androidaps.dana.database.DanaHistoryDatabase -import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao +import info.nightscout.pump.dana.database.DanaHistoryDatabase +import info.nightscout.pump.dana.database.DanaHistoryRecordDao import javax.inject.Singleton @Module diff --git a/pump/dana/src/main/java/info/nightscout/pump/dana/di/DanaModule.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/di/DanaModule.kt new file mode 100644 index 0000000000..fb0273a716 --- /dev/null +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/di/DanaModule.kt @@ -0,0 +1,17 @@ +package info.nightscout.pump.dana.di + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import info.nightscout.pump.dana.DanaFragment +import info.nightscout.pump.dana.activities.DanaHistoryActivity +import info.nightscout.pump.dana.activities.DanaUserOptionsActivity + +@Module +@Suppress("unused") +abstract class DanaModule { + + @ContributesAndroidInjector abstract fun contributesDanaRFragment(): DanaFragment + @ContributesAndroidInjector abstract fun contributeDanaRHistoryActivity(): DanaHistoryActivity + @ContributesAndroidInjector abstract fun contributeDanaRUserOptionsActivity(): DanaUserOptionsActivity + +} \ No newline at end of file diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/events/EventDanaRNewStatus.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/events/EventDanaRNewStatus.kt similarity index 62% rename from pump/dana/src/main/java/info/nightscout/androidaps/dana/events/EventDanaRNewStatus.kt rename to pump/dana/src/main/java/info/nightscout/pump/dana/events/EventDanaRNewStatus.kt index 2471a59e66..8299ddc351 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/events/EventDanaRNewStatus.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/events/EventDanaRNewStatus.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dana.events +package info.nightscout.pump.dana.events import info.nightscout.rx.events.Event diff --git a/core/core-main/src/main/res/drawable/ic_danarprofile.xml b/pump/dana/src/main/res/drawable/ic_dana_profile.xml similarity index 100% rename from core/core-main/src/main/res/drawable/ic_danarprofile.xml rename to pump/dana/src/main/res/drawable/ic_dana_profile.xml diff --git a/pump/dana/src/main/res/layout/danar_fragment.xml b/pump/dana/src/main/res/layout/danar_fragment.xml index 13dd0f5a70..3667cdbef6 100644 --- a/pump/dana/src/main/res/layout/danar_fragment.xml +++ b/pump/dana/src/main/res/layout/danar_fragment.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context="info.nightscout.androidaps.dana.DanaFragment"> + tools:context="info.nightscout.pump.dana.DanaFragment"> @@ -289,7 +289,7 @@ tools:ignore="HardcodedText" /> @@ -667,10 +667,10 @@ android:layout_height="match_parent" android:layout_marginEnd="-2dp" android:layout_weight="1" - android:drawableTop="@drawable/ic_danarprofile" + android:drawableTop="@drawable/ic_dana_profile" android:ellipsize="end" android:maxLines="2" - android:text="@string/viewprofile" + android:text="@string/view_profile" app:iconPadding="-4dp" /> @@ -694,7 +694,7 @@ android:layout_height="match_parent" android:layout_marginEnd="-2dp" android:layout_weight="1" - android:drawableTop="@drawable/ic_danarstats" + android:drawableTop="@drawable/ic_stats" android:ellipsize="end" android:maxLines="2" android:text="@string/stats" @@ -707,10 +707,10 @@ android:layout_height="match_parent" android:layout_marginEnd="-2dp" android:layout_weight="1" - android:drawableTop="@drawable/ic_danar_useropt" + android:drawableTop="@drawable/ic_user_options" android:ellipsize="end" android:maxLines="2" - android:text="@string/danar_useroptions" + android:text="@string/danar_user_options" app:iconPadding="-4dp" /> diff --git a/pump/dana/src/main/res/layout/danar_history_activity.xml b/pump/dana/src/main/res/layout/danar_history_activity.xml index 726ba70805..91fab97d1d 100644 --- a/pump/dana/src/main/res/layout/danar_history_activity.xml +++ b/pump/dana/src/main/res/layout/danar_history_activity.xml @@ -6,7 +6,7 @@ android:id="@+id/relativeLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" - tools:context="info.nightscout.androidaps.dana.activities.DanaHistoryActivity"> + tools:context="info.nightscout.pump.dana.activities.DanaHistoryActivity"> + tools:context="info.nightscout.pump.dana.activities.DanaUserOptionsActivity"> + app:srcCompat="@drawable/ic_user_options" /> @@ -120,33 +120,33 @@ android:layout_height="wrap_content" android:layout_weight="1" android:gravity="start" - android:text="@string/danar_pumpalarm" + android:text="@string/danar_pump_alarm" android:textSize="14sp" /> + android:text="@string/danar_pump_alarm_sound" /> + android:text="@string/danar_pump_alarm_vibrate" /> + android:text="@string/danar_pump_alarm_both" /> @@ -174,11 +174,11 @@ android:layout_height="wrap_content" android:layout_weight="1" android:gravity="top" - android:text="@string/danar_screentimeout" + android:text="@string/danar_screen_timeout" android:textSize="14sp" /> @@ -304,11 +304,11 @@ android:layout_height="wrap_content" android:layout_weight="1" android:gravity="start" - android:text="@string/danar_lowreservoir" + android:text="@string/danar_low_reservoir" android:textSize="14sp" /> + android:text="@string/danar_save_user_options" /> diff --git a/pump/dana/src/main/res/values/strings.xml b/pump/dana/src/main/res/values/strings.xml index 5f4fc453f8..43f77f0459 100644 --- a/pump/dana/src/main/res/values/strings.xml +++ b/pump/dana/src/main/res/values/strings.xml @@ -80,20 +80,20 @@ Refill Suspend Prime - User options - Display time format - Button scroll + User options + Display time format + Button scroll Beep on button press - Alarm - Sound - Vibrate - Both - LCD on time [seconds] + Alarm + Sound + Vibrate + Both + LCD on time [seconds] Backlight on time [seconds] - Glucose units + Glucose units Shutdown [hours] - Low reservoir [Units] - Save options to pump + Low reservoir [Units] + Save options to pump Pump integration for DANA Diabecare R pumps Pump integration for domestic DANA Diabecare R pumps Pump integration for DANA Diabecare R pumps with upgraded firmware @@ -109,10 +109,10 @@ Setting of basal profile failed Bluetooth status Pump IOB - Firmware + Firmware Dana pump settings - 12h - 24h + 12h + 24h On Off DanaR Bluetooth device diff --git a/pump/dana/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt b/pump/dana/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt new file mode 100644 index 0000000000..297ebcc121 --- /dev/null +++ b/pump/dana/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.androidaps + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/pump/dana/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/pump/dana/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index e81c8c3bfa..2d4a3e662b 100644 --- a/pump/dana/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/pump/dana/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -2,14 +2,10 @@ package info.nightscout.androidaps import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.extensions.pureProfileFromJson -import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.DefaultValueHelper -import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profile.ProfileStore import info.nightscout.rx.bus.RxBus @@ -38,7 +34,6 @@ open class TestBaseWithProfile : TestBase() { } private lateinit var validProfileJSON: String - lateinit var validProfile: Profile @Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Before @@ -46,7 +41,6 @@ open class TestBaseWithProfile : TestBase() { validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + "\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}" - validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!) } fun getValidProfileStore(): ProfileStore { diff --git a/pump/dana/src/test/java/info/nightscout/androidaps/dana/DanaPumpTest.kt b/pump/dana/src/test/java/info/nightscout/androidaps/dana/DanaPumpTest.kt index 22a4591945..70ede295c5 100644 --- a/pump/dana/src/test/java/info/nightscout/androidaps/dana/DanaPumpTest.kt +++ b/pump/dana/src/test/java/info/nightscout/androidaps/dana/DanaPumpTest.kt @@ -1,6 +1,8 @@ package info.nightscout.androidaps.dana import info.nightscout.androidaps.TestBaseWithProfile +import info.nightscout.interfaces.profile.ProfileInstantiator +import info.nightscout.pump.dana.DanaPump import info.nightscout.shared.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -10,12 +12,13 @@ import org.mockito.Mock class DanaPumpTest : TestBaseWithProfile() { @Mock lateinit var sp: SP + @Mock lateinit var profileInstantiator: ProfileInstantiator private lateinit var sut: DanaPump @Before fun setup() { - sut = DanaPump(aapsLogger, sp, dateUtil, profileInjector) + sut = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator) } @Test diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt index ab60356634..849d45fe89 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.kt @@ -6,7 +6,6 @@ import android.content.Intent import android.content.ServiceConnection import android.os.IBinder import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danaRKorean.services.DanaRKoreanExecutionService import info.nightscout.androidaps.danar.AbstractDanaRPlugin import info.nightscout.androidaps.danar.R @@ -22,6 +21,7 @@ import info.nightscout.interfaces.pump.PumpSync.TemporaryBasalType import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.utils.Round +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventAppExit diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/comm/MsgCheckValue_k.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/comm/MsgCheckValue_k.kt index 5f8f322d97..106a18e897 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/comm/MsgCheckValue_k.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/comm/MsgCheckValue_k.kt @@ -1,11 +1,10 @@ package info.nightscout.androidaps.danaRKorean.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MessageBase +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag - class MsgCheckValue_k( injector: HasAndroidInjector ) : MessageBase(injector) { diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java index 4b1e1f00b8..1b6e76c0e4 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRKorean/services/DanaRKoreanExecutionService.java @@ -8,8 +8,6 @@ import java.io.IOException; import javax.inject.Inject; -import info.nightscout.androidaps.dana.DanaPump; -import info.nightscout.androidaps.dana.events.EventDanaRNewStatus; import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.danaRKorean.comm.MessageHashTableRKorean; import info.nightscout.androidaps.danaRKorean.comm.MsgCheckValue_k; @@ -49,6 +47,8 @@ import info.nightscout.interfaces.pump.PumpSync; import info.nightscout.interfaces.pump.defs.PumpType; import info.nightscout.interfaces.queue.Command; import info.nightscout.interfaces.queue.CommandQueue; +import info.nightscout.pump.dana.DanaPump; +import info.nightscout.pump.dana.events.EventDanaRNewStatus; import info.nightscout.rx.bus.RxBus; import info.nightscout.rx.events.EventInitializationChanged; import info.nightscout.rx.events.EventOverviewBolusProgress; diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index 6c8b26b84a..1d46aedf8b 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -12,7 +12,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.dana.DanaPump; import info.nightscout.androidaps.danaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.danar.AbstractDanaRPlugin; import info.nightscout.androidaps.danar.R; @@ -29,6 +28,7 @@ import info.nightscout.interfaces.pump.TemporaryBasalStorage; import info.nightscout.interfaces.pump.defs.PumpType; import info.nightscout.interfaces.queue.CommandQueue; import info.nightscout.interfaces.utils.Round; +import info.nightscout.pump.dana.DanaPump; import info.nightscout.rx.AapsSchedulers; import info.nightscout.rx.bus.RxBus; import info.nightscout.rx.events.EventAppExit; diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgCheckValue_v2.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgCheckValue_v2.kt index 9903e1c241..3bfd971e97 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgCheckValue_v2.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgCheckValue_v2.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.danaRv2.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.danar.comm.MessageBase import info.nightscout.core.events.EventNewNotification import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.PluginType +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.events.EventRebuildTabs import info.nightscout.rx.logging.LTag diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEventsV2.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEventsV2.kt index d2d9fad9a6..1dc28add9e 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEventsV2.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEventsV2.kt @@ -1,10 +1,10 @@ package info.nightscout.androidaps.danaRv2.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.danar.comm.MessageBase import info.nightscout.interfaces.pump.defs.PumpType +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.events.EventPumpStatusChanged import info.nightscout.rx.logging.LTag import info.nightscout.shared.utils.T diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java index 64bc02fc51..cbe0c81303 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java @@ -10,8 +10,6 @@ import java.io.IOException; import javax.inject.Inject; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.dana.DanaPump; -import info.nightscout.androidaps.dana.events.EventDanaRNewStatus; import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.danaRv2.DanaRv2Plugin; import info.nightscout.androidaps.danaRv2.comm.MessageHashTableRv2; @@ -63,6 +61,8 @@ import info.nightscout.interfaces.queue.Callback; import info.nightscout.interfaces.queue.Command; import info.nightscout.interfaces.queue.CommandQueue; import info.nightscout.interfaces.ui.ActivityNames; +import info.nightscout.pump.dana.DanaPump; +import info.nightscout.pump.dana.events.EventDanaRNewStatus; import info.nightscout.rx.bus.RxBus; import info.nightscout.rx.events.EventInitializationChanged; import info.nightscout.rx.events.EventOverviewBolusProgress; diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java index 61c1e23fe1..6d2b191203 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java @@ -6,9 +6,6 @@ import org.json.JSONException; import org.json.JSONObject; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.dana.DanaFragment; -import info.nightscout.androidaps.dana.DanaPump; -import info.nightscout.androidaps.dana.comm.RecordTypes; import info.nightscout.androidaps.danar.services.AbstractDanaRExecutionService; import info.nightscout.core.events.EventNewNotification; import info.nightscout.interfaces.constraints.Constraint; @@ -28,6 +25,9 @@ import info.nightscout.interfaces.pump.defs.PumpDescription; import info.nightscout.interfaces.queue.CommandQueue; import info.nightscout.interfaces.utils.DecimalFormatter; import info.nightscout.interfaces.utils.Round; +import info.nightscout.pump.dana.DanaFragment; +import info.nightscout.pump.dana.DanaPump; +import info.nightscout.pump.dana.comm.RecordTypes; import info.nightscout.rx.AapsSchedulers; import info.nightscout.rx.bus.RxBus; import info.nightscout.rx.events.EventConfigBuilderChange; diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java index 6d61fcecaa..fe700c9555 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java @@ -12,7 +12,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.dana.DanaPump; import info.nightscout.androidaps.danar.services.DanaRExecutionService; import info.nightscout.core.utils.fabric.FabricPrivacy; import info.nightscout.interfaces.constraints.Constraint; @@ -25,6 +24,7 @@ import info.nightscout.interfaces.pump.PumpSync; import info.nightscout.interfaces.pump.defs.PumpType; import info.nightscout.interfaces.queue.CommandQueue; import info.nightscout.interfaces.utils.Round; +import info.nightscout.pump.dana.DanaPump; import info.nightscout.rx.AapsSchedulers; import info.nightscout.rx.bus.RxBus; import info.nightscout.rx.events.EventAppExit; diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/SerialIOThread.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/SerialIOThread.java index bd2cdb7168..c4701bcbc4 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/SerialIOThread.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/SerialIOThread.java @@ -7,10 +7,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import info.nightscout.androidaps.dana.DanaPump; import info.nightscout.androidaps.danar.comm.MessageBase; import info.nightscout.androidaps.danar.comm.MessageHashTableBase; import info.nightscout.androidaps.utils.CRC; +import info.nightscout.pump.dana.DanaPump; import info.nightscout.rx.logging.AAPSLogger; import info.nightscout.rx.logging.LTag; diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MessageBase.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MessageBase.kt index ae182ed3b3..f8c60e9035 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MessageBase.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MessageBase.kt @@ -1,8 +1,6 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump -import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.danar.DanaRPlugin @@ -15,6 +13,8 @@ import info.nightscout.interfaces.pump.DetailedBolusInfoStorage import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.TemporaryBasalStorage import info.nightscout.interfaces.queue.CommandQueue +import info.nightscout.pump.dana.DanaPump +import info.nightscout.pump.dana.database.DanaHistoryRecordDao import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgCheckValue.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgCheckValue.kt index 3aef5c1e38..ccad02b8a9 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgCheckValue.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgCheckValue.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgHistoryAll.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgHistoryAll.kt index d72e00886b..b7948f9605 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgHistoryAll.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgHistoryAll.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.comm.RecordTypes -import info.nightscout.androidaps.dana.database.DanaHistoryRecord -import info.nightscout.shared.utils.T +import info.nightscout.pump.dana.comm.RecordTypes +import info.nightscout.pump.dana.database.DanaHistoryRecord import info.nightscout.rx.events.EventDanaRSyncStatus import info.nightscout.rx.logging.LTag +import info.nightscout.shared.utils.T open class MsgHistoryAll( injector: HasAndroidInjector diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt index 57924b2432..c80c16cb69 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgInitConnStatusBasic.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag @@ -32,10 +33,10 @@ class MsgInitConnStatusBasic( val extendedBolusRate = intFromBuff(bytes, 18, 2) / 100.0 danaPump.batteryRemaining = intFromBuff(bytes, 20, 1) val bolusConfig = intFromBuff(bytes, 21, 1) - val deliveryPrime = bolusConfig and info.nightscout.androidaps.dana.DanaPump.DELIVERY_PRIME != 0 - val deliveryStepBolus = bolusConfig and info.nightscout.androidaps.dana.DanaPump.DELIVERY_STEP_BOLUS != 0 - val deliveryBasal = bolusConfig and info.nightscout.androidaps.dana.DanaPump.DELIVERY_BASAL != 0 - val deliveryExtBolus = bolusConfig and info.nightscout.androidaps.dana.DanaPump.DELIVERY_EXT_BOLUS != 0 + val deliveryPrime = bolusConfig and DanaPump.DELIVERY_PRIME != 0 + val deliveryStepBolus = bolusConfig and DanaPump.DELIVERY_STEP_BOLUS != 0 + val deliveryBasal = bolusConfig and DanaPump.DELIVERY_BASAL != 0 + val deliveryExtBolus = bolusConfig and DanaPump.DELIVERY_EXT_BOLUS != 0 aapsLogger.debug(LTag.PUMPCOMM, "Delivery prime: $deliveryPrime") aapsLogger.debug(LTag.PUMPCOMM, "Delivery step bolus: $deliveryStepBolus") aapsLogger.debug(LTag.PUMPCOMM, "Delivery basal: $deliveryBasal") diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetCarbsEntry.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetCarbsEntry.kt index ffb0301551..90e5334ab8 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetCarbsEntry.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSetCarbsEntry.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector +import info.nightscout.pump.dana.comm.RecordTypes import info.nightscout.rx.logging.LTag import java.util.Calendar @@ -15,7 +16,7 @@ class MsgSetCarbsEntry( aapsLogger.debug(LTag.PUMPBTCOMM, "New message") val calendar = Calendar.getInstance() calendar.timeInMillis = time - addParamByte(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO) + addParamByte(RecordTypes.RECORD_TYPE_CARBO) addParamByte((calendar[Calendar.YEAR] % 100).toByte()) addParamByte((calendar[Calendar.MONTH] + 1).toByte()) addParamByte(calendar[Calendar.DAY_OF_MONTH].toByte()) diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingGlucose.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingGlucose.kt index 89f0fb65ce..cf27919ffe 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingGlucose.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingGlucose.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatios.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatios.kt index 3698d1a48b..0f230f6b4b 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatios.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatios.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatiosAll.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatiosAll.kt index dccf7b9237..aa962c4916 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatiosAll.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgSettingProfileRatiosAll.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusProfile.kt b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusProfile.kt index 9b352de990..9bbf0129e7 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusProfile.kt +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/comm/MsgStatusProfile.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.danar.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java index 73dd41e909..a35e4af4d1 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java @@ -22,8 +22,6 @@ import javax.inject.Inject; import dagger.android.DaggerService; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.dana.DanaPump; -import info.nightscout.androidaps.dana.comm.RecordTypes; import info.nightscout.androidaps.danar.R; import info.nightscout.androidaps.danar.SerialIOThread; import info.nightscout.androidaps.danar.comm.MessageBase; @@ -47,6 +45,8 @@ import info.nightscout.interfaces.plugin.ActivePlugin; import info.nightscout.interfaces.profile.Profile; import info.nightscout.interfaces.pump.PumpEnactResult; import info.nightscout.interfaces.pump.PumpSync; +import info.nightscout.pump.dana.DanaPump; +import info.nightscout.pump.dana.comm.RecordTypes; import info.nightscout.rx.AapsSchedulers; import info.nightscout.rx.bus.RxBus; import info.nightscout.rx.events.EventAppExit; diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java b/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java index b30143f867..ac17b6270b 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danar/services/DanaRExecutionService.java @@ -9,8 +9,6 @@ import java.io.IOException; import javax.inject.Inject; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.dana.DanaPump; -import info.nightscout.androidaps.dana.events.EventDanaRNewStatus; import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.danar.DanaRPlugin; import info.nightscout.androidaps.danar.R; @@ -55,6 +53,8 @@ import info.nightscout.interfaces.pump.defs.PumpType; import info.nightscout.interfaces.queue.Callback; import info.nightscout.interfaces.queue.Command; import info.nightscout.interfaces.queue.CommandQueue; +import info.nightscout.pump.dana.DanaPump; +import info.nightscout.pump.dana.events.EventDanaRNewStatus; import info.nightscout.rx.bus.RxBus; import info.nightscout.rx.events.EventInitializationChanged; import info.nightscout.rx.events.EventOverviewBolusProgress; diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt b/pump/danar/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt new file mode 100644 index 0000000000..297ebcc121 --- /dev/null +++ b/pump/danar/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.androidaps + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/pump/danar/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index e6e4304fcb..214f7f2fa9 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -5,7 +5,6 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Config import info.nightscout.interfaces.iob.IobCobCalculator diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt index 7a62d2864d..28151aa228 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt @@ -3,15 +3,16 @@ package info.nightscout.androidaps.plugins.pump.danaR import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.DanaRPlugin import info.nightscout.androidaps.danar.R import info.nightscout.interfaces.Constants import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.PluginType +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.queue.CommandQueue +import info.nightscout.pump.dana.DanaPump import info.nightscout.shared.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -25,6 +26,7 @@ class DanaRPluginTest : TestBaseWithProfile() { @Mock lateinit var sp: SP @Mock lateinit var commandQueue: CommandQueue @Mock lateinit var pumpSync: PumpSync + @Mock lateinit var profileInstantiator: ProfileInstantiator lateinit var danaPump: DanaPump @@ -41,7 +43,7 @@ class DanaRPluginTest : TestBaseWithProfile() { `when`(rh.gs(R.string.itmustbepositivevalue)).thenReturn("it must be positive value") `when`(rh.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(rh.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") - danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) + danaPump = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator) danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync) } diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt index 1b8a51b3d3..7122911f46 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/DanaRTestBase.kt @@ -4,8 +4,6 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestPumpPlugin -import info.nightscout.androidaps.dana.DanaPump -import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.danar.DanaRPlugin @@ -14,9 +12,12 @@ import info.nightscout.interfaces.ConfigBuilder import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.ProfileFunction +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.pump.DetailedBolusInfoStorage import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.queue.CommandQueue +import info.nightscout.pump.dana.DanaPump +import info.nightscout.pump.dana.database.DanaHistoryRecordDao import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -44,12 +45,13 @@ open class DanaRTestBase : TestBase() { @Mock lateinit var constraintChecker: Constraints @Mock lateinit var pumpSync: PumpSync @Mock lateinit var danaHistoryRecordDao: DanaHistoryRecordDao + @Mock lateinit var profileInstantiator: ProfileInstantiator private lateinit var testPumpPlugin: TestPumpPlugin @Before fun setup() { - danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) + danaPump = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator) testPumpPlugin = TestPumpPlugin(injector) `when`(activePlugin.activePump).thenReturn(testPumpPlugin) doNothing().`when`(danaRKoreanPlugin).setPluginEnabled(anyObject(), anyBoolean()) diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt index f44be2f968..c47b182fe7 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgCheckValueTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MsgCheckValue +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAllTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAllTest.kt index fb0a54b21f..98b063c59b 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAllTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosAllTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MsgSettingProfileRatiosAll +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosTest.kt index 7bffd88b0c..26de1b98f7 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingProfileRatiosTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MsgSettingProfileRatios +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt index 6c8358e203..6fbd695660 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingPumpTimeTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MsgSettingPumpTime +import info.nightscout.pump.dana.DanaPump import org.joda.time.DateTime import org.junit.Assert import org.junit.Test diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfoTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfoTest.kt index ae55b85b15..afb5a150dd 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfoTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingShippingInfoTest.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MessageBase import info.nightscout.androidaps.danar.comm.MsgSettingShippingInfo +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt index 518814623e..4ad11364ea 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingUserOptionsTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MsgSettingUserOptions +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfileTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfileTest.kt index 2e467936f9..54b919d126 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfileTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgStatusProfileTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danar.comm.MsgStatusProfile +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypesTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypesTest.kt index c67d8c0b52..d1e68a9a61 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypesTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/RecordTypesTest.kt @@ -1,11 +1,12 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm +import info.nightscout.pump.dana.comm.RecordTypes import org.junit.Assert import org.junit.Test class RecordTypesTest { @Test fun runTest() { - Assert.assertEquals(1.toByte(), info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BOLUS) + Assert.assertEquals(1.toByte(), RecordTypes.RECORD_TYPE_BOLUS) } } \ No newline at end of file diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt index 7a41442bb4..8101c0a70e 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt @@ -3,15 +3,16 @@ package info.nightscout.androidaps.plugins.pump.danaRKorean import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.danar.R import info.nightscout.interfaces.Constants import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.PluginType +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.queue.CommandQueue +import info.nightscout.pump.dana.DanaPump import info.nightscout.shared.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -25,6 +26,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() { @Mock lateinit var sp: SP @Mock lateinit var commandQueue: CommandQueue @Mock lateinit var pumpSync: PumpSync + @Mock lateinit var profileInstantiator: ProfileInstantiator lateinit var danaPump: DanaPump @@ -41,7 +43,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() { `when`(rh.gs(R.string.itmustbepositivevalue)).thenReturn("it must be positive value") `when`(rh.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(rh.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") - danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) + danaPump = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator) danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync) } diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt index b8d7b5af00..45314c7174 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt @@ -3,17 +3,18 @@ package info.nightscout.androidaps.plugins.pump.danaRv2 import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.danar.R import info.nightscout.interfaces.Constants import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.PluginType +import info.nightscout.interfaces.profile.ProfileInstantiator import info.nightscout.interfaces.pump.DetailedBolusInfoStorage import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.TemporaryBasalStorage import info.nightscout.interfaces.queue.CommandQueue +import info.nightscout.pump.dana.DanaPump import info.nightscout.shared.sharedPreferences.SP import org.junit.Before import org.junit.Test @@ -28,6 +29,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var temporaryBasalStorage: TemporaryBasalStorage @Mock lateinit var pumpSync: PumpSync + @Mock lateinit var profileInstantiator: ProfileInstantiator lateinit var danaPump: DanaPump @@ -44,7 +46,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() { `when`(rh.gs(R.string.itmustbepositivevalue)).thenReturn("it must be positive value") `when`(rh.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(rh.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") - danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) + danaPump = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator) danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, rh, constraintChecker, activePluginProvider, sp, commandQueue, danaPump,detailedBolusInfoStorage, temporaryBasalStorage, dateUtil, fabricPrivacy, pumpSync) } diff --git a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValueRv2Test.kt b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValueRv2Test.kt index 2b8abf85b7..59e9e31047 100644 --- a/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValueRv2Test.kt +++ b/pump/danar/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValueRv2Test.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRv2.comm -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danaRv2.comm.MsgCheckValue_v2 import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt index e59947f1ed..4e6fa7b312 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt @@ -8,9 +8,6 @@ import android.os.IBinder import android.text.format.DateFormat import androidx.preference.Preference import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaFragment -import info.nightscout.androidaps.dana.DanaPump -import info.nightscout.androidaps.dana.comm.RecordTypes import info.nightscout.androidaps.danars.events.EventDanaRSDeviceChange import info.nightscout.androidaps.danars.services.DanaRSService import info.nightscout.core.events.EventNewNotification @@ -37,6 +34,9 @@ import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.interfaces.utils.Round +import info.nightscout.pump.dana.DanaFragment +import info.nightscout.pump.dana.DanaPump +import info.nightscout.pump.dana.comm.RecordTypes import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventAppExit diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSHistoryEvents.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSHistoryEvents.kt index 8929cdf49c..c5c2a823c6 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSHistoryEvents.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSHistoryEvents.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfoStorage import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.TemporaryBasalStorage +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventPumpStatusChanged import info.nightscout.rx.logging.LTag diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSSetEventHistory.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSSetEventHistory.kt index 280615b6ce..6abddb86c4 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSSetEventHistory.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketAPSSetEventHistory.kt @@ -1,10 +1,9 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag - import org.joda.time.DateTime import org.joda.time.DateTimeZone import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetBasalRate.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetBasalRate.kt index dc2f529630..9e01308764 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetBasalRate.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetBasalRate.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.core.events.EventNewNotification import info.nightscout.interfaces.notifications.Notification +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventDismissNotification import info.nightscout.rx.logging.LTag diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetProfileNumber.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetProfileNumber.kt index 5aaa172438..12d881b914 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetProfileNumber.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalGetProfileNumber.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGet24CIRCFArray.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGet24CIRCFArray.kt index 83b892d866..ee134289a7 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGet24CIRCFArray.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGet24CIRCFArray.kt @@ -1,10 +1,9 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag - import javax.inject.Inject class DanaRSPacketBolusGet24CIRCFArray( diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetBolusOption.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetBolusOption.kt index 3fd59caad5..62d1625c17 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetBolusOption.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetBolusOption.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.core.events.EventNewNotification import info.nightscout.interfaces.notifications.Notification +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventDismissNotification import info.nightscout.rx.logging.LTag diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCIRCFArray.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCIRCFArray.kt index 9158bd9da1..0af50864fa 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCIRCFArray.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCIRCFArray.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCalculationInformation.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCalculationInformation.kt index 08f2b2add4..72411c9470 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCalculationInformation.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetCalculationInformation.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetStepBolusInformation.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetStepBolusInformation.kt index 6224d85da0..c8941b64d4 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetStepBolusInformation.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusGetStepBolusInformation.kt @@ -1,10 +1,9 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag - import org.joda.time.DateTime import org.joda.time.DateTimeZone import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSet24CIRCFArray.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSet24CIRCFArray.kt index 08040351fd..ac555c38bc 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSet24CIRCFArray.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSet24CIRCFArray.kt @@ -1,12 +1,11 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.profile.Profile +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag - import javax.inject.Inject import kotlin.math.round diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt index 8489af97cb..b0430afe9b 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStart.kt @@ -1,10 +1,10 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStop.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStop.kt index 0652069a99..f4835d5dfd 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStop.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBolusSetStepBolusStop.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption -import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.rx.events.EventOverviewBolusProgress +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.events.EventOverviewBolusProgress import info.nightscout.rx.logging.LTag +import info.nightscout.shared.interfaces.ResourceHelper import javax.inject.Inject open class DanaRSPacketBolusSetStepBolusStop( diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetPumpCheck.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetPumpCheck.kt index 3ec3f5cbf6..b847d0b7b2 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetPumpCheck.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetPumpCheck.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.core.events.EventNewNotification import info.nightscout.interfaces.notifications.Notification +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingInformation.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingInformation.kt index 114aa66e28..ac346920f2 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingInformation.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingInformation.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingVersion.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingVersion.kt index 3a718f40d1..afd9b6cf46 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingVersion.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralGetShippingVersion.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import java.nio.charset.Charset import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralInitialScreenInformation.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralInitialScreenInformation.kt index 264cc408aa..0c8c44bb6a 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralInitialScreenInformation.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketGeneralInitialScreenInformation.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt index 4c47477fb2..033d72c4cd 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistory.kt @@ -1,11 +1,11 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump -import info.nightscout.androidaps.dana.comm.RecordTypes -import info.nightscout.androidaps.dana.database.DanaHistoryRecord -import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao import info.nightscout.interfaces.pump.PumpSync +import info.nightscout.pump.dana.DanaPump +import info.nightscout.pump.dana.comm.RecordTypes +import info.nightscout.pump.dana.database.DanaHistoryRecord +import info.nightscout.pump.dana.database.DanaHistoryRecordDao import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventDanaRSyncStatus import info.nightscout.rx.logging.LTag diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyAlarm.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyAlarm.kt index 6b83c4ebef..3c45f817bb 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyAlarm.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyAlarm.kt @@ -1,12 +1,12 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.core.events.EventNewNotification import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.pump.PumpSync +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryComplete.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryComplete.kt index 843293036a..ed8bdfe853 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryComplete.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryComplete.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption -import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.rx.events.EventOverviewBolusProgress +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.events.EventOverviewBolusProgress import info.nightscout.rx.logging.LTag +import info.nightscout.shared.interfaces.ResourceHelper import javax.inject.Inject import kotlin.math.min diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryRateDisplay.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryRateDisplay.kt index 7943112b6d..0f478f32be 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryRateDisplay.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryRateDisplay.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.encryption.BleEncryption -import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.rx.events.EventOverviewBolusProgress +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.events.EventOverviewBolusProgress import info.nightscout.rx.logging.LTag +import info.nightscout.shared.interfaces.ResourceHelper import javax.inject.Inject import kotlin.math.min diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpTime.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpTime.kt index 0f03ad5d75..e401611583 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpTime.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpTime.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import org.joda.time.DateTime import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpUTCAndTimeZone.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpUTCAndTimeZone.kt index a71a57149b..1d05535199 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpUTCAndTimeZone.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetPumpUTCAndTimeZone.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import org.joda.time.DateTime import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetUserOption.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetUserOption.kt index 020a75bad6..5bb8c589e8 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetUserOption.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionGetUserOption.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOption.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOption.kt index 181c0cbb4b..65cb92dc85 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOption.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOption.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketReviewGetPumpDecRatio.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketReviewGetPumpDecRatio.kt index 159e92e194..626f1b2b16 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketReviewGetPumpDecRatio.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/comm/DanaRSPacketReviewGetPumpDecRatio.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.logging.LTag import javax.inject.Inject diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt index 86d86564b3..4427254a87 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt @@ -19,7 +19,6 @@ import android.os.SystemClock import android.util.Base64 import androidx.core.app.ActivityCompat import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.DanaRSPlugin import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.activities.EnterPinActivity @@ -36,6 +35,7 @@ import info.nightscout.core.utils.notify import info.nightscout.core.utils.waitMillis import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.pump.PumpSync +import info.nightscout.pump.dana.DanaPump import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventDismissNotification import info.nightscout.rx.events.EventPumpStatusChanged diff --git a/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt b/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt index a92620f64d..2c86c3e971 100644 --- a/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt +++ b/pump/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt @@ -8,9 +8,6 @@ import android.os.IBinder import android.os.SystemClock import dagger.android.DaggerService import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump -import info.nightscout.androidaps.dana.comm.RecordTypes -import info.nightscout.androidaps.dana.events.EventDanaRNewStatus import info.nightscout.androidaps.danars.DanaRSPlugin import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.comm.DanaRSPacket @@ -69,6 +66,9 @@ import info.nightscout.interfaces.queue.Callback import info.nightscout.interfaces.queue.Command import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.ui.ActivityNames +import info.nightscout.pump.dana.DanaPump +import info.nightscout.pump.dana.comm.RecordTypes +import info.nightscout.pump.dana.events.EventDanaRNewStatus import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventAppExit diff --git a/pump/danars/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt b/pump/danars/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt new file mode 100644 index 0000000000..297ebcc121 --- /dev/null +++ b/pump/danars/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.androidaps + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/pump/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/pump/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index cc3428ed77..fbc25d6636 100644 --- a/pump/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/pump/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -4,7 +4,6 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Config import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/pump/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt b/pump/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt index b7c74cb6f2..1fc6113a61 100644 --- a/pump/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt +++ b/pump/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt @@ -3,8 +3,9 @@ package info.nightscout.androidaps.danars import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.comm.DanaRSPacket +import info.nightscout.interfaces.profile.ProfileInstantiator +import info.nightscout.pump.dana.DanaPump import info.nightscout.shared.sharedPreferences.SP import org.junit.Before import org.mockito.ArgumentMatchers @@ -14,6 +15,7 @@ import org.mockito.Mockito open class DanaRSTestBase : TestBaseWithProfile() { @Mock lateinit var sp: SP + @Mock lateinit var profileInstantiator: ProfileInstantiator val injector = HasAndroidInjector { AndroidInjector { } } @@ -54,6 +56,6 @@ open class DanaRSTestBase : TestBaseWithProfile() { @Before fun setup() { - danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) + danaPump = DanaPump(aapsLogger, sp, dateUtil, profileInstantiator) } } \ No newline at end of file diff --git a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt index a75b665882..296aa3509a 100644 --- a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt +++ b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt @@ -2,13 +2,13 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.comm.RecordTypes -import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao import info.nightscout.androidaps.danars.DanaRSTestBase +import info.nightscout.pump.dana.comm.RecordTypes +import info.nightscout.pump.dana.database.DanaHistoryRecordDao import org.junit.Assert import org.junit.Test import org.mockito.Mock -import java.util.* +import java.util.GregorianCalendar class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() { diff --git a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt index 1f0970ade2..4f370d1ba5 100644 --- a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt +++ b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt @@ -2,12 +2,12 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test import org.mockito.Mock diff --git a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt index b8f152d522..12a6a3e3f2 100644 --- a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt +++ b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt @@ -2,8 +2,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.DanaRSTestBase +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt index 4c9cd8754e..680bc04d81 100644 --- a/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt +++ b/pump/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt @@ -2,8 +2,8 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.danars.DanaRSTestBase +import info.nightscout.pump.dana.DanaPump import org.junit.Assert import org.junit.Test diff --git a/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt b/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt index ec8fd5ee33..8c019d122d 100644 --- a/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt +++ b/pump/diaconn/src/main/java/info/nightscout/androidaps/diaconn/DiaconnG8Fragment.kt @@ -175,13 +175,13 @@ class DiaconnG8Fragment : DaggerFragment() { val todayInsulinAmount = (pump.todayBaseAmount + pump.todaySnackAmount + pump.todayMealAmount) val todayInsulinLimitAmount = (pump.maxBasal.toInt() * 24) + pump.maxBolusePerDay.toInt() - binding.dailyunits.text = rh.gs(R.string.reservoirvalue, todayInsulinAmount, todayInsulinLimitAmount) + binding.dailyunits.text = rh.gs(R.string.reservoir_value, todayInsulinAmount, todayInsulinLimitAmount) warnColors.setColor(binding.dailyunits, todayInsulinAmount, todayInsulinLimitAmount * 0.75, todayInsulinLimitAmount * 0.9) binding.basabasalrate.text = pump.baseInjAmount.toString() + " / " + rh.gs(R.string.pump_base_basal_rate, plugin.baseBasalRate) binding.tempbasal.text = diaconnG8Pump.temporaryBasalToString() binding.extendedbolus.text = diaconnG8Pump.extendedBolusToString() - binding.reservoir.text = rh.gs(R.string.reservoirvalue, pump.systemRemainInsulin, 307) + binding.reservoir.text = rh.gs(R.string.reservoir_value, pump.systemRemainInsulin, 307) warnColors.setColorInverse(binding.reservoir, pump.systemRemainInsulin, 50.0, 20.0) binding.battery.text = "{fa-battery-" + pump.systemRemainBattery / 25 + "}" + " (" + pump.systemRemainBattery + " %)" warnColors.setColorInverse(binding.battery, pump.systemRemainBattery.toDouble(), 51.0, 26.0) diff --git a/pump/diaconn/src/main/res/layout/diaconn_g8_fragment.xml b/pump/diaconn/src/main/res/layout/diaconn_g8_fragment.xml index 50e94a44ed..e7881ac3d1 100644 --- a/pump/diaconn/src/main/res/layout/diaconn_g8_fragment.xml +++ b/pump/diaconn/src/main/res/layout/diaconn_g8_fragment.xml @@ -300,7 +300,7 @@ android:layout_weight="1" android:paddingStart="0dp" android:paddingEnd="5dp" - android:text="@string/dailyunits" + android:text="@string/daily_units" android:textAlignment="viewEnd" android:textSize="14sp" /> @@ -699,7 +699,7 @@ android:drawableTop="@drawable/ic_pump_history" android:paddingStart="0dp" android:paddingEnd="0dp" - android:text="@string/pumphistory" /> + android:text="@string/pump_history" /> @@ -718,7 +718,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" - android:drawableTop="@drawable/ic_danar_useropt" + android:drawableTop="@drawable/ic_user_options" android:paddingStart="0dp" android:paddingEnd="0dp" android:text="@string/diagonn_g8_useroptions" /> diff --git a/pump/diaconn/src/main/res/layout/diaconn_g8_history_activity.xml b/pump/diaconn/src/main/res/layout/diaconn_g8_history_activity.xml index 98f725b89f..e9ed0cc621 100644 --- a/pump/diaconn/src/main/res/layout/diaconn_g8_history_activity.xml +++ b/pump/diaconn/src/main/res/layout/diaconn_g8_history_activity.xml @@ -29,7 +29,7 @@ android:layout_gravity="center" android:layout_marginStart="10dp" android:layout_marginEnd="10dp" - android:text="@string/pumphistory" + android:text="@string/pump_history" android:textAlignment="center" android:textAppearance="?android:attr/textAppearanceLarge" /> @@ -51,7 +51,7 @@ android:layout_below="@+id/spacer" android:layout_marginStart="5dp" android:layout_marginEnd="5dp" - android:hint="@string/eventtype"> + android:hint="@string/event_type"> + app:srcCompat="@drawable/ic_user_options" /> + android:text="@string/pump_history" /> diff --git a/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt b/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt index a1a19be906..d4dfe1e875 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt @@ -59,7 +59,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { private var tabSelected = 0 private val typeSelected = arrayOf(ProfileType.MOTOL_DEFAULT, ProfileType.CURRENT) - private val ageUsed = arrayOf(15.0, 15.0) + private val ageUsed = arrayOf(15, 15) private val weightUsed = arrayOf(0.0, 0.0) private val tddUsed = arrayOf(0.0, 0.0) private val pctUsed = arrayOf(32.0, 32.0) @@ -244,7 +244,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { switchTab(0, typeSelected[0], false) } - private fun getProfile(age: Double, tdd: Double, weight: Double, basalPct: Double, tab: Int): PureProfile? = + private fun getProfile(age: Int, tdd: Double, weight: Double, basalPct: Double, tab: Int): PureProfile? = try { // Profile must not exist when (typeSelected[tab]) { ProfileType.MOTOL_DEFAULT -> defaultProfile.profile(age, tdd, weight, profileFunction.getUnits()) @@ -257,7 +257,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { null } - private fun getProfileName(age: Double, tdd: Double, weight: Double, basalSumPct: Double, tab: Int): String = + private fun getProfileName(age: Int, tdd: Double, weight: Double, basalSumPct: Double, tab: Int): String = when (typeSelected[tab]) { ProfileType.MOTOL_DEFAULT -> if (tdd > 0) rh.gs(R.string.format_with_tdd, age, tdd) else rh.gs(R.string.format_with_weight, age, weight) ProfileType.DPV_DEFAULT -> rh.gs(R.string.format_with_tdd_and_pct, age, tdd, (basalSumPct * 100).toInt()) @@ -267,7 +267,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { } private fun storeValues() { - ageUsed[tabSelected] = binding.age.value + ageUsed[tabSelected] = binding.age.value.toInt() weightUsed[tabSelected] = binding.weight.value tddUsed[tabSelected] = binding.tdd.value pctUsed[tabSelected] = binding.basalPctFromTdd.value @@ -297,7 +297,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { binding.profileSwitch.visibility = (newContent == ProfileType.PROFILE_SWITCH).toVisibility() // Restore selected values - binding.age.value = ageUsed[tabSelected] + binding.age.value = ageUsed[tabSelected].toDouble() binding.weight.value = weightUsed[tabSelected] binding.tdd.value = tddUsed[tabSelected] binding.basalPctFromTdd.value = pctUsed[tabSelected] diff --git a/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt b/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt index e75bb19b9a..c97ffad145 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt @@ -37,7 +37,7 @@ class SurveyActivity : NoSplashAppCompatActivity() { binding.spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList) binding.profile.setOnClickListener { - val age = SafeParse.stringToDouble(binding.age.text.toString()) + val age = SafeParse.stringToInt(binding.age.text.toString()) val weight = SafeParse.stringToDouble(binding.weight.text.toString()) val tdd = SafeParse.stringToDouble(binding.tdd.text.toString()) if (age < 1 || age > 120) { diff --git a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsCareportalFragment.kt b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsCareportalFragment.kt index 21f372944b..8994e9c5db 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsCareportalFragment.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsCareportalFragment.kt @@ -14,7 +14,6 @@ import androidx.lifecycle.Lifecycle import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.android.support.DaggerFragment -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 @@ -28,6 +27,7 @@ import info.nightscout.database.impl.transactions.InvalidateAAPSStartedTherapyEv import info.nightscout.database.impl.transactions.InvalidateTherapyEventTransaction import info.nightscout.interfaces.Config import info.nightscout.interfaces.Translator +import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventNSClientRestart @@ -245,7 +245,7 @@ class TreatmentsCareportalFragment : DaggerFragment(), MenuProvider { private fun getConfirmationText(selectedItems: SparseArray): String { if (selectedItems.size() == 1) { val therapyEvent = selectedItems.valueAt(0) - return rh.gs(R.string.eventtype) + ": " + translator.translate(therapyEvent.type) + "\n" + + return rh.gs(R.string.event_type) + ": " + translator.translate(therapyEvent.type) + "\n" + rh.gs(R.string.notes_label) + ": " + (therapyEvent.note ?: "") + "\n" + rh.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(therapyEvent.timestamp) } diff --git a/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfile.kt b/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfile.kt index b742a30e4e..0cb85c143f 100644 --- a/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfile.kt +++ b/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfile.kt @@ -24,23 +24,23 @@ class DefaultProfile @Inject constructor(val dateUtil: DateUtil) { private var twelveToSeventeen: TreeMap> = TreeMap() @Suppress("unused") var eighteenToTwentyFour: TreeMap> = TreeMap() - fun profile(age: Double, tdd: Double, weight: Double, units: GlucoseUnit): PureProfile? { + fun profile(age: Int, tdd: Double, weight: Double, units: GlucoseUnit): PureProfile? { val profile = JSONObject() - if (age in 1.0..5.0) { + if (age in 1..5) { val _tdd = if (tdd == 0.0) 0.6 * weight else tdd closest(oneToFive, _tdd * 0.3)?.let { array -> profile.put("basal", arrayToJson(array)) } val ic = Round.roundTo(250.0 / _tdd, 1.0) profile.put("carbratio", singleValueArray(ic, arrayOf(0.0, -4.0, -1.0, -2.0, -4.0, 0.0, -4.0))) val isf = Round.roundTo(200.0 / _tdd, 0.1) profile.put("sens", singleValueArrayFromMmolToUnits(isf, arrayOf(0.0, -2.0, -0.0, -0.0, -2.0, 0.0, -2.0),units)) - } else if (age in 6.0..11.0) { + } else if (age in 6..11) { val _tdd = if (tdd == 0.0) 0.8 * weight else tdd closest(sixToEleven, _tdd * 0.4)?.let { array -> profile.put("basal", arrayToJson(array)) } val ic = Round.roundTo(375.0 / _tdd, 1.0) profile.put("carbratio", singleValueArray(ic, arrayOf(0.0, -3.0, 0.0, -1.0, -3.0, 0.0, -2.0))) val isf = Round.roundTo(170.0 / _tdd, 0.1) profile.put("sens", singleValueArrayFromMmolToUnits(isf, arrayOf(0.0, -1.0, -0.0, -0.0, -1.0, 0.0, -1.0),units)) - } else if (age in 12.0..18.0) { + } else if (age in 12..18) { val _tdd = if (tdd == 0.0) 1.0 * weight else tdd closest(twelveToSeventeen, _tdd * 0.5)?.let { array -> profile.put("basal", arrayToJson(array)) } val ic = Round.roundTo(500.0 / _tdd, 1.0) diff --git a/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfileDPV.kt b/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfileDPV.kt index 53ef0944ef..36199e7ec8 100644 --- a/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfileDPV.kt +++ b/ui/src/main/java/info/nightscout/ui/defaultProfile/DefaultProfileDPV.kt @@ -20,18 +20,18 @@ class DefaultProfileDPV @Inject constructor(val injector: HasAndroidInjector, va private var sixToEleven = arrayOf(4.20, 4.27, 4.41, 4.62, 4.92, 5.09, 5.01, 4.47, 3.89, 3.33, 3.10, 2.91, 2.97, 3.08, 3.36, 3.93, 4.52, 4.76, 4.69, 4.63, 4.63, 4.47, 4.47, 4.31) private var twelveToEighteen = arrayOf(3.47, 3.80, 4.31, 4.95, 5.59, 6.11, 5.89, 5.11, 4.31, 3.78, 3.55, 3.39, 3.35, 3.39, 3.64, 3.97, 4.53, 4.59, 4.50, 4.00, 3.69, 3.39, 3.35, 3.35) - fun profile(age: Double, tdd: Double, basalSumPct: Double, units: GlucoseUnit): PureProfile? { + fun profile(age: Int, tdd: Double, basalSumPct: Double, units: GlucoseUnit): PureProfile? { val basalSum = tdd * basalSumPct val profile = JSONObject() - if (age in 1.0..5.0) { + if (age in 1..5) { profile.put("basal", arrayToJson(oneToFive, basalSum)) profile.put("carbratio", singleValueArray(0.0)) profile.put("sens", singleValueArrayFromMmolToUnits(0.0, units)) - } else if (age in 6.0..11.0) { + } else if (age in 6..11) { profile.put("basal", arrayToJson(sixToEleven, basalSum)) profile.put("carbratio", singleValueArray(0.0)) profile.put("sens", singleValueArrayFromMmolToUnits(0.0, units)) - } else if (age in 12.0..18.0) { + } else if (age in 12..18) { profile.put("basal", arrayToJson(twelveToEighteen, basalSum)) profile.put("carbratio", singleValueArray(0.0)) profile.put("sens", singleValueArrayFromMmolToUnits(0.0, units)) diff --git a/ui/src/main/res/layout/treatments_fragment.xml b/ui/src/main/res/layout/treatments_fragment.xml index 3391381986..e079f0ecb6 100644 --- a/ui/src/main/res/layout/treatments_fragment.xml +++ b/ui/src/main/res/layout/treatments_fragment.xml @@ -56,7 +56,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/user_entry" - android:icon="@drawable/ic_danar_useropt" /> + android:icon="@drawable/ic_user_options" /> diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index dd596bb879..fcc3db5ef8 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -140,9 +140,9 @@ Default profile Current profile Available profile - Age: %1$.0f TDD: %2$.0f U - Age: %1$.0f TDD: %2$.0f U %3$d%% - Age: %1$.0f Weight: %2$.0f kg + Age: %1$d TDD: %2$.0f U + Age: %1$d TDD: %2$.0f U %3$d%% + Age: %1$d Weight: %2$.0f kg DPV Default profile Invalid % entry diff --git a/ui/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt b/ui/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt new file mode 100644 index 0000000000..df1e0e2321 --- /dev/null +++ b/ui/src/test/java/info/nightscout/androidaps/ProfileStoreObject.kt @@ -0,0 +1,107 @@ +package info.nightscout.implementation.profile + +import androidx.collection.ArrayMap +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.core.profile.ProfileSealed +import info.nightscout.interfaces.Config +import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.utils.HardLimits +import info.nightscout.interfaces.utils.JsonHelper +import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.shared.utils.DateUtil +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject + +class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore { + + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var config: Config + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var rxBus: RxBus + @Inject lateinit var hardLimits: HardLimits + + init { + injector.androidInjector().inject(this) + } + + private val cachedObjects = ArrayMap() + + private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null) + + private fun getStore(): JSONObject? { + try { + if (data.has("store")) return data.getJSONObject("store") + } catch (e: JSONException) { + aapsLogger.error("Unhandled exception", e) + } + return null + } + + override fun getStartDate(): Long { + val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 + return try { + dateUtil.fromISODateString(iso) + } catch (e: Exception) { + 0 + } + } + + override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) } + override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) } + + override fun getDefaultProfileName(): String? { + val defaultProfileName = data.optString("defaultProfile") + return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null + } + + override fun getProfileList(): ArrayList { + val ret = ArrayList() + getStore()?.keys()?.let { keys -> + while (keys.hasNext()) { + val profileName = keys.next() as String + ret.add(profileName) + } + } + return ret + } + + @Synchronized + override fun getSpecificProfile(profileName: String): PureProfile? { + var profile: PureProfile? = null + val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits()) + getStore()?.let { store -> + if (store.has(profileName)) { + profile = cachedObjects[profileName] + if (profile == null) { + JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject -> + profile = pureProfileFromJson(profileObject, dateUtil, units) + profile?.let { cachedObjects[profileName] = profile } + } + } + } + } + return profile + } + + private fun getSpecificProfileJson(profileName: String): JSONObject? { + getStore()?.let { store -> + if (store.has(profileName)) + return JsonHelper.safeGetJSONObject(store, profileName, null) + } + return null + } + + override val allProfilesValid: Boolean + get() = getProfileList() + .asSequence() + .map { profileName -> getSpecificProfile(profileName.toString()) } + .map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } } + .all { it?.isValid == true } +} \ No newline at end of file diff --git a/ui/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/ui/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 0cd5f61864..c61c03d0c6 100644 --- a/ui/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/ui/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -5,10 +5,10 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.profile.ProfileStoreObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.entities.EffectiveProfileSwitch import info.nightscout.database.entities.embedments.InsulinConfiguration +import info.nightscout.implementation.profile.ProfileStoreObject import info.nightscout.interfaces.Config import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.plugin.ActivePlugin diff --git a/ui/src/test/java/info/nightscout/ui/defaultProfile/DefaultProfileTest.kt b/ui/src/test/java/info/nightscout/ui/defaultProfile/DefaultProfileTest.kt index e6a159193d..8ccfea4d65 100644 --- a/ui/src/test/java/info/nightscout/ui/defaultProfile/DefaultProfileTest.kt +++ b/ui/src/test/java/info/nightscout/ui/defaultProfile/DefaultProfileTest.kt @@ -10,18 +10,18 @@ class DefaultProfileTest : TestBaseWithProfile() { @Test fun profile() { - val dp = DefaultProfile(dateUtil).profile(5.0, 5.1 / 0.3, 0.0, GlucoseUnit.MMOL) + val dp = DefaultProfile(dateUtil).profile(5, 5.1 / 0.3, 0.0, GlucoseUnit.MMOL) var p = ProfileSealed.Pure(dp!!) assertEquals(0.150, p.getBasalTimeFromMidnight(0), 0.001) assertEquals(15.0, p.getIcTimeFromMidnight(0), 0.001) assertEquals(11.8, p.getIsfTimeFromMidnight(0), 0.001) - p = ProfileSealed.Pure(DefaultProfile(dateUtil).profile(7.0, 10.0 / 0.4, 0.0, GlucoseUnit.MMOL)!!) + p = ProfileSealed.Pure(DefaultProfile(dateUtil).profile(7, 10.0 / 0.4, 0.0, GlucoseUnit.MMOL)!!) assertEquals(0.350, p.getBasalTimeFromMidnight(0), 0.001) assertEquals(15.0, p.getIcTimeFromMidnight(0), 0.001) assertEquals(6.8, p.getIsfTimeFromMidnight(0), 0.001) - p = ProfileSealed.Pure(DefaultProfile(dateUtil).profile(12.0, 25.0 / 0.5, 0.0, GlucoseUnit.MMOL)!!) + p = ProfileSealed.Pure(DefaultProfile(dateUtil).profile(12, 25.0 / 0.5, 0.0, GlucoseUnit.MMOL)!!) assertEquals(0.80, p.getBasalTimeFromMidnight(0), 0.001) assertEquals(10.0, p.getIcTimeFromMidnight(0), 0.001) assertEquals(2.2, p.getIsfTimeFromMidnight(0), 0.001)