mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 17:46:14 -06:00
Fix crash on opening date pickers during holidays (#1456)
This commit is contained in:
parent
4aa6b0b995
commit
ea0fb00bde
@ -35,7 +35,8 @@ import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.fragment_attendance), AttendanceView, MainView.MainChildView,
|
||||
class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.fragment_attendance),
|
||||
AttendanceView, MainView.MainChildView,
|
||||
MainView.TitledView {
|
||||
|
||||
@Inject
|
||||
@ -118,7 +119,9 @@ class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.frag
|
||||
with(binding) {
|
||||
attendanceSwipe.setOnRefreshListener(presenter::onSwipeRefresh)
|
||||
attendanceSwipe.setColorSchemeColors(requireContext().getThemeAttrColor(R.attr.colorPrimary))
|
||||
attendanceSwipe.setProgressBackgroundColorSchemeColor(requireContext().getThemeAttrColor(R.attr.colorSwipeRefresh))
|
||||
attendanceSwipe.setProgressBackgroundColorSchemeColor(
|
||||
requireContext().getThemeAttrColor(R.attr.colorSwipeRefresh)
|
||||
)
|
||||
attendanceErrorRetry.setOnClickListener { presenter.onRetry() }
|
||||
attendanceErrorDetails.setOnClickListener { presenter.onDetailsClick() }
|
||||
|
||||
@ -220,17 +223,16 @@ class AttendanceFragment : BaseFragment<FragmentAttendanceBinding>(R.layout.frag
|
||||
}
|
||||
|
||||
override fun showDatePickerDialog(currentDate: LocalDate) {
|
||||
val now = LocalDate.now()
|
||||
val startOfSchoolYear = now.schoolYearStart.toTimestamp()
|
||||
val endWeek = now.plusWeeks(1).toTimestamp()
|
||||
val baseDate = currentDate.schoolYearStart
|
||||
val rangeStart = baseDate.toTimestamp()
|
||||
val rangeEnd = LocalDate.now().plusWeeks(1).toTimestamp()
|
||||
|
||||
val constraintsBuilder = CalendarConstraints.Builder().apply {
|
||||
setValidator(SchoolDaysValidator(startOfSchoolYear, endWeek))
|
||||
setStart(startOfSchoolYear)
|
||||
setEnd(endWeek)
|
||||
setValidator(SchoolDaysValidator(rangeStart, rangeEnd))
|
||||
setStart(rangeStart)
|
||||
setEnd(rangeEnd)
|
||||
}
|
||||
val datePicker =
|
||||
MaterialDatePicker.Builder.datePicker()
|
||||
val datePicker = MaterialDatePicker.Builder.datePicker()
|
||||
.setCalendarConstraints(constraintsBuilder.build())
|
||||
.setSelection(currentDate.toTimestamp())
|
||||
.build()
|
||||
|
@ -112,16 +112,16 @@ class LuckyNumberHistoryFragment :
|
||||
}
|
||||
|
||||
override fun showDatePickerDialog(currentDate: LocalDate) {
|
||||
val now = LocalDate.now()
|
||||
val startOfSchoolYear = now.schoolYearStart.toTimestamp()
|
||||
val baseDate = currentDate.schoolYearStart
|
||||
val rangeStart = baseDate.toTimestamp()
|
||||
val rangeEnd = LocalDate.now().plusWeeks(1).toTimestamp()
|
||||
|
||||
val constraintsBuilder = CalendarConstraints.Builder().apply {
|
||||
setValidator(SchoolDaysValidator(startOfSchoolYear, now.toTimestamp()))
|
||||
setStart(startOfSchoolYear)
|
||||
setEnd(now.toTimestamp())
|
||||
setValidator(SchoolDaysValidator(rangeStart, rangeEnd))
|
||||
setStart(rangeStart)
|
||||
setEnd(rangeEnd)
|
||||
}
|
||||
val datePicker =
|
||||
MaterialDatePicker.Builder.datePicker()
|
||||
val datePicker = MaterialDatePicker.Builder.datePicker()
|
||||
.setCalendarConstraints(constraintsBuilder.build())
|
||||
.setSelection(currentDate.toTimestamp())
|
||||
.build()
|
||||
|
@ -2,18 +2,22 @@ package io.github.wulkanowy.ui.modules.luckynumber.history
|
||||
|
||||
import io.github.wulkanowy.data.Status
|
||||
import io.github.wulkanowy.data.repositories.LuckyNumberRepository
|
||||
import io.github.wulkanowy.data.repositories.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.afterLoading
|
||||
import io.github.wulkanowy.utils.flowWithResource
|
||||
import io.github.wulkanowy.utils.getLastSchoolDayIfHoliday
|
||||
import io.github.wulkanowy.utils.isHolidays
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.previousOrSameSchoolDay
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import timber.log.Timber
|
||||
import java.time.LocalDate
|
||||
@ -22,6 +26,7 @@ import javax.inject.Inject
|
||||
class LuckyNumberHistoryPresenter @Inject constructor(
|
||||
errorHandler: ErrorHandler,
|
||||
studentRepository: StudentRepository,
|
||||
private val semesterRepository: SemesterRepository,
|
||||
private val luckyNumberRepository: LuckyNumberRepository,
|
||||
private val analytics: AnalyticsHelper
|
||||
) : BasePresenter<LuckyNumberHistoryView>(errorHandler, studentRepository) {
|
||||
@ -40,6 +45,19 @@ class LuckyNumberHistoryPresenter @Inject constructor(
|
||||
Timber.i("Lucky number history view was initialized")
|
||||
errorHandler.showErrorMessage = ::showErrorViewOnError
|
||||
loadData()
|
||||
if (currentDate.isHolidays) setBaseDateOnHolidays()
|
||||
}
|
||||
|
||||
private fun setBaseDateOnHolidays() {
|
||||
flow {
|
||||
val student = studentRepository.getCurrentStudent()
|
||||
emit(semesterRepository.getCurrentSemester(student))
|
||||
}.catch {
|
||||
Timber.i("Loading semester result: An exception occurred")
|
||||
}.onEach {
|
||||
currentDate = currentDate.getLastSchoolDayIfHoliday(it.schoolYear)
|
||||
reloadNavigation()
|
||||
}.launch("holidays")
|
||||
}
|
||||
|
||||
private fun loadData() {
|
||||
|
@ -185,17 +185,16 @@ class TimetableFragment : BaseFragment<FragmentTimetableBinding>(R.layout.fragme
|
||||
}
|
||||
|
||||
override fun showDatePickerDialog(currentDate: LocalDate) {
|
||||
val now = LocalDate.now()
|
||||
val startOfSchoolYear = now.schoolYearStart.toTimestamp()
|
||||
val endOfSchoolYear = now.schoolYearEnd.toTimestamp()
|
||||
val baseDate = currentDate.schoolYearStart
|
||||
val rangeStart = baseDate.toTimestamp()
|
||||
val rangeEnd = LocalDate.now().schoolYearEnd.toTimestamp()
|
||||
|
||||
val constraintsBuilder = CalendarConstraints.Builder().apply {
|
||||
setValidator(SchoolDaysValidator(startOfSchoolYear, endOfSchoolYear))
|
||||
setStart(startOfSchoolYear)
|
||||
setEnd(endOfSchoolYear)
|
||||
setValidator(SchoolDaysValidator(rangeStart, rangeEnd))
|
||||
setStart(rangeStart)
|
||||
setEnd(rangeEnd)
|
||||
}
|
||||
val datePicker =
|
||||
MaterialDatePicker.Builder.datePicker()
|
||||
val datePicker = MaterialDatePicker.Builder.datePicker()
|
||||
.setCalendarConstraints(constraintsBuilder.build())
|
||||
.setSelection(currentDate.toTimestamp())
|
||||
.build()
|
||||
|
Loading…
Reference in New Issue
Block a user