From f42ec8435a50e5b60f3913e70498599bc2d0df46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Mon, 11 Nov 2019 15:46:04 +0100 Subject: [PATCH] [Timetable] Show user friendly day name in view pager. --- .../ui/modules/timetable/v2/TimetablePagerAdapter.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetablePagerAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetablePagerAdapter.kt index 84d7a004..63ecdd6d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetablePagerAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/timetable/v2/TimetablePagerAdapter.kt @@ -4,12 +4,17 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.utils.models.Week class TimetablePagerAdapter(val fragmentManager: FragmentManager, val items: List) : FragmentStatePagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { companion object { private const val TAG = "TimetablePagerAdapter" } + private val today by lazy { Date.getToday() } + private val weekStart by lazy { today.clone().stepForward(0, 0, -today.weekDay) } + private val weekEnd by lazy { weekStart.clone().stepForward(0, 0, 6) } + override fun getItem(position: Int): Fragment { return pl.szczodrzynski.edziennik.ui.modules.timetable.v2.day.TimetableDayFragment(items[position]) /*return TimetableDayFragment().apply { @@ -24,6 +29,11 @@ class TimetablePagerAdapter(val fragmentManager: FragmentManager, val items: Lis } override fun getPageTitle(position: Int): CharSequence? { - return items[position].formattedStringShort + val date = items[position] + val pageTitle = StringBuilder(Week.getFullDayName(date.weekDay)) + if (date > weekEnd || date < weekStart) { + pageTitle.append(", ").append(date.stringDm) + } + return pageTitle } } \ No newline at end of file