forked from github/wulkanowy-mirror
Fix lucky number notification (#937)
This commit is contained in:
parent
f8b7baef24
commit
2ad1d086e0
@ -12,5 +12,5 @@ import javax.inject.Singleton
|
||||
interface LuckyNumberDao : BaseDao<LuckyNumber> {
|
||||
|
||||
@Query("SELECT * FROM LuckyNumbers WHERE student_id = :studentId AND date = :date")
|
||||
fun load(studentId: Int, date: LocalDate): Flow<LuckyNumber>
|
||||
fun load(studentId: Int, date: LocalDate): Flow<LuckyNumber?>
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package io.github.wulkanowy.data.repositories.luckynumber
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.networkBoundResource
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import java.time.LocalDate.now
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@ -28,11 +29,8 @@ class LuckyNumberRepository @Inject constructor(
|
||||
}
|
||||
)
|
||||
|
||||
fun getNotNotifiedLuckyNumber(student: Student): Flow<LuckyNumber?> {
|
||||
return local.getLuckyNumber(student, now())
|
||||
}
|
||||
suspend fun getNotNotifiedLuckyNumber(student: Student) =
|
||||
local.getLuckyNumber(student, now()).map { if (it?.isNotified == false) it else null }.first()
|
||||
|
||||
suspend fun updateLuckyNumber(luckyNumber: LuckyNumber?) {
|
||||
local.updateLuckyNumber(luckyNumber)
|
||||
}
|
||||
suspend fun updateLuckyNumber(luckyNumber: LuckyNumber?) = local.updateLuckyNumber(luckyNumber)
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.getCompatColor
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import kotlinx.coroutines.flow.first
|
||||
import javax.inject.Inject
|
||||
import kotlin.random.Random
|
||||
|
||||
@ -33,7 +32,7 @@ class LuckyNumberWork @Inject constructor(
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
luckyNumberRepository.getLuckyNumber(student, true, preferencesRepository.isNotificationsEnable).waitForResult()
|
||||
|
||||
luckyNumberRepository.getNotNotifiedLuckyNumber(student).first()?.let {
|
||||
luckyNumberRepository.getNotNotifiedLuckyNumber(student)?.let {
|
||||
notify(it)
|
||||
luckyNumberRepository.updateLuckyNumber(it.apply { isNotified = true })
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user