diff --git a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt index 604eac6d89..f97a4f7d93 100644 --- a/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt +++ b/omnipod-common/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/common/ui/wizard/common/viewmodel/ActionViewModelBase.kt @@ -7,14 +7,14 @@ import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import io.reactivex.Single -import io.reactivex.disposables.Disposable +import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.subscribeBy abstract class ActionViewModelBase( protected val injector: HasAndroidInjector, protected val logger: AAPSLogger ) : ViewModelBase() { - private var disposable: Disposable? = null + private val disposable = CompositeDisposable() private val _isActionExecutingLiveData = MutableLiveData(false) val isActionExecutingLiveData: LiveData = _isActionExecutingLiveData @@ -24,7 +24,7 @@ abstract class ActionViewModelBase( fun executeAction() { _isActionExecutingLiveData.postValue(true) - disposable = doExecuteAction().subscribeBy( + val subscription = doExecuteAction().subscribeBy( onSuccess = { result -> _isActionExecutingLiveData.postValue(false) _actionResultLiveData.postValue(result) @@ -35,12 +35,14 @@ abstract class ActionViewModelBase( _actionResultLiveData.postValue(PumpEnactResult(injector).success(false).comment( throwable.message ?: "Caught exception in while executing action in ActionViewModelBase")) }) + disposable.add(subscription) } override fun onCleared() { super.onCleared() - disposable?.dispose() + disposable.clear() } + protected abstract fun doExecuteAction(): Single } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index 83b0796ffe..4f49c6f4f1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -111,13 +111,12 @@ class OmnipodDashPumpPlugin @Inject constructor( updatePodWarnings() aapsLogger.info(LTag.PUMP, "statusChecker") - createFakeTBRWhenNoActivePod() + val err = createFakeTBRWhenNoActivePod() .subscribeOn(aapsSchedulers.io) - .subscribeBy( - onError = { - aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it") - } - ) + .blockingGet() + err?.let { + aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it") + } handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt index a6faa187f4..9bb744fa45 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt @@ -14,6 +14,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.Single +import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject @@ -25,6 +26,8 @@ class DashInitializePodViewModel @Inject constructor( private val podStateManager: OmnipodDashPodStateManager, private val resourceHelper: ResourceHelper ) : InitializePodViewModel(injector, logger) { + private val disposable = CompositeDisposable() + override fun isPodInAlarm(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO @@ -40,7 +43,7 @@ class DashInitializePodViewModel @Inject constructor( } else null - omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( + val subscription = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -61,8 +64,14 @@ class DashInitializePodViewModel @Inject constructor( source.onSuccess(PumpEnactResult(injector).success(true)) } ) + disposable.add(subscription) } + override fun onCleared() { + super.onCleared() + disposable.clear() + } + @StringRes override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_initialize_pod_title diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt index 9a3530f443..a8f57536cf 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInsertCannulaViewModel.kt @@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBas import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.Single +import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject @@ -36,6 +37,7 @@ class DashInsertCannulaViewModel @Inject constructor( injector: HasAndroidInjector, logger: AAPSLogger ) : InsertCannulaViewModel(injector, logger) { + private val disposable = CompositeDisposable() override fun isPodInAlarm(): Boolean = false // TODO @@ -63,7 +65,7 @@ class DashInsertCannulaViewModel @Inject constructor( else null - omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( + val subscription = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -101,9 +103,15 @@ class DashInsertCannulaViewModel @Inject constructor( source.onSuccess(PumpEnactResult(injector).success(true)) } ) + disposable.add(subscription) } } + override fun onCleared() { + super.onCleared() + disposable.clear() + } + @StringRes override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_insert_cannula_title