From da668f93cf309f4ae4c86f492b23849ca3c66dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Thu, 16 Sep 2021 11:24:52 +0200 Subject: [PATCH] Fix bugs in dashboard (#1517) --- .../ui/modules/dashboard/DashboardAdapter.kt | 11 +++- .../ui/modules/dashboard/DashboardFragment.kt | 9 ++-- .../modules/dashboard/DashboardPresenter.kt | 50 +++++++++++-------- .../ui/modules/timetable/TimetableFragment.kt | 14 +++++- .../res/layout/subitem_dashboard_grades.xml | 4 +- 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt index 0eda4932..11b575c1 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardAdapter.kt @@ -53,7 +53,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter Unit = {} - var onLessonsTileClickListener: () -> Unit = {} + var onLessonsTileClickListener: (LocalDate) -> Unit = {} var onHomeworkTileClickListener: () -> Unit = {} @@ -275,10 +275,12 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter { + dateToNavigate = currentDate updateLessonView(item, currentTimetable, binding) binding.dashboardLessonsItemTitleTomorrow.isVisible = false } tomorrowTimetable.isNotEmpty() -> { + dateToNavigate = tomorrowDate updateLessonView(item, tomorrowTimetable, binding) binding.dashboardLessonsItemTitleTomorrow.isVisible = true } currentDayHeader != null && currentDayHeader.content.isNotBlank() -> { + dateToNavigate = currentDate updateLessonView(item, emptyList(), binding, currentDayHeader) binding.dashboardLessonsItemTitleTomorrow.isVisible = false } tomorrowDayHeader != null && tomorrowDayHeader.content.isNotBlank() -> { + dateToNavigate = tomorrowDate updateLessonView(item, emptyList(), binding, tomorrowDayHeader) binding.dashboardLessonsItemTitleTomorrow.isVisible = true } else -> { + dateToNavigate = tomorrowDate updateLessonView(item, emptyList(), binding) binding.dashboardLessonsItemTitleTomorrow.isVisible = !(item.isLoading && item.error == null) @@ -326,7 +333,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter(R.layout.fragme override fun initView() { val mainActivity = requireActivity() as MainActivity val itemTouchHelper = ItemTouchHelper( - DashboardItemMoveCallback( - dashboardAdapter, - presenter::onDragAndDropEnd - ) + DashboardItemMoveCallback(dashboardAdapter, presenter::onDragAndDropEnd) ) dashboardAdapter.apply { @@ -87,7 +84,9 @@ class DashboardFragment : BaseFragment(R.layout.fragme onAttendanceTileClickListener = { mainActivity.pushView(AttendanceSummaryFragment.newInstance()) } - onLessonsTileClickListener = { mainActivity.pushView(TimetableFragment.newInstance()) } + onLessonsTileClickListener = { + mainActivity.pushView(TimetableFragment.newInstance(it)) + } onGradeTileClickListener = { mainActivity.pushView(GradeFragment.newInstance()) } onHomeworkTileClickListener = { mainActivity.pushView(HomeworkFragment.newInstance()) } onAnnouncementsTileClickListener = { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt index 027bcc05..108a086b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt @@ -492,31 +492,37 @@ class DashboardPresenter @Inject constructor( end = LocalDate.now().plusDays(7), forceRefresh = forceRefresh ) - }.onEach { - when (it.status) { - Status.LOADING -> { - Timber.i("Loading dashboard exams data started") - if (forceRefresh) return@onEach - updateData( - DashboardItem.Exams(it.data.orEmpty(), isLoading = true), - forceRefresh - ) + } + .map { examResource -> + val sortedExams = examResource.data?.sortedBy { it.date } - if (!it.data.isNullOrEmpty()) { - firstLoadedItemList += DashboardItem.Type.EXAMS + examResource.copy(data = sortedExams) + } + .onEach { + when (it.status) { + Status.LOADING -> { + Timber.i("Loading dashboard exams data started") + if (forceRefresh) return@onEach + updateData( + DashboardItem.Exams(it.data.orEmpty(), isLoading = true), + forceRefresh + ) + + if (!it.data.isNullOrEmpty()) { + firstLoadedItemList += DashboardItem.Type.EXAMS + } + } + Status.SUCCESS -> { + Timber.i("Loading dashboard exams result: Success") + updateData(DashboardItem.Exams(it.data ?: emptyList()), forceRefresh) + } + Status.ERROR -> { + Timber.i("Loading dashboard exams result: An exception occurred") + errorHandler.dispatch(it.error!!) + updateData(DashboardItem.Exams(error = it.error), forceRefresh) } } - Status.SUCCESS -> { - Timber.i("Loading dashboard exams result: Success") - updateData(DashboardItem.Exams(it.data ?: emptyList()), forceRefresh) - } - Status.ERROR -> { - Timber.i("Loading dashboard exams result: An exception occurred") - errorHandler.dispatch(it.error!!) - updateData(DashboardItem.Exams(error = it.error), forceRefresh) - } - } - }.launch("dashboard_exams") + }.launch("dashboard_exams") } private fun loadConferences(student: Student, forceRefresh: Boolean) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt index 83218a0d..4478a2a6 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt @@ -44,7 +44,13 @@ class TimetableFragment : BaseFragment(R.layout.fragme companion object { private const val SAVED_DATE_KEY = "CURRENT_DATE" - fun newInstance() = TimetableFragment() + private const val ARGUMENT_DATE_KEY = "ARGUMENT_DATE" + + fun newInstance(date: LocalDate? = null) = TimetableFragment().apply { + arguments = Bundle().apply { + date?.let { putLong(ARGUMENT_DATE_KEY, it.toEpochDay()) } + } + } } override val titleStringId get() = R.string.timetable_title @@ -62,7 +68,11 @@ class TimetableFragment : BaseFragment(R.layout.fragme super.onViewCreated(view, savedInstanceState) binding = FragmentTimetableBinding.bind(view) messageContainer = binding.timetableRecycler - presenter.onAttachView(this, savedInstanceState?.getLong(SAVED_DATE_KEY)) + + val initDate = savedInstanceState?.getLong(SAVED_DATE_KEY) + ?: arguments?.getLong(ARGUMENT_DATE_KEY)?.takeUnless { it == 0L } + + presenter.onAttachView(this, initDate) } override fun initView() { diff --git a/app/src/main/res/layout/subitem_dashboard_grades.xml b/app/src/main/res/layout/subitem_dashboard_grades.xml index 61faa6ac..9354be3d 100644 --- a/app/src/main/res/layout/subitem_dashboard_grades.xml +++ b/app/src/main/res/layout/subitem_dashboard_grades.xml @@ -11,12 +11,13 @@ android:layout_height="wrap_content" android:ellipsize="end" android:includeFontPadding="false" + android:maxEms="15" android:maxLines="1" android:textSize="13sp" app:layout_constraintBottom_toBottomOf="@id/dashboard_grades_subitem_grade_container" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/dashboard_grades_subitem_grade_container" - tools:text="Urządzenia techniki kompu..." /> + tools:text="Urządzenia techniki komputerowych" />