Allow to continue in Setup Wizard when Omnipod has been selected and a RL connection has been established

This commit is contained in:
Bart Sopers 2020-09-05 04:26:22 +02:00
parent 1d3f4d3591
commit 503fc9dbf9
4 changed files with 48 additions and 11 deletions

View file

@ -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)

View file

@ -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())

View file

@ -946,6 +946,9 @@
<string name="bgsourcesetup">Configure BG source</string>
<string name="setupwizard_profile_description">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\"</string>
<string name="setupwizard_aps_description">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.</string>
<string name="setupwizard_pump_waiting_for_riley_link_connection">Waiting for RileyLink connection\n</string>
<string name="setupwizard_pump_pump_not_initialized"><b>Note:</b> You can continue setup once the pump has been initialized.\n</string>
<string name="setupwizard_pump_omnipod_init_pod">Init Pod</string>
<string name="startobjective">Start your first objective</string>
<string name="permission">Permission</string>
<string name="askforpermission">Ask for permission</string>

View file

@ -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