From af8bda9e92805fd24f1d7e0791f08460e13e2cce Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sun, 23 Feb 2020 23:16:51 +0100 Subject: [PATCH] [Dialog/Day] Add showing lessons count and length. --- .../edziennik/ui/dialogs/day/DayDialog.kt | 23 +++++++++++++++++++ app/src/main/res/layout/dialog_day.xml | 14 +++++++++++ app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 39 insertions(+) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt index 52a3f53a..b46925f0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/day/DayDialog.kt @@ -14,6 +14,7 @@ import kotlinx.android.synthetic.main.row_lesson_change_item.view.* import kotlinx.android.synthetic.main.row_teacher_absence_item.view.* import kotlinx.coroutines.* import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.data.db.entity.Lesson import pl.szczodrzynski.edziennik.databinding.DialogDayBinding import pl.szczodrzynski.edziennik.ui.dialogs.event.EventDetailsDialog import pl.szczodrzynski.edziennik.ui.dialogs.event.EventListAdapter @@ -22,6 +23,7 @@ import pl.szczodrzynski.edziennik.ui.dialogs.lessonchange.LessonChangeDialog import pl.szczodrzynski.edziennik.ui.dialogs.teacherabsence.TeacherAbsenceDialog import pl.szczodrzynski.edziennik.utils.SimpleDividerItemDecoration import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.utils.models.Time import pl.szczodrzynski.edziennik.utils.models.Week import kotlin.coroutines.CoroutineContext @@ -83,6 +85,27 @@ class DayDialog( date.formattedString ) + val lessons = withContext(Dispatchers.Default) { + app.db.timetableDao().getForDateNow(profileId, date) + }.filter { it.type != Lesson.TYPE_NO_LESSONS } + + if (lessons.isNotEmpty()) { run { + val startTime = lessons.first().startTime ?: return@run + val endTime = lessons.last().endTime ?: return@run + val diff = Time.diff(startTime, endTime) + + b.lessonsInfo.setText( + R.string.dialog_day_lessons_info, + startTime.stringHM, + endTime.stringHM, + lessons.size.toString(), + diff.hour.toString(), + diff.minute.toString() + ) + + b.lessonsInfo.visibility = View.VISIBLE + }} + val lessonChanges = withContext(Dispatchers.Default) { app.db.timetableDao().getChangesForDateNow(profileId, date) } diff --git a/app/src/main/res/layout/dialog_day.xml b/app/src/main/res/layout/dialog_day.xml index d2823940..484f2b2c 100644 --- a/app/src/main/res/layout/dialog_day.xml +++ b/app/src/main/res/layout/dialog_day.xml @@ -26,10 +26,24 @@ android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" + android:layout_marginBottom="8dp" android:textAppearance="@style/NavView.TextView.Title" android:textIsSelectable="true" tools:text="wtorek, 17 grudnia" /> + + By grade\'s value Other Grades settings + %s - %s (%s lessons - %s hours %s minutes) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f6446e3c..89bd6870 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1181,4 +1181,5 @@ Wymagane działanie w aplikacji Problem, który uniemożliwia synchronizację musi być rozwiązany przez użytkownika. Kliknij, aby uzyskać więcej informacji. Librus: wymagane rozwiązanie zadania Captcha. Kliknij, aby kontynuować logowanie do dziennika. + %s - %s (%s lekcji - %s godzin %s minut)