EROS: so not run commands on UI thread
This commit is contained in:
parent
c4765b42f0
commit
42daad43f4
12 changed files with 62 additions and 34 deletions
|
@ -80,7 +80,6 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
uel.log(Action.CAREPORTAL_NS_REFRESH, Sources.Treatments)
|
||||
disposable += Completable.fromAction { repository.deleteAllTherapyEventsEntries() }
|
||||
.subscribeOn(aapsSchedulers.io)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribeBy(
|
||||
onError = { aapsLogger.error("Error removing entries", it) },
|
||||
onComplete = { rxBus.send(EventTherapyEventChange()) }
|
||||
|
|
|
@ -2,8 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
|
|||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
|
||||
abstract class InitializePodViewModel(
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : PodActivationActionViewModelBase(injector, logger)
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : PodActivationActionViewModelBase(injector, logger, aapsSchedulers)
|
|
@ -2,8 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
|
|||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
|
||||
abstract class InsertCannulaViewModel(
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : PodActivationActionViewModelBase(injector, logger)
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : PodActivationActionViewModelBase(injector, logger, aapsSchedulers)
|
|
@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
|
||||
abstract class PodActivationActionViewModelBase(
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : ActionViewModelBase(injector, logger) {
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : ActionViewModelBase(injector, logger, aapsSchedulers) {
|
||||
|
||||
abstract fun isPodInAlarm(): Boolean
|
||||
|
||||
|
|
|
@ -6,16 +6,18 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
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
|
||||
protected val logger: AAPSLogger,
|
||||
private val aapsSchedulers: AapsSchedulers
|
||||
) : ViewModelBase() {
|
||||
|
||||
protected val disposable = CompositeDisposable()
|
||||
|
||||
private val _isActionExecutingLiveData = MutableLiveData(false)
|
||||
|
@ -26,17 +28,23 @@ abstract class ActionViewModelBase(
|
|||
|
||||
fun executeAction() {
|
||||
_isActionExecutingLiveData.postValue(true)
|
||||
disposable += doExecuteAction().subscribeBy(
|
||||
onSuccess = { result ->
|
||||
_isActionExecutingLiveData.postValue(false)
|
||||
_actionResultLiveData.postValue(result)
|
||||
},
|
||||
onError = { throwable ->
|
||||
logger.error(LTag.PUMP, "Caught exception in while executing action in ActionViewModelBase", throwable)
|
||||
_isActionExecutingLiveData.postValue(false)
|
||||
_actionResultLiveData.postValue(PumpEnactResult(injector).success(false).comment(
|
||||
throwable.message ?: "Caught exception in while executing action in ActionViewModelBase"))
|
||||
})
|
||||
disposable += doExecuteAction()
|
||||
.subscribeOn(aapsSchedulers.io)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribeBy(
|
||||
onSuccess = { result ->
|
||||
_isActionExecutingLiveData.postValue(false)
|
||||
_actionResultLiveData.postValue(result)
|
||||
},
|
||||
onError = { throwable ->
|
||||
logger.error(LTag.PUMP, "Caught exception in while executing action in ActionViewModelBase", throwable)
|
||||
_isActionExecutingLiveData.postValue(false)
|
||||
_actionResultLiveData.postValue(
|
||||
PumpEnactResult(injector).success(false).comment(
|
||||
throwable.message ?: "Caught exception in while executing action in ActionViewModelBase"
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
|
@ -44,6 +52,5 @@ abstract class ActionViewModelBase(
|
|||
disposable.clear()
|
||||
}
|
||||
|
||||
|
||||
protected abstract fun doExecuteAction(): Single<PumpEnactResult>
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactiv
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
|
||||
abstract class DeactivatePodViewModel(
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : ActionViewModelBase(injector, logger) {
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : ActionViewModelBase(injector, logger, aapsSchedulers) {
|
||||
|
||||
abstract fun discardPod()
|
||||
}
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.Initial
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.ResolvedResult
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
|
@ -30,8 +31,10 @@ class DashInitializePodViewModel @Inject constructor(
|
|||
private val podStateManager: OmnipodDashPodStateManager,
|
||||
private val resourceHelper: ResourceHelper,
|
||||
private val history: DashHistory,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
|
||||
) : InitializePodViewModel(injector, logger, aapsSchedulers) {
|
||||
|
||||
) : InitializePodViewModel(injector, logger) {
|
||||
override fun isPodInAlarm(): Boolean = false // TODO
|
||||
|
||||
override fun isPodActivationTimeExceeded(): Boolean = false // TODO
|
||||
|
|
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
|
@ -44,8 +45,10 @@ class DashInsertCannulaViewModel @Inject constructor(
|
|||
private val history: DashHistory,
|
||||
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : InsertCannulaViewModel(injector, logger) {
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : InsertCannulaViewModel(injector, logger, aapsSchedulers) {
|
||||
|
||||
override fun isPodInAlarm(): Boolean = false // TODO
|
||||
|
||||
override fun isPodActivationTimeExceeded(): Boolean = false // TODO
|
||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.Comm
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.action.DeactivatePodViewModel
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -21,8 +22,9 @@ class DashDeactivatePodViewModel @Inject constructor(
|
|||
private val commandQueueProvider: CommandQueueProvider,
|
||||
private val rxBus: RxBus,
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : DeactivatePodViewModel(injector, logger) {
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : DeactivatePodViewModel(injector, logger, aapsSchedulers) {
|
||||
|
||||
override fun doExecuteAction(): Single<PumpEnactResult> = Single.create { source ->
|
||||
commandQueueProvider.customCommand(
|
||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.R
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.ActivationProgress
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsErosPodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -16,8 +17,9 @@ class ErosInitializePodViewModel @Inject constructor(
|
|||
private val aapsOmnipodManager: AapsOmnipodErosManager,
|
||||
private val podStateManager: AapsErosPodStateManager,
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : InitializePodViewModel(injector, logger) {
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : InitializePodViewModel(injector, logger, aapsSchedulers) {
|
||||
|
||||
override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.R
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.ActivationProgress
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsErosPodStateManager
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -18,8 +19,9 @@ class ErosInsertCannulaViewModel @Inject constructor(
|
|||
private val podStateManager: AapsErosPodStateManager,
|
||||
private val profileFunction: ProfileFunction,
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : InsertCannulaViewModel(injector, logger) {
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : InsertCannulaViewModel(injector, logger, aapsSchedulers) {
|
||||
|
||||
override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.Comm
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.action.DeactivatePodViewModel
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -17,8 +18,9 @@ class ErosDeactivatePodViewModel @Inject constructor(
|
|||
private val aapsOmnipodManager: AapsOmnipodErosManager,
|
||||
private val commandQueueProvider: CommandQueueProvider,
|
||||
injector: HasAndroidInjector,
|
||||
logger: AAPSLogger
|
||||
) : DeactivatePodViewModel(injector, logger) {
|
||||
logger: AAPSLogger,
|
||||
aapsSchedulers: AapsSchedulers
|
||||
) : DeactivatePodViewModel(injector, logger, aapsSchedulers) {
|
||||
|
||||
override fun doExecuteAction(): Single<PumpEnactResult> =
|
||||
Single.create { source ->
|
||||
|
|
Loading…
Reference in a new issue