From a1bd84df1605bde2a1e4e1072457de92e45b4d94 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 3 Oct 2021 16:18:28 +0200 Subject: [PATCH] cleanup --- .../wizard/common/viewmodel/ActionViewModelBase.kt | 7 ++++--- .../viewmodel/action/DashInitializePodViewModel.kt | 12 +++--------- .../viewmodel/action/DashInsertCannulaViewModel.kt | 13 ++++--------- 3 files changed, 11 insertions(+), 21 deletions(-) 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 f97a4f7d93..d3c0ac8aaa 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 @@ -8,13 +8,15 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import io.reactivex.Single import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.addTo +import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.subscribeBy abstract class ActionViewModelBase( protected val injector: HasAndroidInjector, protected val logger: AAPSLogger ) : ViewModelBase() { - private val disposable = CompositeDisposable() + protected val disposable = CompositeDisposable() private val _isActionExecutingLiveData = MutableLiveData(false) val isActionExecutingLiveData: LiveData = _isActionExecutingLiveData @@ -24,7 +26,7 @@ abstract class ActionViewModelBase( fun executeAction() { _isActionExecutingLiveData.postValue(true) - val subscription = doExecuteAction().subscribeBy( + disposable += doExecuteAction().subscribeBy( onSuccess = { result -> _isActionExecutingLiveData.postValue(false) _actionResultLiveData.postValue(result) @@ -35,7 +37,6 @@ 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() { 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 9bb744fa45..78f8c48d8d 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 @@ -15,6 +15,8 @@ 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.addTo +import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject @@ -26,8 +28,6 @@ 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 @@ -43,7 +43,7 @@ class DashInitializePodViewModel @Inject constructor( } else null - val subscription = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( + super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -64,14 +64,8 @@ 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 a8f57536cf..a716d2b56b 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 @@ -22,6 +22,8 @@ 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.addTo +import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject @@ -37,8 +39,6 @@ class DashInsertCannulaViewModel @Inject constructor( injector: HasAndroidInjector, logger: AAPSLogger ) : InsertCannulaViewModel(injector, logger) { - private val disposable = CompositeDisposable() - override fun isPodInAlarm(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO @@ -65,7 +65,8 @@ class DashInsertCannulaViewModel @Inject constructor( else null - val subscription = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( + super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown) + .subscribeBy( onNext = { podEvent -> logger.debug( LTag.PUMP, @@ -103,15 +104,9 @@ 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