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.StudentRepository
|
||||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||||
import io.github.wulkanowy.domain.adminmessage.GetAppropriateAdminMessageUseCase
|
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.BasePresenter
|
||||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||||
import io.github.wulkanowy.utils.AdsHelper
|
import io.github.wulkanowy.utils.AdsHelper
|
||||||
import io.github.wulkanowy.utils.calculatePercentage
|
import io.github.wulkanowy.utils.calculatePercentage
|
||||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||||
|
import io.github.wulkanowy.utils.sunday
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@ -56,6 +58,7 @@ class DashboardPresenter @Inject constructor(
|
|||||||
private val messageRepository: MessageRepository,
|
private val messageRepository: MessageRepository,
|
||||||
private val attendanceSummaryRepository: AttendanceSummaryRepository,
|
private val attendanceSummaryRepository: AttendanceSummaryRepository,
|
||||||
private val timetableRepository: TimetableRepository,
|
private val timetableRepository: TimetableRepository,
|
||||||
|
private val isStudentHasLessonsOnWeekendUseCase: IsStudentHasLessonsOnWeekendUseCase,
|
||||||
private val homeworkRepository: HomeworkRepository,
|
private val homeworkRepository: HomeworkRepository,
|
||||||
private val examRepository: ExamRepository,
|
private val examRepository: ExamRepository,
|
||||||
private val conferenceRepository: ConferenceRepository,
|
private val conferenceRepository: ConferenceRepository,
|
||||||
@ -435,14 +438,17 @@ class DashboardPresenter @Inject constructor(
|
|||||||
private fun loadLessons(student: Student, forceRefresh: Boolean) {
|
private fun loadLessons(student: Student, forceRefresh: Boolean) {
|
||||||
flatResourceFlow {
|
flatResourceFlow {
|
||||||
val semester = semesterRepository.getCurrentSemester(student)
|
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(
|
timetableRepository.getTimetable(
|
||||||
student = student,
|
student = student,
|
||||||
semester = semester,
|
semester = semester,
|
||||||
start = date,
|
start = date,
|
||||||
end = date,
|
end = date.sunday,
|
||||||
forceRefresh = forceRefresh
|
forceRefresh = forceRefresh,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.onEach {
|
.onEach {
|
||||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.ui.modules.timetable
|
|||||||
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
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.Semester
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.data.db.entities.Timetable
|
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.SemesterRepository
|
||||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||||
import io.github.wulkanowy.data.toFirstResult
|
import io.github.wulkanowy.domain.timetable.IsStudentHasLessonsOnWeekendUseCase
|
||||||
import io.github.wulkanowy.data.waitForResult
|
import io.github.wulkanowy.domain.timetable.IsWeekendHasLessonsUseCase
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter
|
import io.github.wulkanowy.ui.base.BasePresenter
|
||||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
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.isJustFinished
|
||||||
import io.github.wulkanowy.utils.isShowTimeUntil
|
import io.github.wulkanowy.utils.isShowTimeUntil
|
||||||
import io.github.wulkanowy.utils.left
|
import io.github.wulkanowy.utils.left
|
||||||
import io.github.wulkanowy.utils.monday
|
|
||||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||||
import io.github.wulkanowy.utils.nextSchoolDay
|
import io.github.wulkanowy.utils.nextSchoolDay
|
||||||
import io.github.wulkanowy.utils.previousSchoolDay
|
import io.github.wulkanowy.utils.previousSchoolDay
|
||||||
import io.github.wulkanowy.utils.sunday
|
|
||||||
import io.github.wulkanowy.utils.toFormattedString
|
import io.github.wulkanowy.utils.toFormattedString
|
||||||
import io.github.wulkanowy.utils.until
|
import io.github.wulkanowy.utils.until
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.time.DayOfWeek
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDate.now
|
import java.time.LocalDate.now
|
||||||
@ -54,6 +49,8 @@ class TimetablePresenter @Inject constructor(
|
|||||||
errorHandler: ErrorHandler,
|
errorHandler: ErrorHandler,
|
||||||
studentRepository: StudentRepository,
|
studentRepository: StudentRepository,
|
||||||
private val timetableRepository: TimetableRepository,
|
private val timetableRepository: TimetableRepository,
|
||||||
|
private val isStudentHasLessonsOnWeekendUseCase: IsStudentHasLessonsOnWeekendUseCase,
|
||||||
|
private val isWeekendHasLessonsUseCase: IsWeekendHasLessonsUseCase,
|
||||||
private val semesterRepository: SemesterRepository,
|
private val semesterRepository: SemesterRepository,
|
||||||
private val prefRepository: PreferencesRepository,
|
private val prefRepository: PreferencesRepository,
|
||||||
private val analytics: AnalyticsHelper,
|
private val analytics: AnalyticsHelper,
|
||||||
@ -165,7 +162,7 @@ class TimetablePresenter @Inject constructor(
|
|||||||
}
|
}
|
||||||
.logResourceStatus("load timetable data")
|
.logResourceStatus("load timetable data")
|
||||||
.onResourceData {
|
.onResourceData {
|
||||||
isWeekendHasLessons = isWeekendHasLessons || isWeekendHasLessons(it.lessons)
|
isWeekendHasLessons = isWeekendHasLessons || isWeekendHasLessonsUseCase(it.lessons)
|
||||||
|
|
||||||
view?.run {
|
view?.run {
|
||||||
enableSwipe(true)
|
enableSwipe(true)
|
||||||
@ -199,15 +196,7 @@ class TimetablePresenter @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun checkInitialAndCurrentDate(student: Student, semester: Semester) {
|
private suspend fun checkInitialAndCurrentDate(student: Student, semester: Semester) {
|
||||||
if (initialDate == null) {
|
if (initialDate == null) {
|
||||||
val lessons = timetableRepository.getTimetable(
|
isWeekendHasLessons = isStudentHasLessonsOnWeekendUseCase(student, semester)
|
||||||
student = student,
|
|
||||||
semester = semester,
|
|
||||||
start = now().monday,
|
|
||||||
end = now().sunday,
|
|
||||||
forceRefresh = false,
|
|
||||||
timetableType = TimetableRepository.TimetableType.NORMAL
|
|
||||||
).toFirstResult().dataOrNull?.lessons.orEmpty()
|
|
||||||
isWeekendHasLessons = isWeekendHasLessons(lessons)
|
|
||||||
initialDate = getInitialDate(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 {
|
private fun getInitialDate(semester: Semester): LocalDate {
|
||||||
val now = now()
|
val now = now()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user