[Timetable] Fix displaying "no lessons" when all lessons in next 7 days are cancelled.

This commit is contained in:
Kuba Szczodrzyński 2020-03-18 12:45:53 +01:00
parent 22d859fcde
commit 2186da416e
2 changed files with 29 additions and 15 deletions

View File

@ -137,13 +137,13 @@ class HomeTimetableCard(
} }
private fun update() { launch { private fun update() { launch {
var checkedDays = 0
val deferred = async(Dispatchers.Default) { val deferred = async(Dispatchers.Default) {
// get the current bell-synced time // get the current bell-synced time
val now = syncedNow val now = syncedNow
// search for lessons to display // search for lessons to display
val timetableDate = Date.getToday() val timetableDate = Date.getToday()
var checkedDays = 0
lessons = allLessons.filter { lessons = allLessons.filter {
it.profileId == profile.id it.profileId == profile.id
&& it.displayDate == timetableDate && it.displayDate == timetableDate
@ -163,11 +163,14 @@ class HomeTimetableCard(
lessons = allLessons.filter { lessons = allLessons.filter {
it.profileId == profile.id it.profileId == profile.id
&& it.displayDate == timetableDate && it.displayDate == timetableDate
&& !(it.isCancelled && ignoreCancelled)
} }
//if (lessons.isEmpty() && timetableDate.weekDay <= 5) if (lessons.isEmpty())
// break break
/*lessons = lessons.filterNot {
it.isCancelled && ignoreCancelled
}*/
checkedDays++ checkedDays++
} }
@ -176,7 +179,7 @@ class HomeTimetableCard(
timetableDate = deferred.await() timetableDate = deferred.await()
if (lessons.isEmpty()) { if (lessons.isEmpty() && checkedDays < 7) {
// timetable is not downloaded yet // timetable is not downloaded yet
b.timetableLayout.visibility = View.GONE b.timetableLayout.visibility = View.GONE
b.noTimetableLayout.visibility = View.VISIBLE b.noTimetableLayout.visibility = View.VISIBLE
@ -198,14 +201,18 @@ class HomeTimetableCard(
) )
).enqueue(activity) ).enqueue(activity)
} }
timetableDate = Date.getToday()
return@launch 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 // in next 7 days only NO_LESSONS is found
b.timetableLayout.visibility = View.GONE b.timetableLayout.visibility = View.GONE
b.noTimetableLayout.visibility = View.GONE b.noTimetableLayout.visibility = View.GONE
b.noLessonsLayout.visibility = View.VISIBLE b.noLessonsLayout.visibility = View.VISIBLE
timetableDate = timetableDate.weekStart timetableDate = timetableDate.weekStart
timetableDate = Date.getToday()
return@launch return@launch
} }

View File

@ -226,11 +226,14 @@ class WidgetTimetableProvider : AppWidgetProvider() {
lessons = lessonList.filter { lessons = lessonList.filter {
it.profileId == profile.id it.profileId == profile.id
&& it.displayDate == timetableDate && it.displayDate == timetableDate
&& !(it.isCancelled && ignoreCancelled)
} }
//if (lessons.isEmpty() && timetableDate.weekDay <= 5) if (lessons.isEmpty())
// break break
/*lessons = lessons.filterNot {
it.isCancelled && ignoreCancelled
}*/
checkedDays++ checkedDays++
} }
@ -248,35 +251,39 @@ class WidgetTimetableProvider : AppWidgetProvider() {
models.add(separator) 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 // set the displayingDate to show in the header
if (!unified) { if (!unified) {
if (lessons.isNotEmpty()) if (lessons.isNotEmpty())
displayingDate = timetableDate displayingDate = timetableDate
profileId = profile.id profileId = profile.id
if (lessons.isEmpty()) { if (lessons.isEmpty() && checkedDays < 7) {
views.setViewVisibility(R.id.widgetTimetableListView, View.GONE) views.setViewVisibility(R.id.widgetTimetableListView, View.GONE)
views.setViewVisibility(R.id.widgetTimetableNoTimetable, View.VISIBLE) 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.widgetTimetableListView, View.GONE)
views.setViewVisibility(R.id.widgetTimetableNoLessons, View.VISIBLE) views.setViewVisibility(R.id.widgetTimetableNoLessons, View.VISIBLE)
} }
} }
else { else {
if (lessons.isEmpty()) { if (lessons.isEmpty() && checkedDays < 7) {
val separator = ItemWidgetTimetableModel() val separator = ItemWidgetTimetableModel()
separator.profileId = profile.id separator.profileId = profile.id
separator.bigStyle = widgetConfig.bigStyle separator.bigStyle = widgetConfig.bigStyle
separator.darkTheme = widgetConfig.darkTheme separator.darkTheme = widgetConfig.darkTheme
separator.isNoTimetableItem = true; separator.isNoTimetableItem = true
models.add(separator) 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() val separator = ItemWidgetTimetableModel()
separator.profileId = profile.id separator.profileId = profile.id
separator.bigStyle = widgetConfig.bigStyle separator.bigStyle = widgetConfig.bigStyle
separator.darkTheme = widgetConfig.darkTheme separator.darkTheme = widgetConfig.darkTheme
separator.isNoLessonsItem = true; separator.isNoLessonsItem = true
models.add(separator) models.add(separator)
} }
} }