NSC: improve sync

This commit is contained in:
Milos Kozak 2023-09-14 20:07:26 +02:00
parent 081f9ab463
commit d2247dc9bc
6 changed files with 25 additions and 7 deletions

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventFoodChanged : Event()

View file

@ -1,3 +0,0 @@
package info.nightscout.rx.events
class EventFoodDatabaseChanged : Event()

View file

@ -19,7 +19,7 @@ import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventDeviceStatusChange
import info.nightscout.rx.events.EventEffectiveProfileSwitchChanged
import info.nightscout.rx.events.EventExtendedBolusChange
import info.nightscout.rx.events.EventFoodDatabaseChanged
import info.nightscout.rx.events.EventFoodChanged
import info.nightscout.rx.events.EventNewBG
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventOfflineChange
@ -101,7 +101,7 @@ class CompatDBHelper @Inject constructor(
}
it.filterIsInstance<Food>().firstOrNull()?.let { food ->
aapsLogger.debug(LTag.DATABASE, "Firing EventFoodDatabaseChanged $food")
rxBus.send(EventFoodDatabaseChanged())
rxBus.send(EventFoodChanged())
}
it.filterIsInstance<ProfileSwitch>().firstOrNull()?.let { ps ->
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileSwitchChanged $ps")

View file

@ -28,7 +28,7 @@ import info.nightscout.plugins.databinding.FoodFragmentBinding
import info.nightscout.plugins.databinding.FoodItemBinding
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventFoodDatabaseChanged
import info.nightscout.rx.events.EventFoodChanged
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.extensions.toVisibility
@ -92,7 +92,7 @@ class FoodFragment : DaggerFragment() {
override fun onResume() {
super.onResume()
disposable += rxBus
.toObservable(EventFoodDatabaseChanged::class.java)
.toObservable(EventFoodChanged::class.java)
.observeOn(aapsSchedulers.main)
.debounce(1L, TimeUnit.SECONDS)
.subscribe({ swapAdapter() }, fabricPrivacy::logException)

View file

@ -183,6 +183,14 @@ import javax.inject.Inject
.toObservable(EventDeviceStatusChange::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ resend("EventDeviceStatusChange") }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTempTargetChange::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ resend("EventTempTargetChange") }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventProfileSwitchChanged::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ resend("EventProfileSwitchChanged") }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTherapyEventChange::class.java)
.observeOn(aapsSchedulers.io)

View file

@ -72,7 +72,9 @@ import info.nightscout.rx.events.EventNSClientNewLog
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventOfflineChange
import info.nightscout.rx.events.EventPreferenceChange
import info.nightscout.rx.events.EventProfileSwitchChanged
import info.nightscout.rx.events.EventSWSyncStatus
import info.nightscout.rx.events.EventTempTargetChange
import info.nightscout.rx.events.EventTherapyEventChange
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
@ -228,6 +230,14 @@ class NSClientV3Plugin @Inject constructor(
.toObservable(EventNewHistoryData::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ executeUpload("NEW_DATA", forceNew = false) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTempTargetChange::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ executeUpload("EventTempTargetChange", forceNew = false) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventProfileSwitchChanged::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ executeUpload("EventProfileSwitchChanged", forceNew = false) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventDeviceStatusChange::class.java)
.observeOn(aapsSchedulers.io)