From 0f67f623849f139f8f7112f61bbd07e0a4855c37 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 11 Nov 2022 12:47:06 +0100 Subject: [PATCH] LoopDialog -> ui --- .../shared/src/main/res/values/strings.xml | 4 ++ app/src/main/AndroidManifest.xml | 3 - .../androidaps/di/ActivitiesModule.kt | 2 - .../androidaps/di/FragmentsModule.kt | 2 - .../plugins/configBuilder/PluginStore.kt | 3 + .../objectives/ObjectivesPlugin.kt | 25 ++++----- .../objectives/objectives/Objective.kt | 6 +- .../general/overview/OverviewFragment.kt | 6 +- .../androidaps/setupwizard/SWDefinition.kt | 7 ++- app/src/main/res/values/objectives.xml | 2 - app/src/main/res/values/strings.xml | 16 ------ .../androidaps/interfaces/ActivePlugin.kt | 6 ++ .../core-main/src/main/res/values/strings.xml | 7 +++ insight/src/main/res/values/strings.xml | 1 - .../interfaces/constraints/Objectives.kt | 19 +++++++ plugins/src/main/AndroidManifest.xml | 5 +- .../nightscout/plugins/di/SourceModule.kt | 3 + .../java/info/nightscout/ui/di/UiModule.kt | 2 + .../info/nightscout/ui}/dialogs/LoopDialog.kt | 55 +++++++++---------- .../src/main/res/layout/dialog_loop.xml | 0 ui/src/main/res/values/strings.xml | 17 +++++- 21 files changed, 107 insertions(+), 84 deletions(-) create mode 100644 interfaces/src/main/java/info/nightscout/interfaces/constraints/Objectives.kt rename {app/src/main/java/info/nightscout/androidaps => ui/src/main/java/info/nightscout/ui}/dialogs/LoopDialog.kt (90%) rename {app => ui}/src/main/res/layout/dialog_loop.xml (100%) diff --git a/app-wear-shared/shared/src/main/res/values/strings.xml b/app-wear-shared/shared/src/main/res/values/strings.xml index 0d9b555567..74ddc9cc0c 100644 --- a/app-wear-shared/shared/src/main/res/values/strings.xml +++ b/app-wear-shared/shared/src/main/res/values/strings.xml @@ -1,5 +1,9 @@ + insulin_button_increment_1 + insulin_button_increment_2 + insulin_button_increment_3 + %1$d m ago %1$d minutes ago diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1308a8b030..d6fb469bc4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -190,9 +190,6 @@ - = ArrayList() - companion object { - - const val FIRST_OBJECTIVE = 0 - @Suppress("unused") const val USAGE_OBJECTIVE = 1 - @Suppress("unused") const val EXAM_OBJECTIVE = 2 - @Suppress("unused") const val OPENLOOP_OBJECTIVE = 3 - @Suppress("unused") const val MAXBASAL_OBJECTIVE = 4 - const val MAXIOB_ZERO_CL_OBJECTIVE = 5 - @Suppress("unused") const val MAXIOB_OBJECTIVE = 6 - const val AUTOSENS_OBJECTIVE = 7 - const val SMB_OBJECTIVE = 8 - const val AUTO_OBJECTIVE = 9 - } - public override fun onStart() { super.onStart() setupObjectives() @@ -155,4 +148,6 @@ class ObjectivesPlugin @Inject constructor( value.set(aapsLogger, false, rh.gs(R.string.objectivenotstarted, AUTO_OBJECTIVE + 1), this) return value } + + override fun isAccomplished(index: Int) = objectives[Objectives.MAXIOB_OBJECTIVE].isAccomplished } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt index 830fb04c77..c30bdf7fe0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.constraints.objectives.objectives import android.content.Context -import android.graphics.Color import android.text.util.Linkify import android.widget.CheckBox import android.widget.TextView @@ -9,11 +8,10 @@ import androidx.annotation.StringRes import androidx.fragment.app.FragmentActivity import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.shared.utils.DateUtil -import info.nightscout.shared.utils.T import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP -import java.util.* +import info.nightscout.shared.utils.DateUtil +import info.nightscout.shared.utils.T import javax.inject.Inject import kotlin.math.floor 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 eccf93ed99..723cd41dec 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,9 +30,6 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.R import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.databinding.OverviewFragmentBinding -import info.nightscout.androidaps.dialogs.LoopDialog -import info.nightscout.ui.dialogs.ProfileSwitchDialog -import info.nightscout.ui.dialogs.TempTargetDialog import info.nightscout.androidaps.dialogs.WizardDialog import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged import info.nightscout.androidaps.events.EventNewBG @@ -111,6 +108,9 @@ import info.nightscout.shared.utils.DateUtil import info.nightscout.ui.dialogs.CalibrationDialog import info.nightscout.ui.dialogs.CarbsDialog import info.nightscout.ui.dialogs.InsulinDialog +import info.nightscout.ui.dialogs.LoopDialog +import info.nightscout.ui.dialogs.ProfileSwitchDialog +import info.nightscout.ui.dialogs.TempTargetDialog import info.nightscout.ui.dialogs.TreatmentDialog import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign 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 42dc57822c..ded3471ea3 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -9,7 +9,6 @@ import androidx.appcompat.app.AppCompatActivity import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.data.ProfileSealed -import info.nightscout.ui.dialogs.ProfileSwitchDialog import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.CommandQueue @@ -40,6 +39,7 @@ import info.nightscout.interfaces.AndroidPermission import info.nightscout.interfaces.Config import info.nightscout.interfaces.ConfigBuilder import info.nightscout.interfaces.Constants +import info.nightscout.interfaces.constraints.Objectives import info.nightscout.interfaces.maintenance.ImportExportPrefs import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.utils.HardLimits @@ -49,6 +49,7 @@ import info.nightscout.plugins.sync.nsShared.events.EventNSClientStatus import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP +import info.nightscout.ui.dialogs.ProfileSwitchDialog import javax.inject.Inject import javax.inject.Singleton @@ -439,8 +440,8 @@ class SWDefinition @Inject constructor( SWFragment(injector, this) .add(ObjectivesFragment()) ) - .validator { objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted } - .visibility { !objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted && config.APS } + .validator { objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].isStarted } + .visibility { !objectivesPlugin.objectives[Objectives.FIRST_OBJECTIVE].isStarted && config.APS } private fun swDefinitionFull() { // List all the screens here add(screenSetupWizard) diff --git a/app/src/main/res/values/objectives.xml b/app/src/main/res/values/objectives.xml index 49da5eda10..e8419700a8 100644 --- a/app/src/main/res/values/objectives.xml +++ b/app/src/main/res/values/objectives.xml @@ -1,7 +1,5 @@ - ObjectivesDisconnectUsed - ObjectivesReconnectUsed ObjectivesActionsUsed ObjectivesLoopUsed ObjectivesScaleUsed diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 31773891b2..c034ddf27a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -101,9 +101,6 @@ BG Source Where should AAPS gain it\'s data from? APS Mode - Closed Loop - Open Loop - Low Glucose Suspend New suggestion available Carbs Suggestion Carb time @@ -210,24 +207,12 @@ Patient name Please provide patient name or nickname to differentiate among multiple setups I_understand - Suspend loop for 1h - Suspend loop for 2h - Suspend loop for 3h - Suspend loop for 10 h - Disconnect pump - Disconnect pump for 15 min - Disconnect pump for 30 min - Disconnect pump for 1 h - Disconnect pump for 2 h - Disconnect pump for 3 h 15 mins 30 mins 1 hour 2 hours 3 hours 10 hours - Resume - Reconnect Pump Exiting application to apply settings. Which type of insulin are you using? key_usersuperbolus @@ -497,7 +482,6 @@ Miscellaneous Log settings Reset to defaults - aps_mode Preferred APS mode Send today\'s log files to developers along with this time. Unexpected situation. Minimal request change [%] diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt b/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt index 04b2f35a7e..23f309bb72 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt +++ b/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/ActivePlugin.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.interfaces import info.nightscout.interfaces.Overview +import info.nightscout.interfaces.constraints.Objectives import info.nightscout.interfaces.constraints.Safety import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.plugin.PluginBase @@ -66,6 +67,11 @@ interface ActivePlugin { */ val activeIobCobCalculator: IobCobCalculator + /** + * Objectives plugin + */ + val activeObjectives: Objectives? + /** * Currently selected NsClient plugin */ diff --git a/core/core-main/src/main/res/values/strings.xml b/core/core-main/src/main/res/values/strings.xml index 658d857276..31d34bda21 100644 --- a/core/core-main/src/main/res/values/strings.xml +++ b/core/core-main/src/main/res/values/strings.xml @@ -93,6 +93,9 @@ ns_receive_temp_target ObjectivesProfileSwitchUsed ObjectivesTempTargetUsed + ObjectivesDisconnectUsed + ObjectivesReconnectUsed + aps_mode Refresh @@ -259,6 +262,10 @@ Prime/Fill Insulin Stop temp target + Closed Loop + Open Loop + Low Glucose Suspend + Confirm Limiting max basal rate to %1$.2f U/h because of %2$s diff --git a/insight/src/main/res/values/strings.xml b/insight/src/main/res/values/strings.xml index ece7a4902a..a4dc38328e 100644 --- a/insight/src/main/res/values/strings.xml +++ b/insight/src/main/res/values/strings.xml @@ -59,7 +59,6 @@ TDD: %1$.2f Reser.: %1$.2f U Batt.: %1$d%% - Confirm Mute Release software version UI processor software version diff --git a/interfaces/src/main/java/info/nightscout/interfaces/constraints/Objectives.kt b/interfaces/src/main/java/info/nightscout/interfaces/constraints/Objectives.kt new file mode 100644 index 0000000000..f88e94dfe9 --- /dev/null +++ b/interfaces/src/main/java/info/nightscout/interfaces/constraints/Objectives.kt @@ -0,0 +1,19 @@ +package info.nightscout.interfaces.constraints + +interface Objectives { + companion object { + + const val FIRST_OBJECTIVE = 0 + @Suppress("unused") const val USAGE_OBJECTIVE = 1 + @Suppress("unused") const val EXAM_OBJECTIVE = 2 + @Suppress("unused") const val OPENLOOP_OBJECTIVE = 3 + @Suppress("unused") const val MAXBASAL_OBJECTIVE = 4 + const val MAXIOB_ZERO_CL_OBJECTIVE = 5 + @Suppress("unused") const val MAXIOB_OBJECTIVE = 6 + const val AUTOSENS_OBJECTIVE = 7 + const val SMB_OBJECTIVE = 8 + const val AUTO_OBJECTIVE = 9 + } + + fun isAccomplished(index: Int): Boolean +} \ No newline at end of file diff --git a/plugins/src/main/AndroidManifest.xml b/plugins/src/main/AndroidManifest.xml index 4f28ee4e97..c580c2b98a 100644 --- a/plugins/src/main/AndroidManifest.xml +++ b/plugins/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ @@ -18,6 +18,9 @@ + { + loop.isDisconnected -> { binding.overviewLoop.visibility = View.GONE binding.overviewSuspend.visibility = View.GONE binding.overviewPump.visibility = View.VISIBLE @@ -191,7 +188,7 @@ class LoopDialog : DaggerDialogFragment() { binding.overviewReconnect.visibility = View.VISIBLE } - !(loop as PluginBase).isEnabled() -> { + !(loop as PluginBase).isEnabled() -> { binding.overviewLoop.visibility = View.VISIBLE binding.overviewEnable.visibility = View.VISIBLE binding.overviewDisable.visibility = View.GONE @@ -200,7 +197,7 @@ class LoopDialog : DaggerDialogFragment() { binding.overviewReconnect.visibility = View.GONE } - loop.isSuspended -> { + loop.isSuspended -> { binding.overviewLoop.visibility = View.GONE binding.overviewSuspend.visibility = View.VISIBLE binding.overviewSuspendHeader.text = rh.gs(R.string.resumeloop) @@ -284,28 +281,28 @@ class LoopDialog : DaggerDialogFragment() { fun onClick(v: View): Boolean { when (v.id) { R.id.overview_closeloop -> { - uel.log(Action.CLOSED_LOOP_MODE, Sources.LoopDialog) + uel.log(UserEntry.Action.CLOSED_LOOP_MODE, UserEntry.Sources.LoopDialog) sp.putString(R.string.key_aps_mode, "closed") rxBus.send(EventPreferenceChange(rh.gs(R.string.closedloop))) return true } R.id.overview_lgsloop -> { - uel.log(Action.LGS_LOOP_MODE, Sources.LoopDialog) + uel.log(UserEntry.Action.LGS_LOOP_MODE, UserEntry.Sources.LoopDialog) sp.putString(R.string.key_aps_mode, "lgs") rxBus.send(EventPreferenceChange(rh.gs(R.string.lowglucosesuspend))) return true } R.id.overview_openloop -> { - uel.log(Action.OPEN_LOOP_MODE, Sources.LoopDialog) + uel.log(UserEntry.Action.OPEN_LOOP_MODE, UserEntry.Sources.LoopDialog) sp.putString(R.string.key_aps_mode, "open") rxBus.send(EventPreferenceChange(rh.gs(R.string.lowglucosesuspend))) return true } R.id.overview_disable -> { - uel.log(Action.LOOP_DISABLED, Sources.LoopDialog) + uel.log(UserEntry.Action.LOOP_DISABLED, UserEntry.Sources.LoopDialog) (loop as PluginBase).setPluginEnabled(PluginType.LOOP, false) (loop as PluginBase).setFragmentVisible(PluginType.LOOP, false) configBuilder.storeSettings("DisablingLoop") @@ -328,7 +325,7 @@ class LoopDialog : DaggerDialogFragment() { } R.id.overview_enable -> { - uel.log(Action.LOOP_ENABLED, Sources.LoopDialog) + uel.log(UserEntry.Action.LOOP_ENABLED, UserEntry.Sources.LoopDialog) (loop as PluginBase).setPluginEnabled(PluginType.LOOP, true) (loop as PluginBase).setFragmentVisible(PluginType.LOOP, true) configBuilder.storeSettings("EnablingLoop") @@ -343,7 +340,7 @@ class LoopDialog : DaggerDialogFragment() { } R.id.overview_resume, R.id.overview_reconnect -> { - uel.log(if (v.id == R.id.overview_resume) Action.RESUME else Action.RECONNECT, Sources.LoopDialog) + uel.log(if (v.id == R.id.overview_resume) UserEntry.Action.RESUME else UserEntry.Action.RECONNECT, UserEntry.Sources.LoopDialog) disposable += repository.runTransactionForResult(CancelCurrentOfflineEventIfAnyTransaction(dateUtil.now())) .subscribe({ result -> result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated OfflineEvent $it") } @@ -363,28 +360,28 @@ class LoopDialog : DaggerDialogFragment() { } R.id.overview_suspend_1h -> { - uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(1)) + uel.log(UserEntry.Action.SUSPEND, UserEntry.Sources.LoopDialog, ValueWithUnit.Hour(1)) loop.suspendLoop(T.hours(1).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true } R.id.overview_suspend_2h -> { - uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(2)) + uel.log(UserEntry.Action.SUSPEND, UserEntry.Sources.LoopDialog, ValueWithUnit.Hour(2)) loop.suspendLoop(T.hours(2).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true } R.id.overview_suspend_3h -> { - uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(3)) + uel.log(UserEntry.Action.SUSPEND, UserEntry.Sources.LoopDialog, ValueWithUnit.Hour(3)) loop.suspendLoop(T.hours(3).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true } R.id.overview_suspend_10h -> { - uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(10)) + uel.log(UserEntry.Action.SUSPEND, UserEntry.Sources.LoopDialog, ValueWithUnit.Hour(10)) loop.suspendLoop(T.hours(10).mins().toInt()) rxBus.send(EventRefreshOverview("suspend_menu")) return true @@ -392,7 +389,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_15m -> { profileFunction.getProfile()?.let { profile -> - uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(15)) + uel.log(UserEntry.Action.DISCONNECT, UserEntry.Sources.LoopDialog, ValueWithUnit.Minute(15)) loop.goToZeroTemp(T.mins(15).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } @@ -401,7 +398,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_30m -> { profileFunction.getProfile()?.let { profile -> - uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(30)) + uel.log(UserEntry.Action.DISCONNECT, UserEntry.Sources.LoopDialog, ValueWithUnit.Minute(30)) loop.goToZeroTemp(T.mins(30).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } @@ -410,7 +407,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_1h -> { profileFunction.getProfile()?.let { profile -> - uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(1)) + uel.log(UserEntry.Action.DISCONNECT, UserEntry.Sources.LoopDialog, ValueWithUnit.Hour(1)) loop.goToZeroTemp(T.hours(1).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } @@ -420,7 +417,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_2h -> { profileFunction.getProfile()?.let { profile -> - uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(2)) + uel.log(UserEntry.Action.DISCONNECT, UserEntry.Sources.LoopDialog, ValueWithUnit.Hour(2)) loop.goToZeroTemp(T.hours(2).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } @@ -429,7 +426,7 @@ class LoopDialog : DaggerDialogFragment() { R.id.overview_disconnect_3h -> { profileFunction.getProfile()?.let { profile -> - uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(3)) + uel.log(UserEntry.Action.DISCONNECT, UserEntry.Sources.LoopDialog, ValueWithUnit.Hour(3)) loop.goToZeroTemp(T.hours(3).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP) rxBus.send(EventRefreshOverview("suspend_menu")) } @@ -461,8 +458,8 @@ class LoopDialog : DaggerDialogFragment() { ToastUtils.warnToast(ctx, R.string.dialog_canceled) dismiss() } - protectionCheck.queryProtection(activity, BOLUS, { queryingProtection = false }, cancelFail, cancelFail) + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, { queryingProtection = false }, cancelFail, cancelFail) } } } -} +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_loop.xml b/ui/src/main/res/layout/dialog_loop.xml similarity index 100% rename from app/src/main/res/layout/dialog_loop.xml rename to ui/src/main/res/layout/dialog_loop.xml diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index 76251d8f15..17809bf85b 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -59,9 +59,6 @@ Record insulin cartridge change - insulin_button_increment_1 - insulin_button_increment_2 - insulin_button_increment_3 Do not bolus, record only Bolus will be recorded only (not delivered by pump) @@ -69,6 +66,20 @@ Reuse %1$d%% %2$dh Time shift + + Suspend loop for 1h + Suspend loop for 2h + Suspend loop for 3h + Suspend loop for 10 h + Disconnect pump + Disconnect pump for 15 min + Disconnect pump for 30 min + Disconnect pump for 1 h + Disconnect pump for 2 h + Disconnect pump for 3 h + Resume + Reconnect Pump + No records available Calc