diff --git a/app/build.gradle b/app/build.gradle index e4d4c5be8b..63b7948b91 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -111,7 +111,7 @@ android { defaultConfig { multiDexEnabled true versionCode 1500 - version "2.8.2.1-dev-e3" + version "2.8.2.1-dev-e4" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' diff --git a/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt b/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt index 2596ef9583..fa8b2774be 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt +++ b/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfile.kt @@ -1,7 +1,5 @@ package info.nightscout.androidaps.data.defaultProfile -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.data.ProfileImplOld import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.androidaps.interfaces.GlucoseUnit diff --git a/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileDPV.kt b/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileDPV.kt index a0a555cc30..78ed97b335 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileDPV.kt +++ b/app/src/main/java/info/nightscout/androidaps/data/defaultProfile/DefaultProfileDPV.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.data.defaultProfile import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.data.ProfileImplOld import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.androidaps.interfaces.GlucoseUnit diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index 15298fb768..60eb3ace15 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -29,7 +29,6 @@ import info.nightscout.androidaps.plugins.general.tidepool.TidepoolFragment import info.nightscout.androidaps.plugins.general.wear.WearFragment import info.nightscout.androidaps.plugins.insulin.InsulinFragment import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment -import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment import info.nightscout.androidaps.plugins.source.BGSourceFragment import info.nightscout.androidaps.plugins.treatments.TreatmentsFragment @@ -46,8 +45,7 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesAutomationFragment(): AutomationFragment @ContributesAndroidInjector abstract fun contributesBGSourceFragment(): BGSourceFragment - @ContributesAndroidInjector - abstract fun contributesConfigBuilderFragment(): ConfigBuilderFragment + @ContributesAndroidInjector abstract fun contributesConfigBuilderFragment(): ConfigBuilderFragment @ContributesAndroidInjector abstract fun contributesFoodFragment(): FoodFragment @ContributesAndroidInjector abstract fun contributesInsulinFragment(): InsulinFragment @@ -58,10 +56,8 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesOverviewFragment(): OverviewFragment @ContributesAndroidInjector abstract fun contributesLoopFragment(): LoopFragment @ContributesAndroidInjector abstract fun contributesMaintenanceFragment(): MaintenanceFragment - @ContributesAndroidInjector abstract fun contributesNSProfileFragment(): NSProfileFragment @ContributesAndroidInjector abstract fun contributesNSClientFragment(): NSClientFragment - @ContributesAndroidInjector - abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment + @ContributesAndroidInjector abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment @ContributesAndroidInjector abstract fun contributesWearFragment(): WearFragment @ContributesAndroidInjector abstract fun contributesTidepoolFragment(): TidepoolFragment @@ -85,8 +81,7 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesEditEventDialog(): EditEventDialog @ContributesAndroidInjector abstract fun contributesEditTriggerDialog(): EditTriggerDialog - @ContributesAndroidInjector - abstract fun contributesEditQuickWizardDialog(): EditQuickWizardDialog + @ContributesAndroidInjector abstract fun contributesEditQuickWizardDialog(): EditQuickWizardDialog @ContributesAndroidInjector abstract fun contributesExtendedBolusDialog(): ExtendedBolusDialog @ContributesAndroidInjector abstract fun contributesFillDialog(): FillDialog @@ -102,8 +97,7 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesWizardDialog(): WizardDialog @ContributesAndroidInjector abstract fun contributesWizardInfoDialog(): WizardInfoDialog - @ContributesAndroidInjector - abstract fun contributesExchangeAuthTokenDialot(): OpenHumansLoginActivity.ExchangeAuthTokenDialog + @ContributesAndroidInjector abstract fun contributesExchangeAuthTokenDialog(): OpenHumansLoginActivity.ExchangeAuthTokenDialog @ContributesAndroidInjector abstract fun contributesPasswordCheck(): PasswordCheck } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt index 02506911ec..5cb174b533 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -37,7 +37,6 @@ import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin import info.nightscout.androidaps.plugins.insulin.InsulinOrefUltraRapidActingPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin -import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin @@ -192,12 +191,6 @@ abstract class PluginsModule { @IntKey(220) abstract fun bindOpenAPSSMBPlugin(plugin: OpenAPSSMBPlugin): PluginBase - @Binds - @AllConfigs - @IntoMap - @IntKey(230) - abstract fun bindNSProfilePlugin(plugin: NSProfilePlugin): PluginBase - @Binds @NotNSClient @IntoMap diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WorkersModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WorkersModule.kt index 0c67611761..2e7bb25b43 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WorkersModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WorkersModule.kt @@ -9,7 +9,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.NSClientMbgWorker import info.nightscout.androidaps.plugins.general.nsclient.NSClientRemoveWorker import info.nightscout.androidaps.plugins.general.nsclient.NSClientUpdateRemoveAckWorker import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin -import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin +import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.plugins.source.* @Module @@ -24,7 +24,7 @@ abstract class WorkersModule { @ContributesAndroidInjector abstract fun contributesTomatoWorker(): TomatoPlugin.TomatoWorker @ContributesAndroidInjector abstract fun contributesEversenseWorker(): EversensePlugin.EversenseWorker @ContributesAndroidInjector abstract fun contributesNSClientSourceWorker(): NSClientSourcePlugin.NSClientSourceWorker - @ContributesAndroidInjector abstract fun contributesNSProfileWorker(): NSProfilePlugin.NSProfileWorker + @ContributesAndroidInjector abstract fun contributesNSProfileWorker(): LocalProfilePlugin.NSProfileWorker @ContributesAndroidInjector abstract fun contributesSmsCommunicatorWorker(): SmsCommunicatorPlugin.SmsCommunicatorWorker @ContributesAndroidInjector abstract fun contributesNSClientWorker(): NSClientAddUpdateWorker @ContributesAndroidInjector abstract fun contributesNSClientAddAckWorker(): NSClientAddAckWorker diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt index 4fb7f03f78..7e3dd1bb8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/DataSyncSelectorImplementation.kt @@ -2,14 +2,13 @@ package info.nightscout.androidaps.plugins.general.nsclient import info.nightscout.androidaps.R import info.nightscout.androidaps.database.AppRepository -import info.nightscout.androidaps.database.entities.DeviceStatus import info.nightscout.androidaps.database.entities.* +import info.nightscout.androidaps.extensions.toJson import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.DataSyncSelector import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.extensions.toJson import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -26,6 +25,23 @@ class DataSyncSelectorImplementation @Inject constructor( private val localProfilePlugin: LocalProfilePlugin ) : DataSyncSelector { + override fun doUpload() { + if (sp.getBoolean(R.string.key_ns_upload, true)) { + processChangedBolusesCompat() + processChangedCarbsCompat() + processChangedBolusCalculatorResultsCompat() + processChangedTemporaryBasalsCompat() + processChangedExtendedBolusesCompat() + processChangedProfileSwitchesCompat() + processChangedGlucoseValuesCompat() + processChangedTempTargetsCompat() + processChangedFoodsCompat() + processChangedTherapyEventsCompat() + processChangedDeviceStatusesCompat() + processChangedProfileStore() + } + } + override fun resetToNextFullSync() { sp.remove(R.string.key_ns_temporary_target_last_synced_id) sp.remove(R.string.key_ns_glucose_value_last_synced_id) @@ -459,8 +475,7 @@ class DataSyncSelectorImplementation @Inject constructor( if (lastChange == 0L) return localProfilePlugin.createProfileStore() val profileJson = localProfilePlugin.profile?.data ?: return - if (sp.getBoolean(R.string.key_ns_uploadlocalprofile, false)) - if (lastChange > lastSync) - nsClientPlugin.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now())) + if (lastChange > lastSync) + nsClientPlugin.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now())) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt index 1b6ba27cd9..7520cc1326 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt @@ -49,9 +49,6 @@ class NSClientAddUpdateWorker( @Inject lateinit var uel: UserEntryLogger override fun doWork(): Result { - val acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, true) && buildHelper.isEngineeringMode() || config.NSCLIENT - if (!acceptNSData) return Result.success() - val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) @@ -75,62 +72,66 @@ class NSClientAddUpdateWorker( if (mills > latestDateInReceivedData) latestDateInReceivedData = mills if (insulin > 0) { - bolusFromJson(json)?.let { bolus -> - repository.runTransactionForResult(SyncNsBolusTransaction(bolus, invalidateByNsOnly = false)) - .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) - ret = Result.failure(workDataOf("Error" to it.toString())) - } - .blockingGet() - .also { result -> - result.inserted.forEach { - uel.log(Action.BOLUS, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.Insulin(it.amount) - ) - aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") + if (sp.getBoolean(R.string.key_ns_receive_insulin, false) && buildHelper.isEngineeringMode() || config.NSCLIENT) { + bolusFromJson(json)?.let { bolus -> + repository.runTransactionForResult(SyncNsBolusTransaction(bolus, invalidateByNsOnly = false)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving bolus", it) + ret = Result.failure(workDataOf("Error" to it.toString())) } - result.invalidated.forEach { - uel.log(Action.BOLUS_REMOVED, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.Insulin(it.amount) - ) - aapsLogger.debug(LTag.DATABASE, "Invalidated bolus $it") + .blockingGet() + .also { result -> + result.inserted.forEach { + uel.log(Action.BOLUS, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.Insulin(it.amount) + ) + aapsLogger.debug(LTag.DATABASE, "Inserted bolus $it") + } + result.invalidated.forEach { + uel.log(Action.BOLUS_REMOVED, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.Insulin(it.amount) + ) + aapsLogger.debug(LTag.DATABASE, "Invalidated bolus $it") + } + result.updatedNsId.forEach { + aapsLogger.debug(LTag.DATABASE, "Updated nsId bolus $it") + } } - result.updatedNsId.forEach { - aapsLogger.debug(LTag.DATABASE, "Updated nsId bolus $it") - } - } - } ?: aapsLogger.error("Error parsing bolus json $json") + } ?: aapsLogger.error("Error parsing bolus json $json") + } } if (carbs > 0) { - carbsFromJson(json)?.let { carb -> - repository.runTransactionForResult(SyncNsCarbsTransaction(carb, invalidateByNsOnly = false)) - .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) - ret = Result.failure(workDataOf("Error" to it.toString())) - } - .blockingGet() - .also { result -> - result.inserted.forEach { - uel.log(Action.CARBS, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.Gram(it.amount.toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") + if (sp.getBoolean(R.string.key_ns_receive_carbs, false) && buildHelper.isEngineeringMode() || config.NSCLIENT) { + carbsFromJson(json)?.let { carb -> + repository.runTransactionForResult(SyncNsCarbsTransaction(carb, invalidateByNsOnly = false)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving carbs", it) + ret = Result.failure(workDataOf("Error" to it.toString())) } - result.invalidated.forEach { - uel.log(Action.CARBS_REMOVED, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.Gram(it.amount.toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it") + .blockingGet() + .also { result -> + result.inserted.forEach { + uel.log(Action.CARBS, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.Gram(it.amount.toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Inserted carbs $it") + } + result.invalidated.forEach { + uel.log(Action.CARBS_REMOVED, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.Gram(it.amount.toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Invalidated carbs $it") + } + result.updatedNsId.forEach { + aapsLogger.debug(LTag.DATABASE, "Updated nsId carbs $it") + } } - result.updatedNsId.forEach { - aapsLogger.debug(LTag.DATABASE, "Updated nsId carbs $it") - } - } - } ?: aapsLogger.error("Error parsing bolus json $json") + } ?: aapsLogger.error("Error parsing bolus json $json") + } } // Convert back emulated TBR -> EB if (eventType == TherapyEvent.Type.TEMPORARY_BASAL.text && json.has("extendedEmulated")) { @@ -142,46 +143,48 @@ class NSClientAddUpdateWorker( when { insulin > 0 || carbs > 0 -> Any() eventType == TherapyEvent.Type.TEMPORARY_TARGET.text -> - temporaryTargetFromJson(json)?.let { temporaryTarget -> - repository.runTransactionForResult(SyncNsTemporaryTargetTransaction(temporaryTarget, invalidateByNsOnly = false)) - .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) - ret = Result.failure(workDataOf("Error" to it.toString())) - } - .blockingGet() - .also { result -> - result.inserted.forEach { tt -> - uel.log(Action.TT, Sources.NSClient, - ValueWithUnit.TherapyEventTTReason(tt.reason), - ValueWithUnit.fromGlucoseUnit(tt.lowTarget, Constants.MGDL), - ValueWithUnit.fromGlucoseUnit(tt.highTarget, Constants.MGDL).takeIf { tt.lowTarget != tt.highTarget }, - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryTarget $tt") + if (sp.getBoolean(R.string.key_ns_receive_temp_target, false) && buildHelper.isEngineeringMode() || config.NSCLIENT) { + temporaryTargetFromJson(json)?.let { temporaryTarget -> + repository.runTransactionForResult(SyncNsTemporaryTargetTransaction(temporaryTarget, invalidateByNsOnly = false)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving temporary target", it) + ret = Result.failure(workDataOf("Error" to it.toString())) } - result.invalidated.forEach { tt -> - uel.log(Action.TT_REMOVED, Sources.NSClient, - ValueWithUnit.TherapyEventTTReason(tt.reason), - ValueWithUnit.Mgdl(tt.lowTarget), - ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryTarget $tt") + .blockingGet() + .also { result -> + result.inserted.forEach { tt -> + uel.log(Action.TT, Sources.NSClient, + ValueWithUnit.TherapyEventTTReason(tt.reason), + ValueWithUnit.fromGlucoseUnit(tt.lowTarget, Constants.MGDL), + ValueWithUnit.fromGlucoseUnit(tt.highTarget, Constants.MGDL).takeIf { tt.lowTarget != tt.highTarget }, + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryTarget $tt") + } + result.invalidated.forEach { tt -> + uel.log(Action.TT_REMOVED, Sources.NSClient, + ValueWithUnit.TherapyEventTTReason(tt.reason), + ValueWithUnit.Mgdl(tt.lowTarget), + ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryTarget $tt") + } + result.ended.forEach { tt -> + uel.log(Action.CANCEL_TT, Sources.NSClient, + ValueWithUnit.TherapyEventTTReason(tt.reason), + ValueWithUnit.Mgdl(tt.lowTarget), + ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Updated TemporaryTarget $tt") + } + result.updatedNsId.forEach { + aapsLogger.debug(LTag.DATABASE, "Updated nsId TemporaryTarget $it") + } } - result.ended.forEach { tt -> - uel.log(Action.CANCEL_TT, Sources.NSClient, - ValueWithUnit.TherapyEventTTReason(tt.reason), - ValueWithUnit.Mgdl(tt.lowTarget), - ValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(tt.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Updated TemporaryTarget $tt") - } - result.updatedNsId.forEach { - aapsLogger.debug(LTag.DATABASE, "Updated nsId TemporaryTarget $it") - } - } - } ?: aapsLogger.error("Error parsing TT json $json") + } ?: aapsLogger.error("Error parsing TT json $json") + } eventType == TherapyEvent.Type.CANNULA_CHANGE.text || eventType == TherapyEvent.Type.INSULIN_CHANGE.text || eventType == TherapyEvent.Type.SENSOR_CHANGE.text || @@ -192,158 +195,167 @@ class NSClientAddUpdateWorker( eventType == TherapyEvent.Type.EXERCISE.text || eventType == TherapyEvent.Type.APS_OFFLINE.text || eventType == TherapyEvent.Type.PUMP_BATTERY_CHANGE.text -> - therapyEventFromJson(json)?.let { therapyEvent -> - repository.runTransactionForResult(SyncNsTherapyEventTransaction(therapyEvent, invalidateByNsOnly = false)) - .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) - ret = Result.failure(workDataOf("Error" to it.toString())) - } - .blockingGet() - .also { result -> - val action = when (eventType) { - TherapyEvent.Type.CANNULA_CHANGE.text -> Action.SITE_CHANGE - TherapyEvent.Type.INSULIN_CHANGE.text -> Action.RESERVOIR_CHANGE - else -> Action.CAREPORTAL + if (sp.getBoolean(R.string.key_ns_receive_therapy_events, false) || config.NSCLIENT) { + therapyEventFromJson(json)?.let { therapyEvent -> + repository.runTransactionForResult(SyncNsTherapyEventTransaction(therapyEvent, invalidateByNsOnly = false)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving therapy event", it) + ret = Result.failure(workDataOf("Error" to it.toString())) } - result.inserted.forEach { - uel.log(action, Sources.NSClient, - it.note ?: "", - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.TherapyEventType(it.type) - ) - aapsLogger.debug(LTag.DATABASE, "Inserted TherapyEvent $it") + .blockingGet() + .also { result -> + val action = when (eventType) { + TherapyEvent.Type.CANNULA_CHANGE.text -> Action.SITE_CHANGE + TherapyEvent.Type.INSULIN_CHANGE.text -> Action.RESERVOIR_CHANGE + else -> Action.CAREPORTAL + } + result.inserted.forEach { + uel.log(action, Sources.NSClient, + it.note ?: "", + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.TherapyEventType(it.type) + ) + aapsLogger.debug(LTag.DATABASE, "Inserted TherapyEvent $it") + } + result.invalidated.forEach { + uel.log(Action.CAREPORTAL_REMOVED, Sources.NSClient, + it.note ?: "", + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.TherapyEventType(it.type) + ) + aapsLogger.debug(LTag.DATABASE, "Invalidated TherapyEvent $it") + } + result.updatedNsId.forEach { + aapsLogger.debug(LTag.DATABASE, "Updated nsId TherapyEvent $it") + } } - result.invalidated.forEach { - uel.log(Action.CAREPORTAL_REMOVED, Sources.NSClient, - it.note ?: "", - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.TherapyEventType(it.type) - ) - aapsLogger.debug(LTag.DATABASE, "Invalidated TherapyEvent $it") - } - result.updatedNsId.forEach { - aapsLogger.debug(LTag.DATABASE, "Updated nsId TherapyEvent $it") - } - } - } ?: aapsLogger.error("Error parsing TherapyEvent json $json") + } ?: aapsLogger.error("Error parsing TherapyEvent json $json") + } eventType == TherapyEvent.Type.COMBO_BOLUS.text -> - extendedBolusFromJson(json)?.let { extendedBolus -> - repository.runTransactionForResult(SyncNsExtendedBolusTransaction(extendedBolus, invalidateByNsOnly = false)) - .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving extended bolus", it) - ret = Result.failure(workDataOf("Error" to it.toString())) - } - .blockingGet() - .also { result -> - result.inserted.forEach { - uel.log(Action.EXTENDED_BOLUS, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.Insulin(it.amount), - ValueWithUnit.UnitPerHour(it.rate), - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Inserted ExtendedBolus $it") + if (config.NSCLIENT) { + extendedBolusFromJson(json)?.let { extendedBolus -> + repository.runTransactionForResult(SyncNsExtendedBolusTransaction(extendedBolus, invalidateByNsOnly = false)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving extended bolus", it) + ret = Result.failure(workDataOf("Error" to it.toString())) } - result.invalidated.forEach { - uel.log(Action.EXTENDED_BOLUS_REMOVED, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.Insulin(it.amount), - ValueWithUnit.UnitPerHour(it.rate), - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Invalidated ExtendedBolus $it") + .blockingGet() + .also { result -> + result.inserted.forEach { + uel.log(Action.EXTENDED_BOLUS, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.Insulin(it.amount), + ValueWithUnit.UnitPerHour(it.rate), + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Inserted ExtendedBolus $it") + } + result.invalidated.forEach { + uel.log(Action.EXTENDED_BOLUS_REMOVED, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.Insulin(it.amount), + ValueWithUnit.UnitPerHour(it.rate), + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Invalidated ExtendedBolus $it") + } + result.ended.forEach { + uel.log(Action.CANCEL_EXTENDED_BOLUS, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.Insulin(it.amount), + ValueWithUnit.UnitPerHour(it.rate), + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Updated ExtendedBolus $it") + } + result.updatedNsId.forEach { + aapsLogger.debug(LTag.DATABASE, "Updated nsId ExtendedBolus $it") + } } - result.ended.forEach { - uel.log(Action.CANCEL_EXTENDED_BOLUS, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.Insulin(it.amount), - ValueWithUnit.UnitPerHour(it.rate), - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Updated ExtendedBolus $it") - } - result.updatedNsId.forEach { - aapsLogger.debug(LTag.DATABASE, "Updated nsId ExtendedBolus $it") - } - } - } ?: aapsLogger.error("Error parsing ExtendedBolus json $json") + } ?: aapsLogger.error("Error parsing ExtendedBolus json $json") + } eventType == TherapyEvent.Type.TEMPORARY_BASAL.text -> - temporaryBasalFromJson(json)?.let { temporaryBasal -> - repository.runTransactionForResult(SyncNsTemporaryBasalTransaction(temporaryBasal, invalidateByNsOnly = false)) - .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving temporary basal", it) - ret = Result.failure(workDataOf("Error" to it.toString())) - } - .blockingGet() - .also { result -> - result.inserted.forEach { - uel.log(Action.TEMP_BASAL, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.UnitPerHour(it.rate), - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it") + if (config.NSCLIENT) { + temporaryBasalFromJson(json)?.let { temporaryBasal -> + repository.runTransactionForResult(SyncNsTemporaryBasalTransaction(temporaryBasal, invalidateByNsOnly = false)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving temporary basal", it) + ret = Result.failure(workDataOf("Error" to it.toString())) } - result.invalidated.forEach { - uel.log(Action.TEMP_BASAL_REMOVED, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.UnitPerHour(it.rate), - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it") + .blockingGet() + .also { result -> + result.inserted.forEach { + uel.log(Action.TEMP_BASAL, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.UnitPerHour(it.rate), + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Inserted TemporaryBasal $it") + } + result.invalidated.forEach { + uel.log(Action.TEMP_BASAL_REMOVED, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.UnitPerHour(it.rate), + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Invalidated TemporaryBasal $it") + } + result.ended.forEach { + uel.log(Action.CANCEL_TEMP_BASAL, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp), + ValueWithUnit.UnitPerHour(it.rate), + ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) + ) + aapsLogger.debug(LTag.DATABASE, "Ended TemporaryBasal $it") + } + result.updatedNsId.forEach { + aapsLogger.debug(LTag.DATABASE, "Updated nsId TemporaryBasal $it") + } } - result.ended.forEach { - uel.log(Action.CANCEL_TEMP_BASAL, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp), - ValueWithUnit.UnitPerHour(it.rate), - ValueWithUnit.Minute(TimeUnit.MILLISECONDS.toMinutes(it.duration).toInt()) - ) - aapsLogger.debug(LTag.DATABASE, "Ended TemporaryBasal $it") - } - result.updatedNsId.forEach { - aapsLogger.debug(LTag.DATABASE, "Updated nsId TemporaryBasal $it") - } - } - } ?: aapsLogger.error("Error parsing TemporaryBasal json $json") + } ?: aapsLogger.error("Error parsing TemporaryBasal json $json") + } eventType == TherapyEvent.Type.PROFILE_SWITCH.text -> - profileSwitchFromJson(json, dateUtil, activePlugin)?.let { profileSwitch -> - repository.runTransactionForResult(SyncNsProfileSwitchTransaction(profileSwitch, invalidateByNsOnly = false)) - .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving ProfileSwitch", it) - ret = Result.failure(workDataOf("Error" to it.toString())) - } - .blockingGet() - .also { result -> - result.inserted.forEach { - uel.log(Action.PROFILE_SWITCH, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp)) - aapsLogger.debug(LTag.DATABASE, "Inserted ProfileSwitch $it") + if (sp.getBoolean(R.string.key_ns_receive_profile_switch, false) && buildHelper.isEngineeringMode() || config.NSCLIENT) { + profileSwitchFromJson(json, dateUtil, activePlugin)?.let { profileSwitch -> + repository.runTransactionForResult(SyncNsProfileSwitchTransaction(profileSwitch, invalidateByNsOnly = false)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving ProfileSwitch", it) + ret = Result.failure(workDataOf("Error" to it.toString())) } - result.invalidated.forEach { - uel.log(Action.PROFILE_SWITCH_REMOVED, Sources.NSClient, - ValueWithUnit.Timestamp(it.timestamp)) - aapsLogger.debug(LTag.DATABASE, "Invalidated ProfileSwitch $it") + .blockingGet() + .also { result -> + result.inserted.forEach { + uel.log(Action.PROFILE_SWITCH, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp)) + aapsLogger.debug(LTag.DATABASE, "Inserted ProfileSwitch $it") + } + result.invalidated.forEach { + uel.log(Action.PROFILE_SWITCH_REMOVED, Sources.NSClient, + ValueWithUnit.Timestamp(it.timestamp)) + aapsLogger.debug(LTag.DATABASE, "Invalidated ProfileSwitch $it") + } + result.updatedNsId.forEach { + aapsLogger.debug(LTag.DATABASE, "Updated nsId ProfileSwitch $it") + } } - result.updatedNsId.forEach { - aapsLogger.debug(LTag.DATABASE, "Updated nsId ProfileSwitch $it") - } - } - } ?: aapsLogger.error("Error parsing ProfileSwitch json $json") + } ?: aapsLogger.error("Error parsing ProfileSwitch json $json") + } } - if (eventType == TherapyEvent.Type.ANNOUNCEMENT.text) { - val date = safeGetLong(json, "mills") - val now = System.currentTimeMillis() - val enteredBy = JsonHelper.safeGetString(json, "enteredBy", "") - val notes = JsonHelper.safeGetString(json, "notes", "") - if (date > now - 15 * 60 * 1000L && notes.isNotEmpty() - && enteredBy != sp.getString("careportal_enteredby", "AndroidAPS")) { - val defaultVal = config.NSCLIENT - if (sp.getBoolean(R.string.key_ns_announcements, defaultVal)) { - val announcement = Notification(Notification.NS_ANNOUNCEMENT, notes, Notification.ANNOUNCEMENT, 60) - rxBus.send(EventNewNotification(announcement)) + if (sp.getBoolean(R.string.key_ns_receive_therapy_events, false) || config.NSCLIENT) + if (eventType == TherapyEvent.Type.ANNOUNCEMENT.text) { + val date = safeGetLong(json, "mills") + val now = System.currentTimeMillis() + val enteredBy = JsonHelper.safeGetString(json, "enteredBy", "") + val notes = JsonHelper.safeGetString(json, "notes", "") + if (date > now - 15 * 60 * 1000L && notes.isNotEmpty() + && enteredBy != sp.getString("careportal_enteredby", "AndroidAPS")) { + val defaultVal = config.NSCLIENT + if (sp.getBoolean(R.string.key_ns_announcements, defaultVal)) { + val announcement = Notification(Notification.NS_ANNOUNCEMENT, notes, Notification.ANNOUNCEMENT, 60) + rxBus.send(EventNewNotification(announcement)) + } } } - } } nsClientPlugin.updateLatestDateReceivedIfNewer(latestDateInReceivedData) return ret diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientMbgWorker.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientMbgWorker.kt index a769f2ec38..8c73fd908f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientMbgWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientMbgWorker.kt @@ -8,13 +8,13 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.transactions.SyncNsTherapyEventTransaction +import info.nightscout.androidaps.extensions.therapyEventFromNsMbg import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg import info.nightscout.androidaps.receivers.DataWorker import info.nightscout.androidaps.utils.buildHelper.BuildHelper -import info.nightscout.androidaps.extensions.therapyEventFromNsMbg import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject @@ -33,7 +33,7 @@ class NSClientMbgWorker( override fun doWork(): Result { var ret = Result.success() - val acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, true) && buildHelper.isEngineeringMode() || config.NSCLIENT + val acceptNSData = sp.getBoolean(R.string.key_ns_receive_therapy_events, false) || config.NSCLIENT if (!acceptNSData) return ret val mbgArray = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.kt index 51bbf8f0c2..54bc13f0bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.kt @@ -8,6 +8,7 @@ import android.os.Handler import android.os.HandlerThread import android.os.IBinder import androidx.preference.PreferenceFragmentCompat +import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreference import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants @@ -147,25 +148,17 @@ class NSClientPlugin @Inject constructor( override fun preprocessPreferences(preferenceFragment: PreferenceFragmentCompat) { super.preprocessPreferences(preferenceFragment) if (config.NSCLIENT) { - val key_ns_uploadlocalprofile = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_uploadlocalprofile)) - if (key_ns_uploadlocalprofile != null) key_ns_uploadlocalprofile.isVisible = false - val key_ns_autobackfill = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_autobackfill)) - if (key_ns_autobackfill != null) key_ns_autobackfill.isVisible = false - val key_ns_create_announcements_from_errors = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_create_announcements_from_errors)) - if (key_ns_create_announcements_from_errors != null) key_ns_create_announcements_from_errors.isVisible = false - val key_ns_create_announcements_from_carbs_req = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_create_announcements_from_carbs_req)) - if (key_ns_create_announcements_from_carbs_req != null) key_ns_create_announcements_from_carbs_req.isVisible = false - val key_ns_upload_only = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_upload_only)) - if (key_ns_upload_only != null) { - key_ns_upload_only.isVisible = false - key_ns_upload_only.isEnabled = false - } - val key_ns_sync_use_absolute = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_sync_use_absolute)) - if (key_ns_sync_use_absolute != null) key_ns_sync_use_absolute.isVisible = false + preferenceFragment.findPreference(resourceHelper.gs(R.string.ns_sync_options))?.isVisible = false + + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_create_announcements_from_errors))?.isVisible = false + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_create_announcements_from_carbs_req))?.isVisible = false + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_sync_use_absolute))?.isVisible = false } else { // APS or pumpControl mode - val key_ns_upload_only = preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_upload_only)) - if (key_ns_upload_only != null) key_ns_upload_only.isVisible = buildHelper.isEngineeringMode() + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_receive_profile_switch))?.isVisible = buildHelper.isEngineeringMode() + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_receive_insulin))?.isVisible = buildHelper.isEngineeringMode() + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_receive_carbs))?.isVisible = buildHelper.isEngineeringMode() + preferenceFragment.findPreference(resourceHelper.gs(R.string.key_ns_receive_temp_target))?.isVisible = buildHelper.isEngineeringMode() } } @@ -232,7 +225,7 @@ class NSClientPlugin @Inject constructor( fun handleClearAlarm(originalAlarm: NSAlarm, silenceTimeInMilliseconds: Long) { if (!isEnabled(PluginType.GENERAL)) return - if (sp.getBoolean(R.string.key_ns_noupload, false)) { + if (!sp.getBoolean(R.string.key_ns_upload, false)) { aapsLogger.debug(LTag.NSCLIENT, "Upload disabled. Message dropped") return } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt index a2423de9ce..ee8dac6c47 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt @@ -42,8 +42,9 @@ class NSClientRemoveWorker( @Inject lateinit var uel: UserEntryLogger override fun doWork(): Result { - val acceptNSData = !sp.getBoolean(R.string.key_ns_upload_only, true) && buildHelper.isEngineeringMode() || config.NSCLIENT - if (!acceptNSData) return Result.success() + // Do not accept removed data over WS. Only invalidated trough NSClient + @Suppress("ConstantConditionIf") + if (true) return Result.success() var ret = Result.success() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt index a7bc375376..ad73e4160b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.kt @@ -36,7 +36,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNo import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction -import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin.NSProfileWorker +import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.plugins.source.NSClientSourcePlugin.NSClientSourceWorker import info.nightscout.androidaps.receivers.DataWorker import info.nightscout.androidaps.services.Intents @@ -472,7 +472,7 @@ class NSClientService : DaggerService() { val profileStoreJson = profiles[profiles.length() - 1] as JSONObject rxBus.send(EventNSClientNewLog("PROFILE", "profile received")) dataWorker.enqueue( - OneTimeWorkRequest.Builder(NSProfileWorker::class.java) + OneTimeWorkRequest.Builder(LocalProfilePlugin.NSProfileWorker::class.java) .setInputData(dataWorker.storeInputData(profileStoreJson, null)) .build()) if (sp.getBoolean(R.string.key_nsclient_localbroadcasts, false)) { @@ -652,18 +652,7 @@ class NSClientService : DaggerService() { wakeLock.acquire(mins(10).msecs()) try { rxBus.send(EventNSClientNewLog("QUEUE", "Resend started: $reason")) - dataSyncSelector.processChangedBolusesCompat() - dataSyncSelector.processChangedCarbsCompat() - dataSyncSelector.processChangedBolusCalculatorResultsCompat() - dataSyncSelector.processChangedTemporaryBasalsCompat() - dataSyncSelector.processChangedExtendedBolusesCompat() - dataSyncSelector.processChangedProfileSwitchesCompat() - dataSyncSelector.processChangedGlucoseValuesCompat() - dataSyncSelector.processChangedTempTargetsCompat() - dataSyncSelector.processChangedFoodsCompat() - dataSyncSelector.processChangedTherapyEventsCompat() - dataSyncSelector.processChangedDeviceStatusesCompat() - dataSyncSelector.processChangedProfileStore() + dataSyncSelector.doUpload() rxBus.send(EventNSClientNewLog("QUEUE", "Resend ended: $reason")) } finally { if (wakeLock.isHeld) wakeLock.release() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index 2487892414..31f01df6c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -54,6 +54,9 @@ class LocalProfileFragment : DaggerFragment() { private val save = Runnable { doEdit() basalView?.updateLabel(resourceHelper.gs(R.string.basal_label) + ": " + sumLabel()) + localProfilePlugin.profile?.getSpecificProfile(spinner?.selectedItem.toString())?.let { + binding.basalGraph.show(ProfileSealed.Pure(it)) + } } private val textWatch = object : TextWatcher { @@ -124,7 +127,7 @@ class LocalProfileFragment : DaggerFragment() { binding.dia.setParams(currentProfile.dia, hardLimits.minDia(), hardLimits.maxDia(), 0.1, DecimalFormat("0.0"), false, binding.save, textWatch) binding.dia.tag = "LP_DIA" TimeListEdit(context, aapsLogger, dateUtil, view, R.id.ic, "IC", resourceHelper.gs(R.string.ic_label), currentProfile.ic, null, hardLimits.minIC(), hardLimits.maxIC(), 0.1, DecimalFormat("0.0"), save) - basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.basal, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), currentProfile.basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save) + basalView = TimeListEdit(context, aapsLogger, dateUtil, view, R.id.basal_holder, "BASAL", resourceHelper.gs(R.string.basal_label) + ": " + sumLabel(), currentProfile.basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save) if (units == Constants.MGDL) { TimeListEdit(context, aapsLogger, dateUtil, view, R.id.isf, "ISF", resourceHelper.gs(R.string.isf_label), currentProfile.isf, null, HardLimits.MIN_ISF, HardLimits.MAX_ISF, 1.0, DecimalFormat("0"), save) TimeListEdit(context, aapsLogger, dateUtil, view, R.id.target, "TARGET", resourceHelper.gs(R.string.target_label), currentProfile.targetLow, currentProfile.targetHigh, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save) @@ -162,6 +165,9 @@ class LocalProfileFragment : DaggerFragment() { } } }) + localProfilePlugin.profile?.getSpecificProfile(spinner?.selectedItem.toString())?.let { + binding.basalGraph.show(ProfileSealed.Pure(it)) + } binding.profileAdd.setOnClickListener { if (localProfilePlugin.isEdited) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index f61cb713a6..86b56591ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -1,6 +1,10 @@ package info.nightscout.androidaps.plugins.profile.local +import android.content.Context import androidx.fragment.app.FragmentActivity +import androidx.work.Worker +import androidx.work.WorkerParameters +import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R @@ -12,6 +16,8 @@ import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged +import info.nightscout.androidaps.receivers.DataWorker import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HardLimits @@ -165,61 +171,64 @@ class LocalProfilePlugin @Inject constructor( p.dia = sp.getDouble(localProfileNumbered + "dia", Constants.defaultDIA) try { p.ic = JSONArray(sp.getString(localProfileNumbered + "ic", defaultArray)) - } catch (e1: JSONException) { - try { - p.ic = JSONArray(defaultArray) - } catch (ignored: JSONException) { - } - aapsLogger.error("Exception", e1) - } - - try { p.isf = JSONArray(sp.getString(localProfileNumbered + "isf", defaultArray)) - } catch (e1: JSONException) { - try { - p.isf = JSONArray(defaultArray) - } catch (ignored: JSONException) { - } - aapsLogger.error("Exception", e1) - } - - try { p.basal = JSONArray(sp.getString(localProfileNumbered + "basal", defaultArray)) - } catch (e1: JSONException) { - try { - p.basal = JSONArray(defaultArray) - } catch (ignored: JSONException) { - } - aapsLogger.error("Exception", e1) - } - - try { p.targetLow = JSONArray(sp.getString(localProfileNumbered + "targetlow", defaultArray)) - } catch (e1: JSONException) { - try { - p.targetLow = JSONArray(defaultArray) - } catch (ignored: JSONException) { - } - aapsLogger.error("Exception", e1) - } - - try { p.targetHigh = JSONArray(sp.getString(localProfileNumbered + "targethigh", defaultArray)) - } catch (e1: JSONException) { - try { - p.targetHigh = JSONArray(defaultArray) - } catch (ignored: JSONException) { - } - aapsLogger.error("Exception", e1) + profiles.add(p) + } catch (e: JSONException) { + aapsLogger.error("Exception", e) } - - profiles.add(p) } + // create at least one profile if doesn't exist + if (profiles.size < 1) profiles.add(defaultProfile()) isEdited = false numOfProfiles = profiles.size createAndStoreConvertedProfile() } + @Synchronized + fun loadFromStore(store: ProfileStore) { + try { + val newProfiles: ArrayList = ArrayList() + for (p in store.getProfileList()) { + store.getSpecificProfile(p.toString())?.let { + val sp = copyFrom(it, p.toString()) + sp.name = p.toString() + newProfiles.add(sp) + } + } + if (newProfiles.size > 0) { + profiles = newProfiles + numOfProfiles = profiles.size + currentProfileIndex = 0 + isEdited = false + createAndStoreConvertedProfile() + aapsLogger.debug(LTag.PROFILE, "Accepted ${profiles.size} profiles") + rxBus.send(EventLocalProfileChanged()) + } else + aapsLogger.debug(LTag.PROFILE, "ProfileStore not accepted") + } catch (e: Exception) { + aapsLogger.error("Error loading ProfileStore", e) + } + } + + private fun defaultProfile(): SingleProfile = + SingleProfile().also { p -> + p.name = Constants.LOCAL_PROFILE + p.mgdl = profileFunction.getUnits() == GlucoseUnit.MGDL + p.dia = Constants.defaultDIA + try { + p.ic = JSONArray(defaultArray) + p.isf = JSONArray(defaultArray) + p.basal = JSONArray(defaultArray) + p.targetLow = JSONArray(defaultArray) + p.targetHigh = JSONArray(defaultArray) + } catch (e: JSONException) { + aapsLogger.error("Exception", e) + } + } + fun copyFrom(pureProfile: PureProfile, newName: String): SingleProfile { var verifiedName = newName if (rawProfile?.getSpecificProfile(newName) != null) { @@ -378,4 +387,36 @@ class LocalProfilePlugin @Inject constructor( get() = rawProfile?.getDefaultProfile()?.let { DecimalFormatter.to2Decimal(ProfileSealed.Pure(it).percentageBasalSum()) + "U " } ?: "INVALID" + + // cannot be inner class because of needed injection + class NSProfileWorker( + context: Context, + params: WorkerParameters + ) : Worker(context, params) { + + @Inject lateinit var injector: HasAndroidInjector + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var rxBus: RxBusWrapper + @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var dataWorker: DataWorker + @Inject lateinit var sp: SP + @Inject lateinit var config: Config + @Inject lateinit var localProfilePlugin: LocalProfilePlugin + + init { + (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) + } + + override fun doWork(): Result { + val profileJson = dataWorker.pickupJSONObject(inputData.getLong(DataWorker.STORE_KEY, -1)) + ?: return Result.failure(workDataOf("Error" to "missing input data")) + if (sp.getBoolean(R.string.key_ns_receive_profile_store, false) || config.NSCLIENT) { + localProfilePlugin.loadFromStore(ProfileStore(injector, profileJson, dateUtil)) + aapsLogger.debug(LTag.PROFILE, "Received profileStore: $profileJson") + return Result.success(workDataOf("Data" to profileJson.toString())) + } + return Result.success() + } + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt deleted file mode 100644 index ea46599693..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfileFragment.kt +++ /dev/null @@ -1,170 +0,0 @@ -package info.nightscout.androidaps.plugins.profile.ns - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.ArrayAdapter -import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.R -import info.nightscout.androidaps.data.ProfileSealed -import info.nightscout.androidaps.database.entities.UserEntry.Action -import info.nightscout.androidaps.database.entities.UserEntry.Sources -import info.nightscout.androidaps.database.entities.ValueWithUnit -import info.nightscout.androidaps.databinding.NsprofileFragmentBinding -import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.androidaps.interfaces.Config -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.DecimalFormatter -import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.alertDialogs.OKDialog -import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.rx.AapsSchedulers -import io.reactivex.disposables.CompositeDisposable -import io.reactivex.rxkotlin.plusAssign -import javax.inject.Inject - -class NSProfileFragment : DaggerFragment() { - - @Inject lateinit var rxBus: RxBusWrapper - @Inject lateinit var resourceHelper: ResourceHelper - @Inject lateinit var fabricPrivacy: FabricPrivacy - @Inject lateinit var profileFunction: ProfileFunction - @Inject lateinit var nsProfilePlugin: NSProfilePlugin - @Inject lateinit var aapsSchedulers: AapsSchedulers - @Inject lateinit var dateUtil: DateUtil - @Inject lateinit var uel: UserEntryLogger - @Inject lateinit var activePlugin: ActivePlugin - @Inject lateinit var config: Config - - private var disposable: CompositeDisposable = CompositeDisposable() - - private var _binding: NsprofileFragmentBinding? = null - - // This property is only valid between onCreateView and - // onDestroyView. - private val binding get() = _binding!! - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { - _binding = NsprofileFragmentBinding.inflate(inflater, container, false) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.profileviewer.closeLayout.close.visibility = View.GONE // not needed for fragment - - binding.profileswitch.setOnClickListener { - val name = binding.spinner.selectedItem?.toString() ?: "" - nsProfilePlugin.profile?.let { store -> - store.getSpecificProfile(name)?.let { - activity?.let { activity -> - OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.nsprofile), - resourceHelper.gs(R.string.activate_profile) + ": " + name + " ?", Runnable { - uel.log(Action.PROFILE_SWITCH, Sources.NSProfile, - ValueWithUnit.SimpleString(name), - ValueWithUnit.Percent(100)) - profileFunction.createProfileSwitch(store, name, 0, 100, 0, dateUtil.now()) - }) - } - } - } - } - - binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onNothingSelected(parent: AdapterView<*>?) { - if (_binding == null) return - binding.profileviewer.invalidprofile.visibility = View.VISIBLE - binding.profileviewer.noprofile.visibility = View.VISIBLE - binding.profileviewer.units.text = "" - binding.profileviewer.dia.text = "" - binding.profileviewer.activeprofile.text = "" - binding.profileviewer.ic.text = "" - binding.profileviewer.isf.text = "" - binding.profileviewer.basal.text = "" - binding.profileviewer.basaltotal.text = "" - binding.profileviewer.target.text = "" - binding.profileswitch.visibility = View.GONE - } - - override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - if (_binding == null) return - val name = binding.spinner.getItemAtPosition(position).toString() - - binding.profileswitch.visibility = View.GONE - - nsProfilePlugin.profile?.let { store -> - store.getSpecificProfile(name)?.let { profile -> - if (_binding == null) return - val pss = ProfileSealed.Pure(profile) - binding.profileviewer.units.text = pss.units.asText - binding.profileviewer.dia.text = resourceHelper.gs(R.string.format_hours, pss.dia) - binding.profileviewer.activeprofile.text = name - binding.profileviewer.ic.text = pss.getIcList(resourceHelper, dateUtil) - binding.profileviewer.isf.text = pss.getIsfList(resourceHelper, dateUtil) - binding.profileviewer.basal.text = pss.getBasalList(resourceHelper, dateUtil) - binding.profileviewer.basaltotal.text = String.format(resourceHelper.gs(R.string.profile_total), DecimalFormatter.to2Decimal(pss.baseBasalSum())) - binding.profileviewer.target.text = pss.getTargetList(resourceHelper, dateUtil) - binding.profileviewer.basalGraph.show(pss) - if (pss.isValid("NSProfileFragment", activePlugin.activePump, config, resourceHelper, rxBus)) { - binding.profileviewer.invalidprofile.visibility = View.GONE - binding.profileswitch.visibility = View.VISIBLE - } else { - binding.profileviewer.invalidprofile.visibility = View.VISIBLE - binding.profileswitch.visibility = View.GONE - } - } - } - } - } - } - - @Synchronized - override fun onResume() { - super.onResume() - disposable += rxBus - .toObservable(EventNSProfileUpdateGUI::class.java) - .observeOn(aapsSchedulers.main) - .subscribe({ updateGUI() }, fabricPrivacy::logException) - updateGUI() - } - - @Synchronized - override fun onPause() { - super.onPause() - disposable.clear() - } - - @Synchronized - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - - @Synchronized - fun updateGUI() { - if (_binding == null) return - binding.profileviewer.noprofile.visibility = View.VISIBLE - - nsProfilePlugin.profile?.let { profileStore -> - context?.let { context -> - val profileList = profileStore.getProfileList() - val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList) - binding.spinner.adapter = adapter - // set selected to actual profile - for (p in profileList.indices) { - if (profileList[p] == profileFunction.getProfileName()) - binding.spinner.setSelection(p) - } - binding.profileviewer.noprofile.visibility = View.GONE - } - } - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.kt deleted file mode 100644 index e2cf6875a7..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.kt +++ /dev/null @@ -1,110 +0,0 @@ -package info.nightscout.androidaps.plugins.profile.ns - -import android.content.Context -import androidx.work.Worker -import androidx.work.WorkerParameters -import androidx.work.workDataOf -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.interfaces.Config -import info.nightscout.androidaps.R -import info.nightscout.androidaps.events.EventProfileStoreChanged -import info.nightscout.androidaps.interfaces.PluginBase -import info.nightscout.androidaps.interfaces.PluginDescription -import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.interfaces.ProfileSource -import info.nightscout.androidaps.interfaces.ProfileStore -import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart -import info.nightscout.androidaps.plugins.profile.ns.events.EventNSProfileUpdateGUI -import info.nightscout.androidaps.receivers.DataWorker -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.sharedPreferences.SP -import org.json.JSONObject -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class NSProfilePlugin @Inject constructor( - injector: HasAndroidInjector, - aapsLogger: AAPSLogger, - private val rxBus: RxBusWrapper, - resourceHelper: ResourceHelper, - private val sp: SP, - private val dateUtil: DateUtil, - config: Config -) : PluginBase(PluginDescription() - .mainType(PluginType.PROFILE) - .fragmentClass(NSProfileFragment::class.java.name) - .pluginIcon(R.drawable.ic_nightscout_profile) - .pluginName(R.string.nsprofile) - .shortName(R.string.profileviewer_shortname) - .alwaysEnabled(config.NSCLIENT) - .alwaysVisible(config.NSCLIENT) - .showInList(!config.NSCLIENT) - .description(R.string.description_profile_nightscout), - aapsLogger, resourceHelper, injector -), ProfileSource { - - override var profile: ProfileStore? = null - - override val profileName: String? - get() = profile?.getDefaultProfileName() - - override fun onStart() { - super.onStart() - loadNSProfile() - } - - private fun storeNSProfile() { - sp.putString("profile", profile!!.data.toString()) - aapsLogger.debug(LTag.PROFILE, "Storing profile") - } - - private fun loadNSProfile() { - aapsLogger.debug(LTag.PROFILE, "Loading stored profile") - val profileString = sp.getStringOrNull("profile", null) - if (profileString != null) { - aapsLogger.debug(LTag.PROFILE, "Loaded profile: $profileString") - profile = ProfileStore(injector, JSONObject(profileString), dateUtil) - } else { - aapsLogger.debug(LTag.PROFILE, "Stored profile not found") - // force restart of nsclient to fetch profile - rxBus.send(EventNSClientRestart()) - } - } - - - // cannot be inner class because of needed injection - class NSProfileWorker( - context: Context, - params: WorkerParameters - ) : Worker(context, params) { - - @Inject lateinit var injector: HasAndroidInjector - @Inject lateinit var nsProfilePlugin: NSProfilePlugin - @Inject lateinit var aapsLogger: AAPSLogger - @Inject lateinit var rxBus: RxBusWrapper - @Inject lateinit var dateUtil: DateUtil - @Inject lateinit var dataWorker: DataWorker - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { - val profileString = dataWorker.pickupJSONObject(inputData.getLong(DataWorker.STORE_KEY, -1)) - ?: return Result.failure(workDataOf("Error" to "missing input data")) - nsProfilePlugin.profile = ProfileStore(injector, profileString, dateUtil) - nsProfilePlugin.storeNSProfile() - if (nsProfilePlugin.isEnabled()) { - rxBus.send(EventProfileStoreChanged()) - rxBus.send(EventNSProfileUpdateGUI()) - } - aapsLogger.debug(LTag.PROFILE, "Received profileStore: ${nsProfilePlugin.profile}") - return Result.success() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.kt deleted file mode 100644 index 0d7c320876..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/events/EventNSProfileUpdateGUI.kt +++ /dev/null @@ -1,5 +0,0 @@ -package info.nightscout.androidaps.plugins.profile.ns.events - -import info.nightscout.androidaps.events.EventUpdateGui - -class EventNSProfileUpdateGUI : EventUpdateGui() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt index d9c2f221e5..52874bb335 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/NSClientSourcePlugin.kt @@ -5,12 +5,12 @@ import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.database.transactions.CgmSourceTransaction import info.nightscout.androidaps.interfaces.BgSource +import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType @@ -115,7 +115,7 @@ class NSClientSourcePlugin @Inject constructor( override fun doWork(): Result { var ret = Result.success() - if (!nsClientSourcePlugin.isEnabled() && !sp.getBoolean(R.string.key_ns_autobackfill, true) && !dexcomPlugin.isEnabled()) return Result.success() + if (!nsClientSourcePlugin.isEnabled() && !sp.getBoolean(R.string.key_ns_receive_cgm, true) && !dexcomPlugin.isEnabled()) return Result.success() val sgvs = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusCarbsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusCarbsFragment.kt index 9b846f613f..2ba8978ea8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusCarbsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsBolusCarbsFragment.kt @@ -156,7 +156,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() { }) } } - val nsUploadOnly = sp.getBoolean(R.string.key_ns_upload_only, true) || !buildHelper.isEngineeringMode() + val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_insulin, false) || !sp.getBoolean(R.string.key_ns_receive_carbs, false) || !buildHelper.isEngineeringMode() if (nsUploadOnly) binding.refreshFromNightscout.visibility = View.GONE binding.showInvalidated.setOnCheckedChangeListener { _, _ -> rxBus.send(EventTreatmentUpdateGui()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt index 4c90c80e08..ce75d4dc3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt @@ -102,7 +102,7 @@ class TreatmentsCareportalFragment : DaggerFragment() { } } - val nsUploadOnly = sp.getBoolean(R.string.key_ns_upload_only, true) || !buildHelper.isEngineeringMode() + val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_therapy_events, false) || !buildHelper.isEngineeringMode() if (nsUploadOnly) binding.refreshFromNightscout.visibility = View.GONE binding.showInvalidated.setOnCheckedChangeListener { _, _ -> rxBus.send(EventTreatmentUpdateGui()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt index 7e908b0d13..796c811f0f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsProfileSwitchFragment.kt @@ -99,7 +99,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() { } } } - if (sp.getBoolean(R.string.key_ns_upload_only, true) || !buildHelper.isEngineeringMode()) binding.refreshFromNightscout.visibility = View.GONE + if (!sp.getBoolean(R.string.key_ns_receive_profile_switch, false) || !buildHelper.isEngineeringMode()) binding.refreshFromNightscout.visibility = View.GONE binding.showInvalidated.setOnCheckedChangeListener { _, _ -> rxBus.send(EventTreatmentUpdateGui()) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt index e1465eac0e..d603263fc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt @@ -97,7 +97,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() { }) } } - val nsUploadOnly = sp.getBoolean(R.string.key_ns_upload_only, true) || !buildHelper.isEngineeringMode() + val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_temp_target, false) || !buildHelper.isEngineeringMode() if (nsUploadOnly) binding.refreshFromNightscout.visibility = View.INVISIBLE binding.showInvalidated.setOnCheckedChangeListener { _, _ -> rxBus.send(EventTreatmentUpdateGui()) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 5dd1283837..b65a284149 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -19,11 +19,8 @@ import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragm import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus -import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin -import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment -import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange import info.nightscout.androidaps.plugins.pump.omnipod.dash.OmnipodDashPumpPlugin import info.nightscout.androidaps.plugins.pump.omnipod.eros.OmnipodErosPumpPlugin @@ -53,7 +50,6 @@ class SWDefinition @Inject constructor( private val configBuilder: ConfigBuilder, private val loopPlugin: LoopPlugin, private val nsClientPlugin: NSClientPlugin, - private val nsProfilePlugin: NSProfilePlugin, private val importExportPrefs: ImportExportPrefs, private val androidPermission: AndroidPermission, private val cryptoUtil: CryptoUtil, @@ -254,25 +250,6 @@ class SWDefinition @Inject constructor( .option(PluginType.BGSOURCE, R.string.configbuilder_bgsource_description) .label(R.string.configbuilder_bgsource)) .add(SWBreak(injector)) - private val screenProfile = SWScreen(injector, R.string.configbuilder_profile) - .skippable(false) - .add(SWInfoText(injector) - .label(R.string.setupwizard_profile_description)) - .add(SWBreak(injector)) - .add(SWPlugin(injector, this) - .option(PluginType.PROFILE, R.string.configbuilder_profile_description) - .label(R.string.configbuilder_profile)) - private val screenNsProfile = SWScreen(injector, R.string.nsprofile) - .skippable(false) - .add(SWInfoText(injector) - .label(R.string.adjustprofileinns)) - .add(SWFragment(injector, this) - .add(NSProfileFragment())) - .validator { - nsProfilePlugin.profile?.getDefaultProfile()?.let { ProfileSealed.Pure(it).isValid("StartupWizard", activePlugin.activePump, config, resourceHelper, rxBus) } - ?: false - } - .visibility { nsProfilePlugin.isEnabled() } private val screenLocalProfile = SWScreen(injector, R.string.localprofile) .skippable(false) .add(SWFragment(injector, this) @@ -405,8 +382,6 @@ class SWDefinition @Inject constructor( .add(screenAge) .add(screenInsulin) .add(screenBgSource) - .add(screenProfile) - .add(screenNsProfile) .add(screenLocalProfile) .add(screenProfileSwitch) .add(screenPump) @@ -434,8 +409,6 @@ class SWDefinition @Inject constructor( .add(screenAge) .add(screenInsulin) .add(screenBgSource) - .add(screenProfile) - .add(screenNsProfile) .add(screenLocalProfile) .add(screenProfileSwitch) .add(screenPump) diff --git a/app/src/main/res/layout/localprofile_fragment.xml b/app/src/main/res/layout/localprofile_fragment.xml index 5893faa7b6..920d10f4ee 100644 --- a/app/src/main/res/layout/localprofile_fragment.xml +++ b/app/src/main/res/layout/localprofile_fragment.xml @@ -92,8 +92,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" - android:weightSum="5" - android:paddingBottom="10dp"> + android:paddingBottom="10dp" + android:weightSum="5"> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + android:text="@string/activate_profile" /> - - - - -