forked from github/szkolny
[Timetable] Fix displaying "no lessons" when all lessons in next 7 days are cancelled.
This commit is contained in:
parent
22d859fcde
commit
2186da416e
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user