[Timetable] Show user friendly day name in view pager.

This commit is contained in:
Kuba Szczodrzyński 2019-11-11 15:46:04 +01:00
parent 1052b824db
commit f42ec8435a

View File

@ -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<Date>) : 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
}
}