From 2186da416e3d1b6c3802c05f625d199d239750ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 18 Mar 2020 12:45:53 +0100 Subject: [PATCH] [Timetable] Fix displaying "no lessons" when all lessons in next 7 days are cancelled. --- .../modules/home/cards/HomeTimetableCard.kt | 19 +++++++++----- .../timetable/WidgetTimetableProvider.kt | 25 ++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt index a675b418..f7f6fa97 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt @@ -137,13 +137,13 @@ class HomeTimetableCard( } private fun update() { launch { + var checkedDays = 0 val deferred = async(Dispatchers.Default) { // get the current bell-synced time val now = syncedNow // search for lessons to display val timetableDate = Date.getToday() - var checkedDays = 0 lessons = allLessons.filter { it.profileId == profile.id && it.displayDate == timetableDate @@ -163,11 +163,14 @@ class HomeTimetableCard( lessons = allLessons.filter { it.profileId == profile.id && it.displayDate == timetableDate - && !(it.isCancelled && ignoreCancelled) } - //if (lessons.isEmpty() && timetableDate.weekDay <= 5) - // break + if (lessons.isEmpty()) + break + + /*lessons = lessons.filterNot { + it.isCancelled && ignoreCancelled + }*/ checkedDays++ } @@ -176,7 +179,7 @@ class HomeTimetableCard( timetableDate = deferred.await() - if (lessons.isEmpty()) { + if (lessons.isEmpty() && checkedDays < 7) { // timetable is not downloaded yet b.timetableLayout.visibility = View.GONE b.noTimetableLayout.visibility = View.VISIBLE @@ -198,14 +201,18 @@ class HomeTimetableCard( ) ).enqueue(activity) } + + timetableDate = Date.getToday() return@launch } - if (lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) { + if (lessons.none { !it.isCancelled } || lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) { // in next 7 days only NO_LESSONS is found b.timetableLayout.visibility = View.GONE b.noTimetableLayout.visibility = View.GONE b.noLessonsLayout.visibility = View.VISIBLE timetableDate = timetableDate.weekStart + + timetableDate = Date.getToday() return@launch } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt index 85073b58..4e0c829f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/widgets/timetable/WidgetTimetableProvider.kt @@ -226,11 +226,14 @@ class WidgetTimetableProvider : AppWidgetProvider() { lessons = lessonList.filter { it.profileId == profile.id && it.displayDate == timetableDate - && !(it.isCancelled && ignoreCancelled) } - //if (lessons.isEmpty() && timetableDate.weekDay <= 5) - // break + if (lessons.isEmpty()) + break + + /*lessons = lessons.filterNot { + it.isCancelled && ignoreCancelled + }*/ checkedDays++ } @@ -248,35 +251,39 @@ class WidgetTimetableProvider : AppWidgetProvider() { models.add(separator) } + views.setViewVisibility(R.id.widgetTimetableListView, View.VISIBLE) + views.setViewVisibility(R.id.widgetTimetableNoTimetable, View.GONE) + views.setViewVisibility(R.id.widgetTimetableNoLessons, View.GONE) + // set the displayingDate to show in the header if (!unified) { if (lessons.isNotEmpty()) displayingDate = timetableDate profileId = profile.id - if (lessons.isEmpty()) { + if (lessons.isEmpty() && checkedDays < 7) { views.setViewVisibility(R.id.widgetTimetableListView, View.GONE) views.setViewVisibility(R.id.widgetTimetableNoTimetable, View.VISIBLE) } - if (lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) { + if (lessons.none { !it.isCancelled } || lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) { views.setViewVisibility(R.id.widgetTimetableListView, View.GONE) views.setViewVisibility(R.id.widgetTimetableNoLessons, View.VISIBLE) } } else { - if (lessons.isEmpty()) { + if (lessons.isEmpty() && checkedDays < 7) { val separator = ItemWidgetTimetableModel() separator.profileId = profile.id separator.bigStyle = widgetConfig.bigStyle separator.darkTheme = widgetConfig.darkTheme - separator.isNoTimetableItem = true; + separator.isNoTimetableItem = true models.add(separator) } - if (lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) { + if (lessons.none { !it.isCancelled } || lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) { val separator = ItemWidgetTimetableModel() separator.profileId = profile.id separator.bigStyle = widgetConfig.bigStyle separator.darkTheme = widgetConfig.darkTheme - separator.isNoLessonsItem = true; + separator.isNoLessonsItem = true models.add(separator) } }