diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt index 2baaa6ae..bd582a3b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt @@ -71,6 +71,10 @@ class AttendanceFragment : BaseFragment(), AttendanceView, MainView.MainChildVie attendanceAdapter.clear() } + override fun resetView() { + attendanceAdapter.smoothScrollToPosition(0) + } + override fun onFragmentReselected() { presenter.onViewReselected() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt index f576edfd..f1e47093 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendancePresenter.kt @@ -56,8 +56,12 @@ class AttendancePresenter @Inject constructor( } fun onViewReselected() { - loadData(now().previousOrSameSchoolDay) - reloadView() + now().previousOrSameSchoolDay.also { + if (currentDate != it) { + loadData(it) + reloadView() + } else view?.resetView() + } } fun onAttendanceItemSelected(item: AbstractFlexibleItem<*>?) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt index 3479086a..4957b5f0 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceView.kt @@ -17,6 +17,8 @@ interface AttendanceView : BaseView { fun hideRefresh() + fun resetView() + fun showEmpty(show: Boolean) fun showProgress(show: Boolean) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt index abbc2d79..af488af4 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt @@ -77,6 +77,10 @@ class ExamFragment : BaseFragment(), ExamView, MainView.MainChildView, MainView. examAdapter.clear() } + override fun resetView() { + examAdapter.smoothScrollToPosition(0) + } + override fun onFragmentReselected() { presenter.onViewReselected() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamPresenter.kt index 4e7e7705..7d241103 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamPresenter.kt @@ -59,8 +59,13 @@ class ExamPresenter @Inject constructor( } fun onViewReselected() { - loadData(now().nextOrSameSchoolDay) - reloadView() + now().nextOrSameSchoolDay.also { + if (currentDate != it) { + loadData(it) + reloadView() + view?.resetView() + } else view?.resetView() + } } private fun loadData(date: LocalDate, forceRefresh: Boolean = false) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamView.kt index cfe1cb9b..5ee81e8b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamView.kt @@ -17,6 +17,8 @@ interface ExamView : BaseView { fun hideRefresh() + fun resetView() + fun showEmpty(show: Boolean) fun showProgress(show: 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 5247dcee..af9e26da 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 @@ -35,6 +35,9 @@ class TimetableFragment : BaseFragment(), TimetableView, MainView.MainChildView, override val roomString: String get() = getString(R.string.timetable_room) + override val isViewEmpty: Boolean + get() = timetableAdapter.isEmpty + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_timetable, container, false) } @@ -71,12 +74,14 @@ class TimetableFragment : BaseFragment(), TimetableView, MainView.MainChildView, timetableNavDate.text = date } - override fun isViewEmpty() = timetableAdapter.isEmpty - override fun hideRefresh() { timetableSwipe.isRefreshing = false } + override fun resetView() { + timetableAdapter.smoothScrollToPosition(0) + } + override fun onFragmentReselected() { presenter.onViewReselected() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt index fcb6f76a..ef09d257 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt @@ -54,8 +54,12 @@ class TimetablePresenter @Inject constructor( } fun onViewReselected() { - loadData(now().nextOrSameSchoolDay) - reloadView() + now().nextOrSameSchoolDay.also { + if (currentDate != it) { + loadData(it) + reloadView() + } else view?.resetView() + } } fun onTimetableItemSelected(item: AbstractFlexibleItem<*>?) { @@ -88,7 +92,7 @@ class TimetablePresenter @Inject constructor( } logEvent("Timetable load", mapOf("items" to it.size, "forceRefresh" to forceRefresh, "date" to currentDate.toFormattedString())) }) { - view?.run { showEmpty(isViewEmpty()) } + view?.run { showEmpty(isViewEmpty) } errorHandler.dispatch(it) }) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableView.kt index 63ece69f..1411599a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableView.kt @@ -7,18 +7,20 @@ interface TimetableView : BaseView { val roomString: String + val isViewEmpty: Boolean + fun initView() fun updateData(data: List) fun updateNavigationDay(date: String) - fun isViewEmpty(): Boolean - fun clearData() fun hideRefresh() + fun resetView() + fun showEmpty(show: Boolean) fun showProgress(show: Boolean)