clear disposables
This commit is contained in:
parent
ff023fbaa8
commit
f79e5eca6f
4 changed files with 30 additions and 12 deletions
|
@ -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<Boolean> = _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<PumpEnactResult>
|
||||
}
|
||||
|
|
|
@ -111,13 +111,12 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
updatePodWarnings()
|
||||
aapsLogger.info(LTag.PUMP, "statusChecker")
|
||||
|
||||
createFakeTBRWhenNoActivePod()
|
||||
val err = createFakeTBRWhenNoActivePod()
|
||||
.subscribeOn(aapsSchedulers.io)
|
||||
.subscribeBy(
|
||||
onError = {
|
||||
.blockingGet()
|
||||
err?.let {
|
||||
aapsLogger.warn(LTag.PUMP, "Error on createFakeTBRWhenNoActivePod=$it")
|
||||
}
|
||||
)
|
||||
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,6 +64,12 @@ class DashInitializePodViewModel @Inject constructor(
|
|||
source.onSuccess(PumpEnactResult(injector).success(true))
|
||||
}
|
||||
)
|
||||
disposable.add(subscription)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
@StringRes
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue