From 503fc9dbf94139eab690e9fb84b7d628c5f692e2 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sat, 5 Sep 2020 04:26:22 +0200 Subject: [PATCH] Allow to continue in Setup Wizard when Omnipod has been selected and a RL connection has been established --- .../androidaps/setupwizard/SWDefinition.kt | 34 ++++++++++++++----- .../setupwizard/SetupWizardActivity.kt | 12 +++++-- app/src/main/res/values/strings.xml | 3 ++ .../pump/omnipod/OmnipodPumpPlugin.java | 10 ++++++ 4 files changed, 48 insertions(+), 11 deletions(-) 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 73cd2d6e37..0cde09f2f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -12,14 +12,10 @@ import info.nightscout.androidaps.activities.PreferencesActivity import info.nightscout.androidaps.dialogs.ProfileSwitchDialog import info.nightscout.androidaps.events.EventConfigBuilderChange import info.nightscout.androidaps.events.EventPumpStatusChanged -import info.nightscout.androidaps.interfaces.ActivePluginProvider -import info.nightscout.androidaps.interfaces.CommandQueueProvider -import info.nightscout.androidaps.interfaces.PluginBase -import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs @@ -30,12 +26,13 @@ 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.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.setupwizard.elements.* import info.nightscout.androidaps.setupwizard.events.EventSWUpdate import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.CryptoUtil -import info.nightscout.androidaps.utils.locale.LocaleHelper.update import info.nightscout.androidaps.utils.extensions.isRunningTest +import info.nightscout.androidaps.utils.locale.LocaleHelper.update import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -302,6 +299,18 @@ class SWDefinition @Inject constructor( .option(PluginType.PUMP, R.string.configbuilder_pump_description) .label(R.string.configbuilder_pump)) .add(SWBreak(injector)) + .add(SWInfotext(injector) + .label(R.string.setupwizard_pump_pump_not_initialized) + .visibility(SWValidator { !isPumpInitialized(activePlugin.activePump) })) + // BEGIN OMNIPOD + .add(SWInfotext(injector) + .label(R.string.setupwizard_pump_waiting_for_riley_link_connection) + .visibility(SWValidator { + val activePump = activePlugin.activePump + activePump is OmnipodPumpPlugin && !activePump.isRileyLinkReady + })) + // TODO after refactoring Pod (de)activation Wizards, start init Pod activity from here + // END OMNIPOD .add(SWButton(injector) .text(R.string.pumpsetup) .action(Runnable { @@ -315,9 +324,18 @@ class SWDefinition @Inject constructor( .visibility(SWValidator { (activePlugin.activePump as PluginBase).preferencesId > 0 })) .add(SWButton(injector) .text(R.string.readstatus) - .action(Runnable { commandQueue.readStatus("Clicked connect to pump", null) })) + .action(Runnable { commandQueue.readStatus("Clicked connect to pump", null) }) + .visibility(SWValidator { activePlugin.activePump !is OmnipodPumpPlugin })) .add(SWEventListener(injector, EventPumpStatusChanged::class.java)) - .validator(SWValidator { activePlugin.activePump.isInitialized }) + .validator(SWValidator { + val activePump = activePlugin.activePump + isPumpInitialized(activePump) + }) + + private fun isPumpInitialized(activePump: PumpInterface) = + activePump.isInitialized + || (activePump is OmnipodPumpPlugin && activePump.isRileyLinkReady) + private val screenAps = SWScreen(injector, R.string.configbuilder_aps) .skippable(false) .add(SWInfotext(injector) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt index 44af0e1312..f2d763e32e 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt @@ -16,13 +16,14 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin +import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange import info.nightscout.androidaps.setupwizard.elements.SWItem import info.nightscout.androidaps.setupwizard.events.EventSWUpdate import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.locale.LocaleHelper.update import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation +import info.nightscout.androidaps.utils.locale.LocaleHelper.update import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.android.schedulers.AndroidSchedulers @@ -81,6 +82,11 @@ class SetupWizardActivity : NoSplashAppCompatActivity() { .observeOn(AndroidSchedulers.mainThread()) .subscribe({ updateButtons() }) { fabricPrivacy.logException(it) } ) + disposable.add(rxBus + .toObservable(EventRileyLinkDeviceStatusChange::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ updateButtons() }) { fabricPrivacy.logException(it) } + ) disposable.add(rxBus .toObservable(EventNSClientStatus::class.java) .observeOn(AndroidSchedulers.mainThread()) @@ -172,7 +178,7 @@ class SetupWizardActivity : NoSplashAppCompatActivity() { finish() } - @Suppress("UNUSED_PARAMETER","SameParameterValue") + @Suppress("UNUSED_PARAMETER", "SameParameterValue") private fun nextPage(view: View?): Int { var page = currentWizardPage + 1 while (page < screens.size) { @@ -182,7 +188,7 @@ class SetupWizardActivity : NoSplashAppCompatActivity() { return min(currentWizardPage, screens.size - 1) } - @Suppress("UNUSED_PARAMETER","SameParameterValue") + @Suppress("UNUSED_PARAMETER", "SameParameterValue") private fun previousPage(view: View?): Int { var page = currentWizardPage - 1 while (page >= 0) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a804dc395d..60ce679897 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -946,6 +946,9 @@ Configure BG source Please select source of profile. If patient is a child you should use NS profile. If there is nobody following you on Nightscout you will probably prefer Local profile. Please remember that you are only selecting the profile source. To use it you must activate it by executing \"Profile switch\" Select one from availables algorithms. They are sorted from oldest to newest. Newer algorithm is usually more powerful and more aggressive. Thus if you are new looper you may probably start with AMA and not with latest one. Do not forget to read the OpenAPS documentation and configure it before use. + Waiting for RileyLink connection\n + Note: You can continue setup once the pump has been initialized.\n + Init Pod Start your first objective Permission Ask for permission diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index ffdc74eb19..eae6f63730 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -316,6 +316,16 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, ); } + public boolean isRileyLinkReady() { + return rileyLinkServiceData.rileyLinkServiceState.isReady(); + } + + public boolean needsPodActivation() { + // don't use PodStateManager.isActivationCompleted() because that returns false for PodProgressStatus.ACTIVATION_TIME_EXCEEDED + // which indicates that the pod should be deactivated rather then activated + return !podStateManager.isPodInitialized() || podStateManager.getPodProgressStatus().isBefore(PodProgressStatus.ABOVE_FIFTY_UNITS); + } + private void updateAapsTbr() { // As per the characteristics of the Omnipod, we only know whether or not a TBR is currently active // But it doesn't tell us the duration or amount, so we can only update TBR status in AAPS if