fix warning
This commit is contained in:
parent
9de71e1051
commit
a7f82eb4fb
1 changed files with 8 additions and 1 deletions
|
@ -7,12 +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.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 _isActionExecutingLiveData = MutableLiveData(false)
|
private val _isActionExecutingLiveData = MutableLiveData(false)
|
||||||
val isActionExecutingLiveData: LiveData<Boolean> = _isActionExecutingLiveData
|
val isActionExecutingLiveData: LiveData<Boolean> = _isActionExecutingLiveData
|
||||||
|
@ -22,7 +24,7 @@ abstract class ActionViewModelBase(
|
||||||
|
|
||||||
fun executeAction() {
|
fun executeAction() {
|
||||||
_isActionExecutingLiveData.postValue(true)
|
_isActionExecutingLiveData.postValue(true)
|
||||||
val disposable = doExecuteAction().subscribeBy(
|
disposable = doExecuteAction().subscribeBy(
|
||||||
onSuccess = { result ->
|
onSuccess = { result ->
|
||||||
_isActionExecutingLiveData.postValue(false)
|
_isActionExecutingLiveData.postValue(false)
|
||||||
_actionResultLiveData.postValue(result)
|
_actionResultLiveData.postValue(result)
|
||||||
|
@ -35,5 +37,10 @@ abstract class ActionViewModelBase(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
disposable?.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun doExecuteAction(): Single<PumpEnactResult>
|
protected abstract fun doExecuteAction(): Single<PumpEnactResult>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue