[Widget/Timetable] Fix widget crashing with NO_LESSONS item.

This commit is contained in:
Kuba Szczodrzyński 2020-01-20 19:27:06 +01:00
parent d8a8bed68d
commit 8cc594d170
2 changed files with 10 additions and 3 deletions

View File

@ -29,6 +29,7 @@ import pl.szczodrzynski.edziennik.*
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
import pl.szczodrzynski.edziennik.data.db.entity.Event.TYPE_HOMEWORK import pl.szczodrzynski.edziennik.data.db.entity.Event.TYPE_HOMEWORK
import pl.szczodrzynski.edziennik.data.db.entity.Lesson import pl.szczodrzynski.edziennik.data.db.entity.Lesson
import pl.szczodrzynski.edziennik.data.db.entity.Lesson.Companion.TYPE_NO_LESSONS
import pl.szczodrzynski.edziennik.ui.widgets.LessonDialogActivity import pl.szczodrzynski.edziennik.ui.widgets.LessonDialogActivity
import pl.szczodrzynski.edziennik.ui.widgets.WidgetConfig import pl.szczodrzynski.edziennik.ui.widgets.WidgetConfig
import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.edziennik.utils.models.Date
@ -77,7 +78,7 @@ class WidgetTimetableProvider : AppWidgetProvider() {
super.onReceive(context, intent) super.onReceive(context, intent)
} }
private val ignoreCancelled = true private val ignoreCancelled = false
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
val thisWidget = ComponentName(context, WidgetTimetableProvider::class.java) val thisWidget = ComponentName(context, WidgetTimetableProvider::class.java)
@ -280,6 +281,8 @@ class WidgetTimetableProvider : AppWidgetProvider() {
val events = app.db.eventDao().getAllByDateNow(profile.id, timetableDate)?.filterNotNull() ?: emptyList() val events = app.db.eventDao().getAllByDateNow(profile.id, timetableDate)?.filterNotNull() ?: emptyList()
lessons.forEachIndexed { pos, lesson -> lessons.forEachIndexed { pos, lesson ->
if (lesson.type == TYPE_NO_LESSONS)
return@forEachIndexed
val model = ItemWidgetTimetableModel() val model = ItemWidgetTimetableModel()
model.bigStyle = widgetConfig.bigStyle model.bigStyle = widgetConfig.bigStyle
@ -289,8 +292,8 @@ class WidgetTimetableProvider : AppWidgetProvider() {
model.lessonId = lesson.id model.lessonId = lesson.id
model.lessonDate = timetableDate model.lessonDate = timetableDate
model.startTime = lesson.displayStartTime model.startTime = lesson.displayStartTime ?: return@forEachIndexed
model.endTime = lesson.displayEndTime model.endTime = lesson.displayEndTime ?: return@forEachIndexed
// check if the lesson has already passed or it's currently in progress // check if the lesson has already passed or it's currently in progress
if (lesson.displayDate == today) { if (lesson.displayDate == today) {

View File

@ -1,5 +1,7 @@
package pl.szczodrzynski.edziennik.utils.models; package pl.szczodrzynski.edziennik.utils.models;
import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -11,7 +13,9 @@ public class ItemWidgetTimetableModel {
public int profileId; public int profileId;
public long lessonId; public long lessonId;
public Date lessonDate; public Date lessonDate;
@NonNull
public Time startTime; public Time startTime;
@NonNull
public Time endTime; public Time endTime;
public boolean lessonPassed; public boolean lessonPassed;
public boolean lessonCurrent; public boolean lessonCurrent;