EROS: so not run commands on UI thread

This commit is contained in:
Milos Kozak 2021-10-30 19:44:54 +02:00
parent c4765b42f0
commit 42daad43f4
12 changed files with 62 additions and 34 deletions

View file

@ -80,7 +80,6 @@ class TreatmentsCareportalFragment : DaggerFragment() {
uel.log(Action.CAREPORTAL_NS_REFRESH, Sources.Treatments) uel.log(Action.CAREPORTAL_NS_REFRESH, Sources.Treatments)
disposable += Completable.fromAction { repository.deleteAllTherapyEventsEntries() } disposable += Completable.fromAction { repository.deleteAllTherapyEventsEntries() }
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)
.subscribeBy( .subscribeBy(
onError = { aapsLogger.error("Error removing entries", it) }, onError = { aapsLogger.error("Error removing entries", it) },
onComplete = { rxBus.send(EventTherapyEventChange()) } onComplete = { rxBus.send(EventTherapyEventChange()) }

View file

@ -2,8 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.utils.rx.AapsSchedulers
abstract class InitializePodViewModel( abstract class InitializePodViewModel(
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : PodActivationActionViewModelBase(injector, logger) aapsSchedulers: AapsSchedulers
) : PodActivationActionViewModelBase(injector, logger, aapsSchedulers)

View file

@ -2,8 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.utils.rx.AapsSchedulers
abstract class InsertCannulaViewModel( abstract class InsertCannulaViewModel(
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : PodActivationActionViewModelBase(injector, logger) aapsSchedulers: AapsSchedulers
) : PodActivationActionViewModelBase(injector, logger, aapsSchedulers)

View file

@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.activat
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
import info.nightscout.androidaps.utils.rx.AapsSchedulers
abstract class PodActivationActionViewModelBase( abstract class PodActivationActionViewModelBase(
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : ActionViewModelBase(injector, logger) { aapsSchedulers: AapsSchedulers
) : ActionViewModelBase(injector, logger, aapsSchedulers) {
abstract fun isPodInAlarm(): Boolean abstract fun isPodInAlarm(): Boolean

View file

@ -6,16 +6,18 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.PumpEnactResult 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 info.nightscout.androidaps.utils.rx.AapsSchedulers
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.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,
private val aapsSchedulers: AapsSchedulers
) : ViewModelBase() { ) : ViewModelBase() {
protected val disposable = CompositeDisposable() protected val disposable = CompositeDisposable()
private val _isActionExecutingLiveData = MutableLiveData(false) private val _isActionExecutingLiveData = MutableLiveData(false)
@ -26,7 +28,10 @@ abstract class ActionViewModelBase(
fun executeAction() { fun executeAction() {
_isActionExecutingLiveData.postValue(true) _isActionExecutingLiveData.postValue(true)
disposable += doExecuteAction().subscribeBy( disposable += doExecuteAction()
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)
.subscribeBy(
onSuccess = { result -> onSuccess = { result ->
_isActionExecutingLiveData.postValue(false) _isActionExecutingLiveData.postValue(false)
_actionResultLiveData.postValue(result) _actionResultLiveData.postValue(result)
@ -34,8 +39,11 @@ abstract class ActionViewModelBase(
onError = { throwable -> onError = { throwable ->
logger.error(LTag.PUMP, "Caught exception in while executing action in ActionViewModelBase", throwable) logger.error(LTag.PUMP, "Caught exception in while executing action in ActionViewModelBase", throwable)
_isActionExecutingLiveData.postValue(false) _isActionExecutingLiveData.postValue(false)
_actionResultLiveData.postValue(PumpEnactResult(injector).success(false).comment( _actionResultLiveData.postValue(
throwable.message ?: "Caught exception in while executing action in ActionViewModelBase")) PumpEnactResult(injector).success(false).comment(
throwable.message ?: "Caught exception in while executing action in ActionViewModelBase"
)
)
}) })
} }
@ -44,6 +52,5 @@ abstract class ActionViewModelBase(
disposable.clear() disposable.clear()
} }
protected abstract fun doExecuteAction(): Single<PumpEnactResult> protected abstract fun doExecuteAction(): Single<PumpEnactResult>
} }

View file

@ -3,11 +3,13 @@ package info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactiv
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.common.viewmodel.ActionViewModelBase
import info.nightscout.androidaps.utils.rx.AapsSchedulers
abstract class DeactivatePodViewModel( abstract class DeactivatePodViewModel(
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : ActionViewModelBase(injector, logger) { aapsSchedulers: AapsSchedulers
) : ActionViewModelBase(injector, logger, aapsSchedulers) {
abstract fun discardPod() abstract fun discardPod()
} }

View file

@ -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.history.data.ResolvedResult
import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.I8n 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.rx.AapsSchedulers
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.rxkotlin.plusAssign import io.reactivex.rxkotlin.plusAssign
@ -30,8 +31,10 @@ class DashInitializePodViewModel @Inject constructor(
private val podStateManager: OmnipodDashPodStateManager, private val podStateManager: OmnipodDashPodStateManager,
private val resourceHelper: ResourceHelper, private val resourceHelper: ResourceHelper,
private val history: DashHistory, private val history: DashHistory,
aapsSchedulers: AapsSchedulers
) : InitializePodViewModel(injector, logger, aapsSchedulers) {
) : InitializePodViewModel(injector, logger) {
override fun isPodInAlarm(): Boolean = false // TODO override fun isPodInAlarm(): Boolean = false // TODO
override fun isPodActivationTimeExceeded(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO

View file

@ -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.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
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.rxkotlin.plusAssign import io.reactivex.rxkotlin.plusAssign
@ -44,8 +45,10 @@ class DashInsertCannulaViewModel @Inject constructor(
private val history: DashHistory, private val history: DashHistory,
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : InsertCannulaViewModel(injector, logger) { aapsSchedulers: AapsSchedulers
) : InsertCannulaViewModel(injector, logger, aapsSchedulers) {
override fun isPodInAlarm(): Boolean = false // TODO override fun isPodInAlarm(): Boolean = false // TODO
override fun isPodActivationTimeExceeded(): Boolean = false // TODO override fun isPodActivationTimeExceeded(): Boolean = false // TODO

View file

@ -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.common.ui.wizard.deactivation.viewmodel.action.DeactivatePodViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.Single import io.reactivex.Single
import javax.inject.Inject import javax.inject.Inject
@ -21,8 +22,9 @@ class DashDeactivatePodViewModel @Inject constructor(
private val commandQueueProvider: CommandQueueProvider, private val commandQueueProvider: CommandQueueProvider,
private val rxBus: RxBus, private val rxBus: RxBus,
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : DeactivatePodViewModel(injector, logger) { aapsSchedulers: AapsSchedulers
) : DeactivatePodViewModel(injector, logger, aapsSchedulers) {
override fun doExecuteAction(): Single<PumpEnactResult> = Single.create { source -> override fun doExecuteAction(): Single<PumpEnactResult> = Single.create { source ->
commandQueueProvider.customCommand( commandQueueProvider.customCommand(

View file

@ -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.driver.definition.ActivationProgress
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsErosPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsErosPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.Single import io.reactivex.Single
import javax.inject.Inject import javax.inject.Inject
@ -16,8 +17,9 @@ class ErosInitializePodViewModel @Inject constructor(
private val aapsOmnipodManager: AapsOmnipodErosManager, private val aapsOmnipodManager: AapsOmnipodErosManager,
private val podStateManager: AapsErosPodStateManager, private val podStateManager: AapsErosPodStateManager,
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : InitializePodViewModel(injector, logger) { aapsSchedulers: AapsSchedulers
) : InitializePodViewModel(injector, logger, aapsSchedulers) {
override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted

View file

@ -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.driver.definition.ActivationProgress
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsErosPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsErosPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.Single import io.reactivex.Single
import javax.inject.Inject import javax.inject.Inject
@ -18,8 +19,9 @@ class ErosInsertCannulaViewModel @Inject constructor(
private val podStateManager: AapsErosPodStateManager, private val podStateManager: AapsErosPodStateManager,
private val profileFunction: ProfileFunction, private val profileFunction: ProfileFunction,
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : InsertCannulaViewModel(injector, logger) { aapsSchedulers: AapsSchedulers
) : InsertCannulaViewModel(injector, logger, aapsSchedulers) {
override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted override fun isPodInAlarm(): Boolean = podStateManager.isPodFaulted

View file

@ -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.common.ui.wizard.deactivation.viewmodel.action.DeactivatePodViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.Single import io.reactivex.Single
import javax.inject.Inject import javax.inject.Inject
@ -17,8 +18,9 @@ class ErosDeactivatePodViewModel @Inject constructor(
private val aapsOmnipodManager: AapsOmnipodErosManager, private val aapsOmnipodManager: AapsOmnipodErosManager,
private val commandQueueProvider: CommandQueueProvider, private val commandQueueProvider: CommandQueueProvider,
injector: HasAndroidInjector, injector: HasAndroidInjector,
logger: AAPSLogger logger: AAPSLogger,
) : DeactivatePodViewModel(injector, logger) { aapsSchedulers: AapsSchedulers
) : DeactivatePodViewModel(injector, logger, aapsSchedulers) {
override fun doExecuteAction(): Single<PumpEnactResult> = override fun doExecuteAction(): Single<PumpEnactResult> =
Single.create { source -> Single.create { source ->