forked from github/wulkanowy-mirror
Fix displaying lessons for tomorrow if there is no more lessons for today (#2416)
This commit is contained in:
parent
ed5166333a
commit
bce92b7347
@ -0,0 +1,33 @@
|
||||
package io.github.wulkanowy.domain.timetable
|
||||
|
||||
import io.github.wulkanowy.data.dataOrNull
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||
import io.github.wulkanowy.data.toFirstResult
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
|
||||
class IsStudentHasLessonsOnWeekendUseCase @Inject constructor(
|
||||
private val timetableRepository: TimetableRepository,
|
||||
private val isWeekendHasLessonsUseCase: IsWeekendHasLessonsUseCase,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
student: Student,
|
||||
semester: Semester,
|
||||
currentDate: LocalDate = LocalDate.now(),
|
||||
): Boolean {
|
||||
val lessons = timetableRepository.getTimetable(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = currentDate.monday,
|
||||
end = currentDate.sunday,
|
||||
forceRefresh = false,
|
||||
timetableType = TimetableRepository.TimetableType.NORMAL
|
||||
).toFirstResult().dataOrNull?.lessons.orEmpty()
|
||||
return isWeekendHasLessonsUseCase(lessons)
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.github.wulkanowy.domain.timetable
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Timetable
|
||||
import java.time.DayOfWeek
|
||||
import javax.inject.Inject
|
||||
|
||||
class IsWeekendHasLessonsUseCase @Inject constructor() {
|
||||
|
||||
operator fun invoke(
|
||||
lessons: List<Timetable>,
|
||||
): Boolean = lessons.any {
|
||||
it.date.dayOfWeek in listOf(
|
||||
DayOfWeek.SATURDAY,
|
||||
DayOfWeek.SUNDAY,
|
||||
)
|
||||
}
|
||||
}
|
@ -24,11 +24,13 @@ import io.github.wulkanowy.data.repositories.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||
import io.github.wulkanowy.domain.adminmessage.GetAppropriateAdminMessageUseCase
|
||||
import io.github.wulkanowy.domain.timetable.IsStudentHasLessonsOnWeekendUseCase
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AdsHelper
|
||||
import io.github.wulkanowy.utils.calculatePercentage
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.combine
|
||||
@ -56,6 +58,7 @@ class DashboardPresenter @Inject constructor(
|
||||
private val messageRepository: MessageRepository,
|
||||
private val attendanceSummaryRepository: AttendanceSummaryRepository,
|
||||
private val timetableRepository: TimetableRepository,
|
||||
private val isStudentHasLessonsOnWeekendUseCase: IsStudentHasLessonsOnWeekendUseCase,
|
||||
private val homeworkRepository: HomeworkRepository,
|
||||
private val examRepository: ExamRepository,
|
||||
private val conferenceRepository: ConferenceRepository,
|
||||
@ -435,14 +438,17 @@ class DashboardPresenter @Inject constructor(
|
||||
private fun loadLessons(student: Student, forceRefresh: Boolean) {
|
||||
flatResourceFlow {
|
||||
val semester = semesterRepository.getCurrentSemester(student)
|
||||
val date = LocalDate.now().nextOrSameSchoolDay
|
||||
val date = when (isStudentHasLessonsOnWeekendUseCase(student, semester)) {
|
||||
true -> LocalDate.now()
|
||||
else -> LocalDate.now().nextOrSameSchoolDay
|
||||
}
|
||||
|
||||
timetableRepository.getTimetable(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = date,
|
||||
end = date,
|
||||
forceRefresh = forceRefresh
|
||||
end = date.sunday,
|
||||
forceRefresh = forceRefresh,
|
||||
)
|
||||
}
|
||||
.onEach {
|
||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.ui.modules.timetable
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import io.github.wulkanowy.data.dataOrNull
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.Timetable
|
||||
@ -20,8 +19,8 @@ import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||
import io.github.wulkanowy.data.toFirstResult
|
||||
import io.github.wulkanowy.data.waitForResult
|
||||
import io.github.wulkanowy.domain.timetable.IsStudentHasLessonsOnWeekendUseCase
|
||||
import io.github.wulkanowy.domain.timetable.IsWeekendHasLessonsUseCase
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
@ -31,16 +30,12 @@ import io.github.wulkanowy.utils.isHolidays
|
||||
import io.github.wulkanowy.utils.isJustFinished
|
||||
import io.github.wulkanowy.utils.isShowTimeUntil
|
||||
import io.github.wulkanowy.utils.left
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
import io.github.wulkanowy.utils.nextSchoolDay
|
||||
import io.github.wulkanowy.utils.previousSchoolDay
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import io.github.wulkanowy.utils.until
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import timber.log.Timber
|
||||
import java.time.DayOfWeek
|
||||
import java.time.Instant
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDate.now
|
||||
@ -54,6 +49,8 @@ class TimetablePresenter @Inject constructor(
|
||||
errorHandler: ErrorHandler,
|
||||
studentRepository: StudentRepository,
|
||||
private val timetableRepository: TimetableRepository,
|
||||
private val isStudentHasLessonsOnWeekendUseCase: IsStudentHasLessonsOnWeekendUseCase,
|
||||
private val isWeekendHasLessonsUseCase: IsWeekendHasLessonsUseCase,
|
||||
private val semesterRepository: SemesterRepository,
|
||||
private val prefRepository: PreferencesRepository,
|
||||
private val analytics: AnalyticsHelper,
|
||||
@ -165,7 +162,7 @@ class TimetablePresenter @Inject constructor(
|
||||
}
|
||||
.logResourceStatus("load timetable data")
|
||||
.onResourceData {
|
||||
isWeekendHasLessons = isWeekendHasLessons || isWeekendHasLessons(it.lessons)
|
||||
isWeekendHasLessons = isWeekendHasLessons || isWeekendHasLessonsUseCase(it.lessons)
|
||||
|
||||
view?.run {
|
||||
enableSwipe(true)
|
||||
@ -199,15 +196,7 @@ class TimetablePresenter @Inject constructor(
|
||||
|
||||
private suspend fun checkInitialAndCurrentDate(student: Student, semester: Semester) {
|
||||
if (initialDate == null) {
|
||||
val lessons = timetableRepository.getTimetable(
|
||||
student = student,
|
||||
semester = semester,
|
||||
start = now().monday,
|
||||
end = now().sunday,
|
||||
forceRefresh = false,
|
||||
timetableType = TimetableRepository.TimetableType.NORMAL
|
||||
).toFirstResult().dataOrNull?.lessons.orEmpty()
|
||||
isWeekendHasLessons = isWeekendHasLessons(lessons)
|
||||
isWeekendHasLessons = isStudentHasLessonsOnWeekendUseCase(student, semester)
|
||||
initialDate = getInitialDate(semester)
|
||||
}
|
||||
|
||||
@ -216,15 +205,6 @@ class TimetablePresenter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun isWeekendHasLessons(
|
||||
lessons: List<Timetable>,
|
||||
): Boolean = lessons.any {
|
||||
it.date.dayOfWeek in listOf(
|
||||
DayOfWeek.SATURDAY,
|
||||
DayOfWeek.SUNDAY,
|
||||
)
|
||||
}
|
||||
|
||||
private fun getInitialDate(semester: Semester): LocalDate {
|
||||
val now = now()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user