Improve retry activation
This commit is contained in:
parent
3b0ac0b1cb
commit
b6272cfea7
3 changed files with 59 additions and 35 deletions
|
@ -43,14 +43,22 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
|
||||||
PatchStep.ATTACH_PATCH -> setupViewFragment(MedtrumAttachPatchFragment.newInstance())
|
PatchStep.ATTACH_PATCH -> setupViewFragment(MedtrumAttachPatchFragment.newInstance())
|
||||||
PatchStep.ACTIVATE -> setupViewFragment(MedtrumActivateFragment.newInstance())
|
PatchStep.ACTIVATE -> setupViewFragment(MedtrumActivateFragment.newInstance())
|
||||||
PatchStep.ACTIVATE_COMPLETE -> setupViewFragment(MedtrumActivateCompleteFragment.newInstance())
|
PatchStep.ACTIVATE_COMPLETE -> setupViewFragment(MedtrumActivateCompleteFragment.newInstance())
|
||||||
PatchStep.CANCEL,
|
|
||||||
PatchStep.COMPLETE -> this@MedtrumActivity.finish()
|
|
||||||
PatchStep.ERROR -> Unit // Do nothing, let activity handle this
|
PatchStep.ERROR -> Unit // Do nothing, let activity handle this
|
||||||
PatchStep.RETRY_ACTIVATION -> setupViewFragment(MedtrumRetryActivationFragment.newInstance())
|
PatchStep.RETRY_ACTIVATION -> setupViewFragment(MedtrumRetryActivationFragment.newInstance())
|
||||||
PatchStep.RETRY_ACTIVATION_CONNECT -> setupViewFragment(MedtrumRetryActivationConnectFragment.newInstance())
|
PatchStep.RETRY_ACTIVATION_CONNECT -> setupViewFragment(MedtrumRetryActivationConnectFragment.newInstance())
|
||||||
PatchStep.START_DEACTIVATION -> setupViewFragment(MedtrumStartDeactivationFragment.newInstance())
|
PatchStep.START_DEACTIVATION -> setupViewFragment(MedtrumStartDeactivationFragment.newInstance())
|
||||||
PatchStep.DEACTIVATE -> setupViewFragment(MedtrumDeactivatePatchFragment.newInstance())
|
PatchStep.DEACTIVATE -> setupViewFragment(MedtrumDeactivatePatchFragment.newInstance())
|
||||||
|
|
||||||
|
PatchStep.CANCEL -> {
|
||||||
|
handleCancel()
|
||||||
|
this@MedtrumActivity.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
PatchStep.COMPLETE -> {
|
||||||
|
handleComplete()
|
||||||
|
this@MedtrumActivity.finish()
|
||||||
|
}
|
||||||
|
|
||||||
PatchStep.FORCE_DEACTIVATION -> {
|
PatchStep.FORCE_DEACTIVATION -> {
|
||||||
medtrumPump.pumpState = MedtrumPumpState.STOPPED
|
medtrumPump.pumpState = MedtrumPumpState.STOPPED
|
||||||
moveStep(PatchStep.DEACTIVATION_COMPLETE)
|
moveStep(PatchStep.DEACTIVATION_COMPLETE)
|
||||||
|
|
|
@ -34,15 +34,17 @@ class MedtrumRetryActivationConnectFragment : MedtrumBaseFragment<FragmentMedtru
|
||||||
viewModel?.apply {
|
viewModel?.apply {
|
||||||
|
|
||||||
setupStep.observe(viewLifecycleOwner) {
|
setupStep.observe(viewLifecycleOwner) {
|
||||||
when (it) {
|
if (patchStep.value != PatchStep.CANCEL) {
|
||||||
MedtrumViewModel.SetupStep.INITIAL -> Unit // Nothing to do here
|
when (it) {
|
||||||
MedtrumViewModel.SetupStep.FILLED -> forceMoveStep(PatchStep.PRIME)
|
MedtrumViewModel.SetupStep.INITIAL -> Unit // Nothing to do here
|
||||||
MedtrumViewModel.SetupStep.PRIMING -> forceMoveStep(PatchStep.PRIMING)
|
MedtrumViewModel.SetupStep.FILLED -> forceMoveStep(PatchStep.PRIME)
|
||||||
MedtrumViewModel.SetupStep.PRIMED -> forceMoveStep(PatchStep.PRIME_COMPLETE)
|
MedtrumViewModel.SetupStep.PRIMING -> forceMoveStep(PatchStep.PRIMING)
|
||||||
MedtrumViewModel.SetupStep.ACTIVATED -> forceMoveStep(PatchStep.ACTIVATE_COMPLETE)
|
MedtrumViewModel.SetupStep.PRIMED -> forceMoveStep(PatchStep.PRIME_COMPLETE)
|
||||||
|
MedtrumViewModel.SetupStep.ACTIVATED -> forceMoveStep(PatchStep.ACTIVATE_COMPLETE)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
aapsLogger.error(LTag.PUMP, "Unexpected state: $it")
|
aapsLogger.error(LTag.PUMP, "Unexpected state: $it")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ class MedtrumViewModel @Inject constructor(
|
||||||
val eventHandler: LiveData<UIEvent<EventType>>
|
val eventHandler: LiveData<UIEvent<EventType>>
|
||||||
get() = _eventHandler
|
get() = _eventHandler
|
||||||
|
|
||||||
|
private var oldPatchStep: PatchStep? = null
|
||||||
private var mInitPatchStep: PatchStep? = null
|
private var mInitPatchStep: PatchStep? = null
|
||||||
private var connectRetryCounter = 0
|
private var connectRetryCounter = 0
|
||||||
|
|
||||||
|
@ -135,52 +136,41 @@ class MedtrumViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun moveStep(newPatchStep: PatchStep) {
|
fun moveStep(newPatchStep: PatchStep) {
|
||||||
val oldPatchStep = patchStep.value
|
oldPatchStep = patchStep.value
|
||||||
|
|
||||||
if (oldPatchStep != newPatchStep) {
|
if (oldPatchStep != newPatchStep) {
|
||||||
when (newPatchStep) {
|
when (newPatchStep) {
|
||||||
PatchStep.CANCEL -> {
|
PatchStep.CANCEL,
|
||||||
if (oldPatchStep !in listOf(
|
PatchStep.COMPLETE,
|
||||||
PatchStep.PREPARE_PATCH,
|
PatchStep.ACTIVATE_COMPLETE,
|
||||||
PatchStep.START_DEACTIVATION,
|
PatchStep.ERROR,
|
||||||
PatchStep.DEACTIVATE,
|
|
||||||
PatchStep.FORCE_DEACTIVATION,
|
|
||||||
PatchStep.DEACTIVATION_COMPLETE
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
medtrumService?.disconnect("Cancel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PatchStep.COMPLETE -> {
|
|
||||||
medtrumService?.disconnect("Complete")
|
|
||||||
}
|
|
||||||
|
|
||||||
PatchStep.START_DEACTIVATION,
|
PatchStep.START_DEACTIVATION,
|
||||||
PatchStep.DEACTIVATE,
|
PatchStep.DEACTIVATE,
|
||||||
PatchStep.FORCE_DEACTIVATION,
|
PatchStep.FORCE_DEACTIVATION,
|
||||||
PatchStep.DEACTIVATION_COMPLETE,
|
PatchStep.DEACTIVATION_COMPLETE,
|
||||||
PatchStep.PREPARE_PATCH,
|
PatchStep.PREPARE_PATCH,
|
||||||
PatchStep.RETRY_ACTIVATION,
|
PatchStep.RETRY_ACTIVATION -> {
|
||||||
PatchStep.RETRY_ACTIVATION_CONNECT -> {
|
// Do nothing, these steps don't require a connection
|
||||||
// Do nothing, deactivation uses commandQueue to control connection
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PatchStep.PREPARE_PATCH_CONNECT -> {
|
PatchStep.RETRY_ACTIVATION_CONNECT,
|
||||||
|
PatchStep.PREPARE_PATCH_CONNECT -> {
|
||||||
// Make sure we are disconnected, else dont move step
|
// Make sure we are disconnected, else dont move step
|
||||||
if (medtrumService?.isConnected == true) {
|
if (medtrumService?.isConnected == true) {
|
||||||
aapsLogger.info(LTag.PUMP, "moveStep: connected, not moving step")
|
aapsLogger.info(LTag.PUMP, "moveStep: connected, not moving step")
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
PatchStep.PRIME,
|
||||||
|
PatchStep.PRIMING,
|
||||||
|
PatchStep.PRIME_COMPLETE,
|
||||||
|
PatchStep.ATTACH_PATCH,
|
||||||
|
PatchStep.ACTIVATE -> {
|
||||||
// Make sure we are connected, else dont move step
|
// Make sure we are connected, else dont move step
|
||||||
if (medtrumService?.isConnected == false) {
|
if (medtrumService?.isConnected == false) {
|
||||||
aapsLogger.info(LTag.PUMP, "moveStep: not connected, not moving step")
|
aapsLogger.info(LTag.PUMP, "moveStep: not connected, not moving step")
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,6 +188,30 @@ class MedtrumViewModel @Inject constructor(
|
||||||
aapsLogger.info(LTag.PUMP, "forceMoveStep: $oldPatchStep -> $newPatchStep")
|
aapsLogger.info(LTag.PUMP, "forceMoveStep: $oldPatchStep -> $newPatchStep")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleCancel() {
|
||||||
|
if (oldPatchStep !in listOf(
|
||||||
|
PatchStep.PREPARE_PATCH,
|
||||||
|
PatchStep.START_DEACTIVATION,
|
||||||
|
PatchStep.DEACTIVATE,
|
||||||
|
PatchStep.FORCE_DEACTIVATION,
|
||||||
|
PatchStep.DEACTIVATION_COMPLETE
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
medtrumService?.disconnect("Cancel")
|
||||||
|
}
|
||||||
|
if (oldPatchStep == PatchStep.RETRY_ACTIVATION_CONNECT) {
|
||||||
|
while (medtrumService?.isConnecting == true || medtrumService?.isConnected == true) {
|
||||||
|
SystemClock.sleep(100)
|
||||||
|
}
|
||||||
|
// Set pump state to FILLED, so user will be able to retry activation again
|
||||||
|
medtrumPump.pumpState = MedtrumPumpState.FILLED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun handleComplete() {
|
||||||
|
medtrumService?.disconnect("Complete")
|
||||||
|
}
|
||||||
|
|
||||||
fun initializePatchStep(step: PatchStep) {
|
fun initializePatchStep(step: PatchStep) {
|
||||||
mInitPatchStep = prepareStep(step)
|
mInitPatchStep = prepareStep(step)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue