clear disposables

This commit is contained in:
Andrei Vereha 2021-10-03 12:11:41 +02:00
parent ff023fbaa8
commit f79e5eca6f
4 changed files with 30 additions and 12 deletions

View file

@ -7,14 +7,14 @@ import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.logging.AAPSLogger 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.Disposable import io.reactivex.disposables.CompositeDisposable
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 var disposable: Disposable? = null private 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 +24,7 @@ abstract class ActionViewModelBase(
fun executeAction() { fun executeAction() {
_isActionExecutingLiveData.postValue(true) _isActionExecutingLiveData.postValue(true)
disposable = doExecuteAction().subscribeBy( val subscription = doExecuteAction().subscribeBy(
onSuccess = { result -> onSuccess = { result ->
_isActionExecutingLiveData.postValue(false) _isActionExecutingLiveData.postValue(false)
_actionResultLiveData.postValue(result) _actionResultLiveData.postValue(result)
@ -35,12 +35,14 @@ 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() {
super.onCleared() super.onCleared()
disposable?.dispose() disposable.clear()
} }
protected abstract fun doExecuteAction(): Single<PumpEnactResult> protected abstract fun doExecuteAction(): Single<PumpEnactResult>
} }

View file

@ -111,13 +111,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
updatePodWarnings() updatePodWarnings()
aapsLogger.info(LTag.PUMP, "statusChecker") aapsLogger.info(LTag.PUMP, "statusChecker")
createFakeTBRWhenNoActivePod() val err = createFakeTBRWhenNoActivePod()
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.subscribeBy( .blockingGet()
onError = { err?.let {
aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it") aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it")
} }
)
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
} }
} }

View file

@ -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.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.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import javax.inject.Inject import javax.inject.Inject
@ -25,6 +26,8 @@ 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
@ -40,7 +43,7 @@ class DashInitializePodViewModel @Inject constructor(
} else } else
null null
omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy( val subscription = omnipodManager.activatePodPart1(lowReservoirAlertTrigger).subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
logger.debug( logger.debug(
LTag.PUMP, LTag.PUMP,
@ -61,6 +64,12 @@ 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

@ -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.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.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import javax.inject.Inject import javax.inject.Inject
@ -36,6 +37,7 @@ 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
@ -63,7 +65,7 @@ class DashInsertCannulaViewModel @Inject constructor(
else else
null null
omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy( val subscription = omnipodManager.activatePodPart2(basalProgram, expirationHoursBeforeShutdown).subscribeBy(
onNext = { podEvent -> onNext = { podEvent ->
logger.debug( logger.debug(
LTag.PUMP, LTag.PUMP,
@ -101,9 +103,15 @@ 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