move events

This commit is contained in:
Milos Kozak 2022-11-23 13:23:17 +01:00
parent 1670cd0c06
commit de7a6422d8
17 changed files with 48 additions and 56 deletions

View file

@ -33,4 +33,6 @@ dependencies {
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
api "org.apache.commons:commons-lang3:$commonslang3_version"
api "net.danlew:android.joda:$joda_version"
}

View file

@ -0,0 +1,10 @@
package info.nightscout.rx.events
class EventEffectiveProfileSwitchChanged(timestamp: Long?) : Event() {
var startDate: Long = 0
init {
startDate = timestamp ?: 0L
}
}

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventNewBG(val glucoseValueTimestamp: Long?) : EventLoop()

View file

@ -1,12 +1,10 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
import info.nightscout.database.entities.GlucoseValue
import info.nightscout.rx.events.Event
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.text.DateFormat
class EventNewHistoryData(val oldDataTimestamp: Long, var reloadBgData: Boolean, var newestGlucoseValue: GlucoseValue? = null) : Event() {
class EventNewHistoryData(val oldDataTimestamp: Long, var reloadBgData: Boolean, var newestGlucoseValueTimestamp: Long? = null) : Event() {
override fun toString(): String {
return super.toString() +

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.configBuilder
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.extensions.fromConstant
import info.nightscout.core.main.R
import info.nightscout.core.utils.fabric.FabricPrivacy
@ -20,6 +19,7 @@ import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.plugins.sync.nsclient.data.ProcessedDeviceStatusData
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventEffectiveProfileSwitchChanged
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper

View file

@ -29,8 +29,6 @@ import dagger.android.HasAndroidInjector
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.extensions.directionToIcon
import info.nightscout.androidaps.extensions.valueToUnitsString
import info.nightscout.androidaps.logging.UserEntryLogger
@ -86,8 +84,10 @@ import info.nightscout.plugins.ui.StatusLightHandler
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventAcceptOpenLoopChange
import info.nightscout.rx.events.EventEffectiveProfileSwitchChanged
import info.nightscout.rx.events.EventExtendedBolusChange
import info.nightscout.rx.events.EventMobileToWear
import info.nightscout.rx.events.EventNewBG
import info.nightscout.rx.events.EventPreferenceChange
import info.nightscout.rx.events.EventPumpStatusChanged
import info.nightscout.rx.events.EventRefreshOverview

View file

@ -4,9 +4,6 @@ import androidx.collection.LongSparseArray
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.events.EventNewHistoryData
import info.nightscout.androidaps.extensions.convertedToAbsolute
import info.nightscout.androidaps.extensions.iobCalc
import info.nightscout.androidaps.extensions.toTemporaryBasal
@ -45,6 +42,9 @@ import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.Event
import info.nightscout.rx.events.EventConfigBuilderChange
import info.nightscout.rx.events.EventEffectiveProfileSwitchChanged
import info.nightscout.rx.events.EventNewBG
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventPreferenceChange
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
@ -399,7 +399,7 @@ class IobCobCalculatorPlugin @Inject constructor(
newHistoryData(
event.oldDataTimestamp,
event.reloadBgData,
if (event.newestGlucoseValue != null) EventNewBG(event.newestGlucoseValue) else event
if (event.newestGlucoseValueTimestamp != null) EventNewBG(event.newestGlucoseValueTimestamp) else event
)
scheduledEvent = null
scheduledHistoryPost = null
@ -412,8 +412,8 @@ class IobCobCalculatorPlugin @Inject constructor(
// set reload bg data if was not set
if (!it.reloadBgData) it.reloadBgData = event.reloadBgData
// set Glucose value if newer
event.newestGlucoseValue?.let { gv ->
if (gv.timestamp > (it.newestGlucoseValue?.timestamp ?: 0L)) it.newestGlucoseValue = gv
event.newestGlucoseValueTimestamp?.let { timestamp ->
if (timestamp > (it.newestGlucoseValueTimestamp ?: 0L)) it.newestGlucoseValueTimestamp = timestamp
}
}
}

View file

@ -10,7 +10,6 @@ import androidx.work.WorkInfo
import androidx.work.WorkManager
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventNewHistoryData
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Worker
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOrefWorker
@ -23,6 +22,7 @@ import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.Event
import info.nightscout.rx.events.EventAppInitialized
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventOfflineChange
import info.nightscout.rx.events.EventPreferenceChange
import info.nightscout.rx.events.EventTherapyEventChange

View file

@ -5,11 +5,11 @@ import androidx.work.Worker
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.core.utils.receivers.DataWorkerStorage
import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.rx.events.Event
import info.nightscout.rx.events.EventNewBG
import javax.inject.Inject
class InvokeLoopWorker(

View file

@ -1,15 +0,0 @@
package info.nightscout.androidaps.events
import info.nightscout.database.entities.EffectiveProfileSwitch
import info.nightscout.rx.events.Event
class EventEffectiveProfileSwitchChanged(effectiveProfileSwitch: EffectiveProfileSwitch?) : Event() {
var startDate: Long = 0
init {
effectiveProfileSwitch?.let { startDate = it.timestamp}
}
constructor(startDate: Long) : this(null) {
this.startDate = startDate
}
}

View file

@ -1,6 +0,0 @@
package info.nightscout.androidaps.events
import info.nightscout.database.entities.GlucoseValue
import info.nightscout.rx.events.EventLoop
class EventNewBG(val glucoseValue: GlucoseValue?) : EventLoop()

View file

@ -1,10 +1,6 @@
package info.nightscout.implementation.db
import android.content.Context
import info.nightscout.database.impl.AppRepository
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.events.EventNewHistoryData
import info.nightscout.database.entities.Bolus
import info.nightscout.database.entities.Carbs
import info.nightscout.database.entities.EffectiveProfileSwitch
@ -16,9 +12,13 @@ import info.nightscout.database.entities.ProfileSwitch
import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.impl.AppRepository
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventEffectiveProfileSwitchChanged
import info.nightscout.rx.events.EventExtendedBolusChange
import info.nightscout.rx.events.EventFoodDatabaseChanged
import info.nightscout.rx.events.EventNewBG
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventOfflineChange
import info.nightscout.rx.events.EventProfileSwitchChanged
import info.nightscout.rx.events.EventTempBasalChange
@ -56,13 +56,13 @@ class CompatDBHelper @Inject constructor(
var newestGlucoseValue: GlucoseValue? = null
it.filterIsInstance<GlucoseValue>().maxByOrNull { gv -> gv.timestamp }?.let { gv ->
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv")
rxBus.send(EventNewBG(gv))
rxBus.send(EventNewBG(gv.timestamp))
Widget.updateWidget(context)
newestGlucoseValue = gv
}
it.filterIsInstance<GlucoseValue>().minOfOrNull { gv -> gv.timestamp }?.let { timestamp ->
aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData $timestamp $newestGlucoseValue")
rxBus.send(EventNewHistoryData(timestamp, true, newestGlucoseValue))
rxBus.send(EventNewHistoryData(timestamp, true, newestGlucoseValue?.timestamp))
}
it.filterIsInstance<Carbs>().minOfOrNull { t -> t.timestamp }?.let { timestamp ->
aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp")
@ -86,7 +86,7 @@ class CompatDBHelper @Inject constructor(
}
it.filterIsInstance<EffectiveProfileSwitch>().firstOrNull()?.let { eps ->
aapsLogger.debug(LTag.DATABASE, "Firing EventEffectiveProfileSwitchChanged $eps")
rxBus.send(EventEffectiveProfileSwitchChanged(eps))
rxBus.send(EventEffectiveProfileSwitchChanged(eps.timestamp))
rxBus.send(EventNewHistoryData(eps.timestamp, false))
}
it.filterIsInstance<TemporaryTarget>().firstOrNull()?.let { tt ->

View file

@ -14,7 +14,6 @@ import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.extensions.directionToIcon
import info.nightscout.androidaps.extensions.valueToUnitsString
import info.nightscout.androidaps.logging.UserEntryLogger
@ -35,6 +34,7 @@ import info.nightscout.plugins.databinding.SourceFragmentBinding
import info.nightscout.plugins.databinding.SourceItemBinding
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventNewBG
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.extensions.toVisibility

View file

@ -5,11 +5,10 @@ import android.text.Spanned
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.core.utils.receivers.ReceiverStatusStore
import info.nightscout.core.toast.showToastAdNotification
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.core.utils.receivers.ReceiverStatusStore
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
@ -27,6 +26,7 @@ import info.nightscout.plugins.sync.tidepool.utils.RateLimit
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventNetworkChange
import info.nightscout.rx.events.EventNewBG
import info.nightscout.rx.events.EventPreferenceChange
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
@ -94,11 +94,11 @@ class TidepoolPlugin @Inject constructor(
disposable += rxBus
.toObservable(EventNewBG::class.java)
.observeOn(aapsSchedulers.io)
.filter { it.glucoseValue != null } // better would be optional in API level >24
.map { it.glucoseValue!! }
.subscribe({ bgReading ->
if (bgReading!!.timestamp < uploadChunk.getLastEnd())
uploadChunk.setLastEnd(bgReading.timestamp)
.filter { it.glucoseValueTimestamp != null } // better would be optional in API level >24
.map { it.glucoseValueTimestamp!! }
.subscribe({ bgReadingTimestamp ->
if (bgReadingTimestamp < uploadChunk.getLastEnd())
uploadChunk.setLastEnd(bgReadingTimestamp)
if (isEnabled()
&& (!sp.getBoolean(R.string.key_tidepool_only_while_charging, false) || receiverStatusStore.isCharging)
&& (!sp.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || receiverStatusStore.isWifiConnected)

View file

@ -16,7 +16,6 @@ import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.events.EventNewHistoryData
import info.nightscout.androidaps.extensions.iobCalc
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.ui.dialogs.OKDialog
@ -40,6 +39,7 @@ import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventNSClientRestart
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventTreatmentChange
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag

View file

@ -17,8 +17,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.events.EventNewHistoryData
import info.nightscout.androidaps.extensions.getCustomizedName
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.core.ui.dialogs.OKDialog
@ -35,8 +33,10 @@ import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventEffectiveProfileSwitchChanged
import info.nightscout.rx.events.EventLocalProfileChanged
import info.nightscout.rx.events.EventNSClientRestart
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventProfileSwitchChanged
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag

View file

@ -15,8 +15,6 @@ import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
import info.nightscout.androidaps.events.EventNewHistoryData
import info.nightscout.androidaps.extensions.friendlyDescription
import info.nightscout.androidaps.extensions.highValueToUnitsToString
import info.nightscout.androidaps.extensions.lowValueToUnitsToString
@ -38,7 +36,9 @@ import info.nightscout.interfaces.Translator
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventEffectiveProfileSwitchChanged
import info.nightscout.rx.events.EventNSClientRestart
import info.nightscout.rx.events.EventNewHistoryData
import info.nightscout.rx.events.EventProfileSwitchChanged
import info.nightscout.rx.events.EventTempTargetChange
import info.nightscout.rx.logging.AAPSLogger