1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-19 22:29:09 -05:00

Cancel scheduled lesson notifications which turned into canceled (#991)

This commit is contained in:
Mikołaj Pich 2020-10-11 20:51:03 +02:00 committed by GitHub
parent 5092f8c0bf
commit a87818f3d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -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)
}
}

View File

@ -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