From eee4e1f4b52fc41a8c397ed2fd79b7c8009f57bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Mon, 15 Mar 2021 00:33:40 +0100 Subject: [PATCH] Fix empty view in attendance (#1217) --- .../modules/attendance/AttendanceFragment.kt | 2 +- .../modules/attendance/AttendancePresenter.kt | 39 ++++++++++++------- 2 files changed, 27 insertions(+), 14 deletions(-) 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 00d5aae87..cb718c724 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 @@ -192,7 +192,7 @@ class AttendanceFragment : BaseFragment(R.layout.frag } override fun showContent(show: Boolean) { - binding. attendanceRecycler.visibility = if (show) VISIBLE else GONE + binding.attendanceRecycler.visibility = if (show) VISIBLE else GONE } override fun showRefresh(show: Boolean) { 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 68802c0c7..b03db91af 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 @@ -190,35 +190,48 @@ class AttendancePresenter @Inject constructor( flowWithResourceIn { val student = studentRepository.getCurrentStudent() val semester = semesterRepository.getCurrentSemester(student) - attendanceRepository.getAttendance(student, semester, currentDate, currentDate, forceRefresh) + attendanceRepository.getAttendance( + student, + semester, + currentDate, + currentDate, + forceRefresh + ) }.onEach { when (it.status) { Status.LOADING -> { view?.showExcuseButton(false) if (!it.data.isNullOrEmpty()) { + val filteredAttendance = if (prefRepository.isShowPresent) { + it.data + } else { + it.data.filter { item -> !item.presence } + } + view?.run { enableSwipe(true) showRefresh(true) showProgress(false) - showContent(true) - updateData(it.data.let { items -> - if (prefRepository.isShowPresent) items - else items.filter { item -> !item.presence } - }.sortedBy { item -> item.number }) + showEmpty(filteredAttendance.isEmpty()) + showContent(filteredAttendance.isNotEmpty()) + updateData(filteredAttendance.sortedBy { item -> item.number }) } } } Status.SUCCESS -> { Timber.i("Loading attendance result: Success") + val filteredAttendance = if (prefRepository.isShowPresent) { + it.data.orEmpty() + } else { + it.data?.filter { item -> !item.presence }.orEmpty() + } + view?.apply { - updateData(it.data!!.let { items -> - if (prefRepository.isShowPresent) items - else items.filter { item -> !item.presence } - }.sortedBy { item -> item.number }) - showEmpty(it.data.isEmpty()) + updateData(filteredAttendance.sortedBy { item -> item.number }) + showEmpty(filteredAttendance.isEmpty()) showErrorView(false) - showContent(it.data.isNotEmpty()) - showExcuseButton(it.data.any { item -> item.excusable }) + showContent(filteredAttendance.isNotEmpty()) + showExcuseButton(filteredAttendance.any { item -> item.excusable }) } analytics.logEvent( "load_data",