This commit is contained in:
Andrei Vereha 2021-10-03 16:18:28 +02:00
parent b4cdd4e7b3
commit 86ceda76c8
3 changed files with 11 additions and 21 deletions

View file

@ -8,13 +8,15 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
abstract class ActionViewModelBase( abstract class ActionViewModelBase(
protected val injector: HasAndroidInjector, protected val injector: HasAndroidInjector,
protected val logger: AAPSLogger protected val logger: AAPSLogger
) : ViewModelBase() { ) : ViewModelBase() {
private val disposable = CompositeDisposable() protected val disposable = CompositeDisposable()
private val _isActionExecutingLiveData = MutableLiveData(false) private val _isActionExecutingLiveData = MutableLiveData(false)
val isActionExecutingLiveData: LiveData<Boolean> = _isActionExecutingLiveData val isActionExecutingLiveData: LiveData<Boolean> = _isActionExecutingLiveData
@ -24,7 +26,7 @@ abstract class ActionViewModelBase(
fun executeAction() { fun executeAction() {
_isActionExecutingLiveData.postValue(true) _isActionExecutingLiveData.postValue(true)
val subscription = doExecuteAction().subscribeBy( disposable += doExecuteAction().subscribeBy(
onSuccess = { result -> onSuccess = { result ->
_isActionExecutingLiveData.postValue(false) _isActionExecutingLiveData.postValue(false)
_actionResultLiveData.postValue(result) _actionResultLiveData.postValue(result)
@ -35,7 +37,6 @@ abstract class ActionViewModelBase(
_actionResultLiveData.postValue(PumpEnactResult(injector).success(false).comment( _actionResultLiveData.postValue(PumpEnactResult(injector).success(false).comment(
throwable.message ?: "Caught exception in while executing action in ActionViewModelBase")) throwable.message ?: "Caught exception in while executing action in ActionViewModelBase"))
}) })
disposable.add(subscription)
} }
override fun onCleared() { override fun onCleared() {

View file

@ -15,6 +15,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import javax.inject.Inject import javax.inject.Inject
@ -26,8 +28,6 @@ class DashInitializePodViewModel @Inject constructor(
private val podStateManager: OmnipodDashPodStateManager, private val podStateManager: OmnipodDashPodStateManager,
private val resourceHelper: ResourceHelper private val resourceHelper: ResourceHelper
) : InitializePodViewModel(injector, logger) { ) : InitializePodViewModel(injector, logger) {
private val disposable = CompositeDisposable()
override fun isPodInAlarm(): Boolean = false // TODO override fun isPodInAlarm(): Boolean = false // TODO
override fun isPodActivationTimeExceeded(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO
@ -43,7 +43,7 @@ class DashInitializePodViewModel @Inject constructor(
} else } else
null null
val subscription = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( super.disposable += omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
logger.debug( logger.debug(
LTag.PUMP, LTag.PUMP,
@ -64,12 +64,6 @@ class DashInitializePodViewModel @Inject constructor(
source.onSuccess(PumpEnactResult(injector).success(true)) source.onSuccess(PumpEnactResult(injector).success(true))
} }
) )
disposable.add(subscription)
}
override fun onCleared() {
super.onCleared()
disposable.clear()
} }
@StringRes @StringRes

View file

@ -22,6 +22,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import javax.inject.Inject import javax.inject.Inject
@ -37,8 +39,6 @@ class DashInsertCannulaViewModel @Inject constructor(
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger
) : InsertCannulaViewModel(injector, logger) { ) : InsertCannulaViewModel(injector, logger) {
private val disposable = CompositeDisposable()
override fun isPodInAlarm(): Boolean = false // TODO override fun isPodInAlarm(): Boolean = false // TODO
override fun isPodActivationTimeExceeded(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO
@ -65,7 +65,8 @@ class DashInsertCannulaViewModel @Inject constructor(
else else
null null
val subscription = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( super.disposable += omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown)
.subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
logger.debug( logger.debug(
LTag.PUMP, LTag.PUMP,
@ -103,15 +104,9 @@ class DashInsertCannulaViewModel @Inject constructor(
source.onSuccess(PumpEnactResult(injector).success(true)) source.onSuccess(PumpEnactResult(injector).success(true))
} }
) )
disposable.add(subscription)
} }
} }
override fun onCleared() {
super.onCleared()
disposable.clear()
}
@StringRes @StringRes
override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_insert_cannula_title override fun getTitleId(): Int = R.string.omnipod_common_pod_activation_wizard_insert_cannula_title