[UI/Home] Improve displaying cancelled lessons in timetable card.

This commit is contained in:
Kuba Szczodrzyński 2022-09-17 14:58:49 +02:00
parent bb44fa066c
commit a85f935eb4
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB

View File

@ -75,7 +75,7 @@ class HomeTimetableCard(
private var counterEnd: Time? = null private var counterEnd: Time? = null
private var subjectSpannable: CharSequence? = null private var subjectSpannable: CharSequence? = null
private val ignoreCancelled = true private val ignoreCancelled = false
private val countInSeconds: Boolean private val countInSeconds: Boolean
get() = app.config.timetable.countInSeconds get() = app.config.timetable.countInSeconds
@ -160,6 +160,9 @@ class HomeTimetableCard(
&& it.displayEndTime > now && it.displayEndTime > now
&& !(it.isCancelled && ignoreCancelled) && !(it.isCancelled && ignoreCancelled)
} }
if (!ignoreCancelled && lessons.all { it.isCancelled })
// skip current day if all lessons are cancelled
lessons = listOf()
while ((lessons.isEmpty() || lessons.none { while ((lessons.isEmpty() || lessons.none {
it.type != Lesson.TYPE_NO_LESSONS it.type != Lesson.TYPE_NO_LESSONS
&& (it.displayDate != today && (it.displayDate != today
@ -174,6 +177,7 @@ class HomeTimetableCard(
it.profileId == profile.id it.profileId == profile.id
&& it.displayDate == timetableDate && it.displayDate == timetableDate
} }
lessons = lessons.dropWhile { it.isCancelled }
if (lessons.isEmpty()) if (lessons.isEmpty())
break break
@ -238,15 +242,18 @@ class HomeTimetableCard(
b.counter.visibility = View.GONE b.counter.visibility = View.GONE
val now = syncedNow val now = syncedNow
val firstLesson = lessons.firstOrNull() val firstLesson = lessons.firstOrNull { !it.isCancelled }
val lastLesson = lessons.lastOrNull() val lastLesson = lessons.lastOrNull { !it.isCancelled }
val skipFirst = if (firstLesson == null) 0 else lessons.indexOf(firstLesson)
val skipLast = if (lastLesson == null) 0 else lessons.size - 1 - lessons.indexOf(lastLesson)
val lessonCount = lessons.size - skipFirst - skipLast
if (isToday) { if (isToday) {
// today // today
b.dayInfo.setText(R.string.home_timetable_today) b.dayInfo.setText(R.string.home_timetable_today)
b.lessonInfo.setText( b.lessonInfo.setText(
R.string.home_timetable_lessons_remaining, R.string.home_timetable_lessons_remaining,
lessons.size, lessonCount,
lastLesson?.displayEndTime?.stringHM ?: "?" lastLesson?.displayEndTime?.stringHM ?: "?"
) )
counterStart = firstLesson?.displayStartTime counterStart = firstLesson?.displayStartTime
@ -291,12 +298,14 @@ class HomeTimetableCard(
b.dayInfo.setText(dayInfoRes, Week.getFullDayName(timetableDate.weekDay), timetableDate.formattedString) b.dayInfo.setText(dayInfoRes, Week.getFullDayName(timetableDate.weekDay), timetableDate.formattedString)
b.lessonInfo.setText( b.lessonInfo.setText(
R.string.home_timetable_lessons_info, R.string.home_timetable_lessons_info,
lessons.size, lessonCount,
firstLesson?.displayStartTime?.stringHM ?: "?", firstLesson?.displayStartTime?.stringHM ?: "?",
lastLesson?.displayEndTime?.stringHM ?: "?" lastLesson?.displayEndTime?.stringHM ?: "?"
) )
b.lessonBig.setText(R.string.home_timetable_lesson_first, firstLesson.subjectSpannable) b.lessonBig.setText(R.string.home_timetable_lesson_first, firstLesson.subjectSpannable)
b.counter.visibility = View.VISIBLE
b.counter.text = firstLesson?.displayStartTime?.stringHM
firstLesson?.displayClassroom?.let { firstLesson?.displayClassroom?.let {
b.classroom.visibility = View.VISIBLE b.classroom.visibility = View.VISIBLE
b.classroom.text = it b.classroom.text = it
@ -308,9 +317,8 @@ class HomeTimetableCard(
val text = mutableListOf<CharSequence>( val text = mutableListOf<CharSequence>(
activity.getString(R.string.home_timetable_later) activity.getString(R.string.home_timetable_later)
) )
var first = true val nextLessons = lessons.drop(skipFirst + 1)
for (lesson in lessons) { for (lesson in nextLessons) {
if (first) { first = false; continue }
text += listOf( text += listOf(
lesson.displayStartTime?.stringHM, lesson.displayStartTime?.stringHM,
lesson.subjectSpannable lesson.subjectSpannable
@ -363,7 +371,10 @@ class HomeTimetableCard(
b.progress.visibility = View.GONE b.progress.visibility = View.GONE
b.counter.visibility = View.VISIBLE b.counter.visibility = View.VISIBLE
val diff = counterStart - now val diff = counterStart - now
b.counter.text = activity.timeTill(diff.toInt(), "\n", countInSeconds) if (diff >= 60 * MINUTE)
b.counter.text = counterStart.stringHM
else
b.counter.text = activity.timeTill(diff.toInt(), "\n", countInSeconds)
} }
else { else {
// the lesson is right now // the lesson is right now