Expand exam sync date range to next month (#960)
This commit is contained in:
@ -2,9 +2,9 @@ package io.github.wulkanowy.data.repositories.exam
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.endExamsDay
|
||||
import io.github.wulkanowy.utils.networkBoundResource
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.startExamsDay
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
@ -18,8 +18,8 @@ class ExamRepository @Inject constructor(
|
||||
|
||||
fun getExams(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean) = networkBoundResource(
|
||||
shouldFetch = { it.isEmpty() || forceRefresh },
|
||||
query = { local.getExams(semester, start.monday, end.sunday) },
|
||||
fetch = { remote.getExams(student, semester, start.monday, end.sunday) },
|
||||
query = { local.getExams(semester, start.startExamsDay, start.endExamsDay) },
|
||||
fetch = { remote.getExams(student, semester, start.startExamsDay, start.endExamsDay) },
|
||||
saveFetchResult = { old, new ->
|
||||
local.deleteExams(old uniqueSubtract new)
|
||||
local.saveExams(new uniqueSubtract old)
|
||||
|
@ -3,8 +3,6 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.exam.ExamRepository
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.waitForResult
|
||||
import java.time.LocalDate.now
|
||||
import javax.inject.Inject
|
||||
@ -12,6 +10,6 @@ import javax.inject.Inject
|
||||
class ExamWork @Inject constructor(private val examRepository: ExamRepository) : Work {
|
||||
|
||||
override suspend fun doWork(student: Student, semester: Semester) {
|
||||
examRepository.getExams(student, semester, now().monday, now().sunday, true).waitForResult()
|
||||
examRepository.getExams(student, semester, now(), now(), true).waitForResult()
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,7 @@ import java.time.Month
|
||||
import java.time.ZoneId
|
||||
import java.time.ZoneOffset
|
||||
import java.time.format.DateTimeFormatter.ofPattern
|
||||
import java.time.format.TextStyle.FULL_STANDALONE
|
||||
import java.time.format.TextStyle.*
|
||||
import java.time.format.TextStyle.FULL
|
||||
import java.time.temporal.TemporalAdjusters.firstInMonth
|
||||
import java.time.temporal.TemporalAdjusters.next
|
||||
import java.time.temporal.TemporalAdjusters.previous
|
||||
@ -78,6 +77,12 @@ inline val LocalDate.nextOrSameSchoolDay: LocalDate
|
||||
}
|
||||
}
|
||||
|
||||
inline val LocalDate.startExamsDay: LocalDate
|
||||
get() = nextOrSameSchoolDay.monday
|
||||
|
||||
inline val LocalDate.endExamsDay: LocalDate
|
||||
get() = nextOrSameSchoolDay.monday.plusWeeks(4).minusDays(1)
|
||||
|
||||
inline val LocalDate.previousOrSameSchoolDay: LocalDate
|
||||
get() {
|
||||
return when (dayOfWeek) {
|
||||
|
Reference in New Issue
Block a user