mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 19:36:16 -06:00
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) {
|
||||
lessons.groupBy { it.date }
|
||||
.map { it.value.sortedBy { lesson -> lesson.start } }
|
||||
.map { it.filter { lesson -> !lesson.canceled && lesson.isStudentPlan } }
|
||||
.map { it.filter { lesson -> lesson.isStudentPlan } }
|
||||
.map { day ->
|
||||
day.forEachIndexed { index, lesson ->
|
||||
val intent = createIntent(student, lesson, day.getOrNull(index + 1))
|
||||
val canceled = day.filter { it.canceled }
|
||||
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()) {
|
||||
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()) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import timber.log.Timber
|
||||
import java.lang.NullPointerException
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDate.now
|
||||
import java.time.LocalDate.of
|
||||
|
Loading…
Reference in New Issue
Block a user