Avoid re-loading fragments on the current week/day (#191)

This commit is contained in:
Rafał Borcz 2018-12-02 15:23:46 +01:00 committed by Mikołaj Pich
parent 9a298833f5
commit 48f96b5932
9 changed files with 43 additions and 11 deletions

View File

@ -71,6 +71,10 @@ class AttendanceFragment : BaseFragment(), AttendanceView, MainView.MainChildVie
attendanceAdapter.clear()
}
override fun resetView() {
attendanceAdapter.smoothScrollToPosition(0)
}
override fun onFragmentReselected() {
presenter.onViewReselected()
}

View File

@ -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<*>?) {

View File

@ -17,6 +17,8 @@ interface AttendanceView : BaseView {
fun hideRefresh()
fun resetView()
fun showEmpty(show: Boolean)
fun showProgress(show: Boolean)

View File

@ -77,6 +77,10 @@ class ExamFragment : BaseFragment(), ExamView, MainView.MainChildView, MainView.
examAdapter.clear()
}
override fun resetView() {
examAdapter.smoothScrollToPosition(0)
}
override fun onFragmentReselected() {
presenter.onViewReselected()
}

View File

@ -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) {

View File

@ -17,6 +17,8 @@ interface ExamView : BaseView {
fun hideRefresh()
fun resetView()
fun showEmpty(show: Boolean)
fun showProgress(show: Boolean)

View File

@ -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()
}

View File

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

View File

@ -7,18 +7,20 @@ interface TimetableView : BaseView {
val roomString: String
val isViewEmpty: Boolean
fun initView()
fun updateData(data: List<TimetableItem>)
fun updateNavigationDay(date: String)
fun isViewEmpty(): Boolean
fun clearData()
fun hideRefresh()
fun resetView()
fun showEmpty(show: Boolean)
fun showProgress(show: Boolean)