Ignore future events for status lights

This commit is contained in:
Milos Kozak 2021-09-18 18:06:11 +02:00
parent a448efe09c
commit fb9f5220d3
3 changed files with 5 additions and 5 deletions

View file

@ -74,7 +74,7 @@ class StatusLightHandler @Inject constructor(
private fun handleAge(view: TextView?, type: TherapyEvent.Type, @StringRes warnSettings: Int, defaultWarnThreshold: Double, @StringRes urgentSettings: Int, defaultUrgentThreshold: Double) {
val warn = sp.getDouble(warnSettings, defaultWarnThreshold)
val urgent = sp.getDouble(urgentSettings, defaultUrgentThreshold)
val therapyEvent = repository.getLastTherapyRecord(type).blockingGet()
val therapyEvent = repository.getLastTherapyRecordUpToNow(type).blockingGet()
if (therapyEvent is ValueWrapper.Existing) {
warnColors.setColorByAge(view, therapyEvent.value, warn, urgent)
view?.text = therapyEvent.value.age(resourceHelper.shortTextMode(), resourceHelper, dateUtil)

View file

@ -342,8 +342,8 @@ open class AppRepository @Inject internal constructor(
fun deleteAllTherapyEventsEntries() =
database.therapyEventDao.deleteAllEntries()
fun getLastTherapyRecord(type: TherapyEvent.Type): Single<ValueWrapper<TherapyEvent>> =
database.therapyEventDao.getLastTherapyRecord(type).toWrappedSingle()
fun getLastTherapyRecordUpToNow(type: TherapyEvent.Type): Single<ValueWrapper<TherapyEvent>> =
database.therapyEventDao.getLastTherapyRecord(type, System.currentTimeMillis()).toWrappedSingle()
.subscribeOn(Schedulers.io())
fun getTherapyEventByTimestamp(type: TherapyEvent.Type, timestamp: Long): TherapyEvent? =

View file

@ -39,8 +39,8 @@ internal interface TherapyEventDao : TraceableDao<TherapyEvent> {
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
fun getTherapyEventDataIncludingInvalidFromTime(timestamp: Long): Single<List<TherapyEvent>>
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND isValid = 1 ORDER BY id DESC LIMIT 1")
fun getLastTherapyRecord(type: TherapyEvent.Type): Maybe<TherapyEvent>
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND isValid = 1 AND timestamp <= :now ORDER BY id DESC LIMIT 1")
fun getLastTherapyRecord(type: TherapyEvent.Type, now: Long): Maybe<TherapyEvent>
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
fun compatGetTherapyEventDataFromTime(timestamp: Long): Single<List<TherapyEvent>>