From 45fd5264b087b5a0bfb99d2e5510959b1e75eaa4 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Fri, 4 Sep 2020 23:11:27 +0200 Subject: [PATCH] Fix queue size view --- .../general/openhumans/OpenHumansFragment.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt index 66ec00bd91..a14659d38d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansFragment.kt @@ -18,6 +18,8 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.extensions.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper +import io.reactivex.BackpressureStrategy +import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers @@ -46,23 +48,18 @@ class OpenHumansFragment : DaggerFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - compositeDisposable += rxBus.toObservable(UpdateQueueEvent::class.java) - .throttleLatest(5, TimeUnit.SECONDS) - .observeOn(Schedulers.io()) - .map { MainApp.getDbHelper().ohQueueSize } + compositeDisposable += Single.fromCallable { MainApp.getDbHelper().ohQueueSize } + .subscribeOn(Schedulers.io()) + .repeatWhen { rxBus.toObservable(UpdateViewEvent::class.java) + .cast(Any::class.java) + .mergeWith(rxBus.toObservable(UpdateQueueEvent::class.java) + .throttleLatest(5, TimeUnit.SECONDS)) + .toFlowable(BackpressureStrategy.LATEST) } .observeOn(AndroidSchedulers.mainThread()) - .subscribe { + .subscribe({ queueSizeValue = it updateGUI() - } - compositeDisposable += rxBus.toObservable(UpdateViewEvent::class.java) - .observeOn(Schedulers.io()) - .map { MainApp.getDbHelper().ohQueueSize } - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { - queueSizeValue = it - updateGUI() - } + }, {}) context?.applicationContext?.let { appContext -> WorkManager.getInstance(appContext).getWorkInfosForUniqueWorkLiveData(OpenHumansUploader.WORK_NAME).observe(this, Observer> { val workInfo = it.lastOrNull() @@ -74,6 +71,10 @@ class OpenHumansFragment : DaggerFragment() { } }) } + + openHumansUploader.uploadDataSegmentally() + .subscribeOn(Schedulers.io()) + .subscribe() } override fun onDestroy() {