1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-22 11:06:05 -06:00

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) {
binding. attendanceRecycler.visibility = if (show) VISIBLE else GONE
binding.attendanceRecycler.visibility = if (show) VISIBLE else GONE
}
override fun showRefresh(show: Boolean) {

View File

@ -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",