Fix timetable widget crash when there are no lessons for the day (#1737)

This commit is contained in:
Mikołaj Pich 2021-12-31 09:40:15 +01:00 committed by GitHub
parent 210c3a0e28
commit ba02531aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,13 +73,12 @@ class TimetableWidgetFactory(
updateTheme(appWidgetId) updateTheme(appWidgetId)
lessons = getLessons(date, studentId) lessons = getLessons(date, studentId)
if (date == LocalDate.now()) { val todayLastLessonEndTimestamp = lessons.maxOfOrNull { it.end }
val todayLastLessonEndTimestamp = if (date == LocalDate.now() && todayLastLessonEndTimestamp != null) {
lessons.maxOf { it.end }.toEpochSecond(ZoneOffset.UTC)
sharedPref.putLong( sharedPref.putLong(
getTodayLastLessonEndDateTimeWidgetKey(appWidgetId), key = getTodayLastLessonEndDateTimeWidgetKey(appWidgetId),
todayLastLessonEndTimestamp, value = todayLastLessonEndTimestamp.toEpochSecond(ZoneOffset.UTC),
true sync = true
) )
} }
} }