Fix empty view in attendance (#1217)

This commit is contained in:
Rafał Borcz 2021-03-15 00:33:40 +01:00 committed by GitHub
parent c1942d012f
commit eee4e1f4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View File

@ -192,7 +192,7 @@ class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.frag
} }
override fun showContent(show: Boolean) { 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) { override fun showRefresh(show: Boolean) {

View File

@ -190,35 +190,48 @@ class AttendancePresenter @Inject constructor(
flowWithResourceIn { flowWithResourceIn {
val student = studentRepository.getCurrentStudent() val student = studentRepository.getCurrentStudent()
val semester = semesterRepository.getCurrentSemester(student) val semester = semesterRepository.getCurrentSemester(student)
attendanceRepository.getAttendance(student, semester, currentDate, currentDate, forceRefresh) attendanceRepository.getAttendance(
student,
semester,
currentDate,
currentDate,
forceRefresh
)
}.onEach { }.onEach {
when (it.status) { when (it.status) {
Status.LOADING -> { Status.LOADING -> {
view?.showExcuseButton(false) view?.showExcuseButton(false)
if (!it.data.isNullOrEmpty()) { if (!it.data.isNullOrEmpty()) {
val filteredAttendance = if (prefRepository.isShowPresent) {
it.data
} else {
it.data.filter { item -> !item.presence }
}
view?.run { view?.run {
enableSwipe(true) enableSwipe(true)
showRefresh(true) showRefresh(true)
showProgress(false) showProgress(false)
showContent(true) showEmpty(filteredAttendance.isEmpty())
updateData(it.data.let { items -> showContent(filteredAttendance.isNotEmpty())
if (prefRepository.isShowPresent) items updateData(filteredAttendance.sortedBy { item -> item.number })
else items.filter { item -> !item.presence }
}.sortedBy { item -> item.number })
} }
} }
} }
Status.SUCCESS -> { Status.SUCCESS -> {
Timber.i("Loading attendance result: 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 { view?.apply {
updateData(it.data!!.let { items -> updateData(filteredAttendance.sortedBy { item -> item.number })
if (prefRepository.isShowPresent) items showEmpty(filteredAttendance.isEmpty())
else items.filter { item -> !item.presence }
}.sortedBy { item -> item.number })
showEmpty(it.data.isEmpty())
showErrorView(false) showErrorView(false)
showContent(it.data.isNotEmpty()) showContent(filteredAttendance.isNotEmpty())
showExcuseButton(it.data.any { item -> item.excusable }) showExcuseButton(filteredAttendance.any { item -> item.excusable })
} }
analytics.logEvent( analytics.logEvent(
"load_data", "load_data",