forked from github/wulkanowy-mirror
Cancel scheduled lesson notifications which turned into canceled (#991)
This commit is contained in:
parent
5092f8c0bf
commit
a87818f3d0
@ -72,18 +72,22 @@ class TimetableNotificationSchedulerHelper @Inject constructor(
|
|||||||
withContext(dispatchersProvider.backgroundThread) {
|
withContext(dispatchersProvider.backgroundThread) {
|
||||||
lessons.groupBy { it.date }
|
lessons.groupBy { it.date }
|
||||||
.map { it.value.sortedBy { lesson -> lesson.start } }
|
.map { it.value.sortedBy { lesson -> lesson.start } }
|
||||||
.map { it.filter { lesson -> !lesson.canceled && lesson.isStudentPlan } }
|
.map { it.filter { lesson -> lesson.isStudentPlan } }
|
||||||
.map { day ->
|
.map { day ->
|
||||||
day.forEachIndexed { index, lesson ->
|
val canceled = day.filter { it.canceled }
|
||||||
val intent = createIntent(student, lesson, day.getOrNull(index + 1))
|
val active = day.filter { !it.canceled }
|
||||||
|
|
||||||
|
cancelScheduled(canceled)
|
||||||
|
active.forEachIndexed { index, lesson ->
|
||||||
|
val intent = createIntent(student, lesson, active.getOrNull(index + 1))
|
||||||
|
|
||||||
if (lesson.start > now()) {
|
if (lesson.start > now()) {
|
||||||
scheduleBroadcast(intent, student.studentId, NOTIFICATION_TYPE_UPCOMING, getUpcomingLessonTime(index, day, lesson))
|
scheduleBroadcast(intent, student.studentId, NOTIFICATION_TYPE_UPCOMING, getUpcomingLessonTime(index, active, lesson))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lesson.end > now()) {
|
if (lesson.end > now()) {
|
||||||
scheduleBroadcast(intent, student.studentId, NOTIFICATION_TYPE_CURRENT, lesson.start)
|
scheduleBroadcast(intent, student.studentId, NOTIFICATION_TYPE_CURRENT, lesson.start)
|
||||||
if (day.lastIndex == index) {
|
if (active.lastIndex == index) {
|
||||||
scheduleBroadcast(intent, student.studentId, NOTIFICATION_TYPE_LAST_LESSON_CANCELLATION, lesson.end)
|
scheduleBroadcast(intent, student.studentId, NOTIFICATION_TYPE_LAST_LESSON_CANCELLATION, lesson.end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.catch
|
|||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.lang.NullPointerException
|
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDate.now
|
import java.time.LocalDate.now
|
||||||
import java.time.LocalDate.of
|
import java.time.LocalDate.of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user