Fix bugs in dashboard (#1517)

This commit is contained in:
Rafał Borcz 2021-09-16 11:24:52 +02:00 committed by GitHub
parent 037dbd792f
commit da668f93cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 32 deletions

View File

@ -53,7 +53,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
var onAttendanceTileClickListener: () -> Unit = {}
var onLessonsTileClickListener: () -> Unit = {}
var onLessonsTileClickListener: (LocalDate) -> Unit = {}
var onHomeworkTileClickListener: () -> Unit = {}
@ -275,10 +275,12 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
val item = items[position] as DashboardItem.Lessons
val timetableFull = item.lessons
val binding = lessonsViewHolder.binding
var dateToNavigate = LocalDate.now()
fun updateLessonState() {
val currentDateTime = LocalDateTime.now()
val currentDate = LocalDate.now()
val tomorrowDate = currentDate.plusDays(1)
val currentTimetable = timetableFull?.lessons
.orEmpty()
@ -296,22 +298,27 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
when {
currentTimetable.isNotEmpty() -> {
dateToNavigate = currentDate
updateLessonView(item, currentTimetable, binding)
binding.dashboardLessonsItemTitleTomorrow.isVisible = false
}
tomorrowTimetable.isNotEmpty() -> {
dateToNavigate = tomorrowDate
updateLessonView(item, tomorrowTimetable, binding)
binding.dashboardLessonsItemTitleTomorrow.isVisible = true
}
currentDayHeader != null && currentDayHeader.content.isNotBlank() -> {
dateToNavigate = currentDate
updateLessonView(item, emptyList(), binding, currentDayHeader)
binding.dashboardLessonsItemTitleTomorrow.isVisible = false
}
tomorrowDayHeader != null && tomorrowDayHeader.content.isNotBlank() -> {
dateToNavigate = tomorrowDate
updateLessonView(item, emptyList(), binding, tomorrowDayHeader)
binding.dashboardLessonsItemTitleTomorrow.isVisible = true
}
else -> {
dateToNavigate = tomorrowDate
updateLessonView(item, emptyList(), binding)
binding.dashboardLessonsItemTitleTomorrow.isVisible =
!(item.isLoading && item.error == null)
@ -326,7 +333,7 @@ class DashboardAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView
Handler(Looper.getMainLooper()).post { updateLessonState() }
}
binding.root.setOnClickListener { onLessonsTileClickListener() }
binding.root.setOnClickListener { onLessonsTileClickListener(dateToNavigate) }
}
private fun updateLessonView(

View File

@ -70,10 +70,7 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
override fun initView() {
val mainActivity = requireActivity() as MainActivity
val itemTouchHelper = ItemTouchHelper(
DashboardItemMoveCallback(
dashboardAdapter,
presenter::onDragAndDropEnd
)
DashboardItemMoveCallback(dashboardAdapter, presenter::onDragAndDropEnd)
)
dashboardAdapter.apply {
@ -87,7 +84,9 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
onAttendanceTileClickListener = {
mainActivity.pushView(AttendanceSummaryFragment.newInstance())
}
onLessonsTileClickListener = { mainActivity.pushView(TimetableFragment.newInstance()) }
onLessonsTileClickListener = {
mainActivity.pushView(TimetableFragment.newInstance(it))
}
onGradeTileClickListener = { mainActivity.pushView(GradeFragment.newInstance()) }
onHomeworkTileClickListener = { mainActivity.pushView(HomeworkFragment.newInstance()) }
onAnnouncementsTileClickListener = {

View File

@ -492,31 +492,37 @@ class DashboardPresenter @Inject constructor(
end = LocalDate.now().plusDays(7),
forceRefresh = forceRefresh
)
}.onEach {
when (it.status) {
Status.LOADING -> {
Timber.i("Loading dashboard exams data started")
if (forceRefresh) return@onEach
updateData(
DashboardItem.Exams(it.data.orEmpty(), isLoading = true),
forceRefresh
)
}
.map { examResource ->
val sortedExams = examResource.data?.sortedBy { it.date }
if (!it.data.isNullOrEmpty()) {
firstLoadedItemList += DashboardItem.Type.EXAMS
examResource.copy(data = sortedExams)
}
.onEach {
when (it.status) {
Status.LOADING -> {
Timber.i("Loading dashboard exams data started")
if (forceRefresh) return@onEach
updateData(
DashboardItem.Exams(it.data.orEmpty(), isLoading = true),
forceRefresh
)
if (!it.data.isNullOrEmpty()) {
firstLoadedItemList += DashboardItem.Type.EXAMS
}
}
Status.SUCCESS -> {
Timber.i("Loading dashboard exams result: Success")
updateData(DashboardItem.Exams(it.data ?: emptyList()), forceRefresh)
}
Status.ERROR -> {
Timber.i("Loading dashboard exams result: An exception occurred")
errorHandler.dispatch(it.error!!)
updateData(DashboardItem.Exams(error = it.error), forceRefresh)
}
}
Status.SUCCESS -> {
Timber.i("Loading dashboard exams result: Success")
updateData(DashboardItem.Exams(it.data ?: emptyList()), forceRefresh)
}
Status.ERROR -> {
Timber.i("Loading dashboard exams result: An exception occurred")
errorHandler.dispatch(it.error!!)
updateData(DashboardItem.Exams(error = it.error), forceRefresh)
}
}
}.launch("dashboard_exams")
}.launch("dashboard_exams")
}
private fun loadConferences(student: Student, forceRefresh: Boolean) {

View File

@ -44,7 +44,13 @@ class TimetableFragment : BaseFragment<FragmentTimetableBinding>(R.layout.fragme
companion object {
private const val SAVED_DATE_KEY = "CURRENT_DATE"
fun newInstance() = TimetableFragment()
private const val ARGUMENT_DATE_KEY = "ARGUMENT_DATE"
fun newInstance(date: LocalDate? = null) = TimetableFragment().apply {
arguments = Bundle().apply {
date?.let { putLong(ARGUMENT_DATE_KEY, it.toEpochDay()) }
}
}
}
override val titleStringId get() = R.string.timetable_title
@ -62,7 +68,11 @@ class TimetableFragment : BaseFragment<FragmentTimetableBinding>(R.layout.fragme
super.onViewCreated(view, savedInstanceState)
binding = FragmentTimetableBinding.bind(view)
messageContainer = binding.timetableRecycler
presenter.onAttachView(this, savedInstanceState?.getLong(SAVED_DATE_KEY))
val initDate = savedInstanceState?.getLong(SAVED_DATE_KEY)
?: arguments?.getLong(ARGUMENT_DATE_KEY)?.takeUnless { it == 0L }
presenter.onAttachView(this, initDate)
}
override fun initView() {

View File

@ -11,12 +11,13 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxEms="15"
android:maxLines="1"
android:textSize="13sp"
app:layout_constraintBottom_toBottomOf="@id/dashboard_grades_subitem_grade_container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/dashboard_grades_subitem_grade_container"
tools:text="Urządzenia techniki kompu..." />
tools:text="Urządzenia techniki komputerowych" />
<LinearLayout
android:id="@+id/dashboard_grades_subitem_grade_container"
@ -26,6 +27,7 @@
android:layout_marginBottom="6dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/dashboard_grades_subitem_title"
app:layout_constraintTop_toTopOf="parent">