forked from github/wulkanowy-mirror
Allow access to saturday in timetable and attendance (#833)
This commit is contained in:
parent
428b599be0
commit
2cdde78c54
@ -5,7 +5,7 @@ import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.Inter
|
||||
import io.github.wulkanowy.data.db.entities.Attendance
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import io.reactivex.Single
|
||||
@ -22,19 +22,19 @@ class AttendanceRepository @Inject constructor(
|
||||
) {
|
||||
|
||||
fun getAttendance(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean): Single<List<Attendance>> {
|
||||
return local.getAttendance(semester, start.monday, end.friday).filter { !forceRefresh }
|
||||
return local.getAttendance(semester, start.monday, end.sunday).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings).flatMap {
|
||||
if (it) remote.getAttendance(student, semester, start.monday, end.friday)
|
||||
if (it) remote.getAttendance(student, semester, start.monday, end.sunday)
|
||||
else Single.error(UnknownHostException())
|
||||
}.flatMap { newAttendance ->
|
||||
local.getAttendance(semester, start.monday, end.friday)
|
||||
local.getAttendance(semester, start.monday, end.sunday)
|
||||
.toSingle(emptyList())
|
||||
.doOnSuccess { oldAttendance ->
|
||||
local.deleteAttendance(oldAttendance.uniqueSubtract(newAttendance))
|
||||
local.saveAttendance(newAttendance.uniqueSubtract(oldAttendance))
|
||||
}
|
||||
}.flatMap {
|
||||
local.getAttendance(semester, start.monday, end.friday)
|
||||
local.getAttendance(semester, start.monday, end.sunday)
|
||||
.toSingle(emptyList())
|
||||
}).map { list -> list.filter { it.date in start..end } }
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.Inter
|
||||
import io.github.wulkanowy.data.db.entities.CompletedLesson
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import io.reactivex.Single
|
||||
@ -22,20 +22,20 @@ class CompletedLessonsRepository @Inject constructor(
|
||||
) {
|
||||
|
||||
fun getCompletedLessons(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean = false): Single<List<CompletedLesson>> {
|
||||
return local.getCompletedLessons(semester, start.monday, end.friday).filter { !forceRefresh }
|
||||
return local.getCompletedLessons(semester, start.monday, end.sunday).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
if (it) remote.getCompletedLessons(student, semester, start.monday, end.friday)
|
||||
if (it) remote.getCompletedLessons(student, semester, start.monday, end.sunday)
|
||||
else Single.error(UnknownHostException())
|
||||
}.flatMap { new ->
|
||||
local.getCompletedLessons(semester, start.monday, end.friday)
|
||||
local.getCompletedLessons(semester, start.monday, end.sunday)
|
||||
.toSingle(emptyList())
|
||||
.doOnSuccess { old ->
|
||||
local.deleteCompleteLessons(old.uniqueSubtract(new))
|
||||
local.saveCompletedLessons(new.uniqueSubtract(old))
|
||||
}
|
||||
}.flatMap {
|
||||
local.getCompletedLessons(semester, start.monday, end.friday)
|
||||
local.getCompletedLessons(semester, start.monday, end.sunday)
|
||||
.toSingle(emptyList())
|
||||
}).map { list -> list.filter { it.date in start..end } }
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.Inter
|
||||
import io.github.wulkanowy.data.db.entities.Exam
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import io.reactivex.Single
|
||||
@ -22,20 +22,20 @@ class ExamRepository @Inject constructor(
|
||||
) {
|
||||
|
||||
fun getExams(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean = false): Single<List<Exam>> {
|
||||
return local.getExams(semester, start.monday, end.friday).filter { !forceRefresh }
|
||||
return local.getExams(semester, start.monday, end.sunday).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
if (it) remote.getExams(student, semester, start.monday, end.friday)
|
||||
if (it) remote.getExams(student, semester, start.monday, end.sunday)
|
||||
else Single.error(UnknownHostException())
|
||||
}.flatMap { new ->
|
||||
local.getExams(semester, start.monday, end.friday)
|
||||
local.getExams(semester, start.monday, end.sunday)
|
||||
.toSingle(emptyList())
|
||||
.doOnSuccess { old ->
|
||||
local.deleteExams(old.uniqueSubtract(new))
|
||||
local.saveExams(new.uniqueSubtract(old))
|
||||
}
|
||||
}.flatMap {
|
||||
local.getExams(semester, start.monday, end.friday)
|
||||
local.getExams(semester, start.monday, end.sunday)
|
||||
.toSingle(emptyList())
|
||||
}).map { list -> list.filter { it.date in start..end } }
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.Inter
|
||||
import io.github.wulkanowy.data.db.entities.Homework
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import io.reactivex.Completable
|
||||
@ -23,7 +23,7 @@ class HomeworkRepository @Inject constructor(
|
||||
) {
|
||||
|
||||
fun getHomework(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean = false): Single<List<Homework>> {
|
||||
return Single.fromCallable { start.monday to end.friday }.flatMap { (monday, friday) ->
|
||||
return Single.fromCallable { start.monday to end.sunday }.flatMap { (monday, friday) ->
|
||||
local.getHomework(semester, monday, friday).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
|
@ -6,7 +6,7 @@ import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.Timetable
|
||||
import io.github.wulkanowy.services.alarm.TimetableNotificationSchedulerHelper
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import io.reactivex.Single
|
||||
@ -24,13 +24,13 @@ class TimetableRepository @Inject constructor(
|
||||
) {
|
||||
|
||||
fun getTimetable(student: Student, semester: Semester, start: LocalDate, end: LocalDate, forceRefresh: Boolean = false): Single<List<Timetable>> {
|
||||
return Single.fromCallable { start.monday to end.friday }.flatMap { (monday, friday) ->
|
||||
local.getTimetable(semester, monday, friday).filter { !forceRefresh }
|
||||
return Single.fromCallable { start.monday to end.sunday }.flatMap { (monday, sunday) ->
|
||||
local.getTimetable(semester, monday, sunday).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings).flatMap {
|
||||
if (it) remote.getTimetable(student, semester, monday, friday)
|
||||
if (it) remote.getTimetable(student, semester, monday, sunday)
|
||||
else Single.error(UnknownHostException())
|
||||
}.flatMap { new ->
|
||||
local.getTimetable(semester, monday, friday)
|
||||
local.getTimetable(semester, monday, sunday)
|
||||
.toSingle(emptyList())
|
||||
.doOnSuccess { old ->
|
||||
local.deleteTimetable(old.uniqueSubtract(new).also { schedulerHelper.cancelScheduled(it) })
|
||||
@ -46,7 +46,7 @@ class TimetableRepository @Inject constructor(
|
||||
})
|
||||
}
|
||||
}.flatMap {
|
||||
local.getTimetable(semester, monday, friday).toSingle(emptyList())
|
||||
local.getTimetable(semester, monday, sunday).toSingle(emptyList())
|
||||
}).map { list -> list.filter { it.date in start..end }.also { schedulerHelper.scheduleNotifications(it, student) } }
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.attendance.AttendanceRepository
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.reactivex.Completable
|
||||
import org.threeten.bp.LocalDate.now
|
||||
@ -12,7 +12,7 @@ import javax.inject.Inject
|
||||
class AttendanceWork @Inject constructor(private val attendanceRepository: AttendanceRepository) : Work {
|
||||
|
||||
override fun create(student: Student, semester: Semester): Completable {
|
||||
return attendanceRepository.getAttendance(student, semester, now().monday, now().friday, true)
|
||||
return attendanceRepository.getAttendance(student, semester, now().monday, now().sunday, true)
|
||||
.ignoreElement()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.completedlessons.CompletedLessonsRepository
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.reactivex.Completable
|
||||
import org.threeten.bp.LocalDate.now
|
||||
@ -14,7 +14,7 @@ class CompletedLessonWork @Inject constructor(
|
||||
) : Work {
|
||||
|
||||
override fun create(student: Student, semester: Semester): Completable {
|
||||
return completedLessonsRepository.getCompletedLessons(student, semester, now().monday, now().friday, true)
|
||||
return completedLessonsRepository.getCompletedLessons(student, semester, now().monday, now().sunday, true)
|
||||
.ignoreElement()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.exam.ExamRepository
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.reactivex.Completable
|
||||
import org.threeten.bp.LocalDate.now
|
||||
@ -12,6 +12,6 @@ import javax.inject.Inject
|
||||
class ExamWork @Inject constructor(private val examRepository: ExamRepository) : Work {
|
||||
|
||||
override fun create(student: Student, semester: Semester): Completable {
|
||||
return examRepository.getExams(student, semester, now().monday, now().friday, true).ignoreElement()
|
||||
return examRepository.getExams(student, semester, now().monday, now().sunday, true).ignoreElement()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.homework.HomeworkRepository
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.reactivex.Completable
|
||||
import org.threeten.bp.LocalDate.now
|
||||
@ -12,6 +12,6 @@ import javax.inject.Inject
|
||||
class HomeworkWork @Inject constructor(private val homeworkRepository: HomeworkRepository) : Work {
|
||||
|
||||
override fun create(student: Student, semester: Semester): Completable {
|
||||
return homeworkRepository.getHomework(student, semester, now().monday, now().friday, true).ignoreElement()
|
||||
return homeworkRepository.getHomework(student, semester, now().monday, now().sunday, true).ignoreElement()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package io.github.wulkanowy.services.sync.works
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.timetable.TimetableRepository
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.monday
|
||||
import io.reactivex.Completable
|
||||
import org.threeten.bp.LocalDate.now
|
||||
@ -12,7 +12,7 @@ import javax.inject.Inject
|
||||
class TimetableWork @Inject constructor(private val timetableRepository: TimetableRepository) : Work {
|
||||
|
||||
override fun create(student: Student, semester: Semester): Completable {
|
||||
return timetableRepository.getTimetable(student, semester, now().monday, now().friday, true)
|
||||
return timetableRepository.getTimetable(student, semester, now().monday, now().sunday, true)
|
||||
.ignoreElement()
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.getLastSchoolDayIfHoliday
|
||||
import io.github.wulkanowy.utils.isHolidays
|
||||
import io.github.wulkanowy.utils.monday
|
||||
@ -110,7 +110,7 @@ class ExamPresenter @Inject constructor(
|
||||
add(studentRepository.getCurrentStudent()
|
||||
.flatMap { student ->
|
||||
semesterRepository.getCurrentSemester(student).flatMap { semester ->
|
||||
examRepository.getExams(student, semester, currentDate.monday, currentDate.friday, forceRefresh)
|
||||
examRepository.getExams(student, semester, currentDate.monday, currentDate.sunday, forceRefresh)
|
||||
}
|
||||
}
|
||||
.map { createExamItems(it) }
|
||||
@ -181,7 +181,7 @@ class ExamPresenter @Inject constructor(
|
||||
showPreButton(!currentDate.minusDays(7).isHolidays)
|
||||
showNextButton(!currentDate.plusDays(7).isHolidays)
|
||||
updateNavigationWeek("${currentDate.monday.toFormattedString("dd.MM")} - " +
|
||||
currentDate.friday.toFormattedString("dd.MM"))
|
||||
currentDate.sunday.toFormattedString("dd.MM"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.friday
|
||||
import io.github.wulkanowy.utils.sunday
|
||||
import io.github.wulkanowy.utils.getLastSchoolDayIfHoliday
|
||||
import io.github.wulkanowy.utils.isHolidays
|
||||
import io.github.wulkanowy.utils.monday
|
||||
@ -175,7 +175,7 @@ class HomeworkPresenter @Inject constructor(
|
||||
showPreButton(!currentDate.minusDays(7).isHolidays)
|
||||
showNextButton(!currentDate.plusDays(7).isHolidays)
|
||||
updateNavigationWeek("${currentDate.monday.toFormattedString("dd.MM")} - " +
|
||||
currentDate.friday.toFormattedString("dd.MM"))
|
||||
currentDate.sunday.toFormattedString("dd.MM"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class SchooldaysRangeLimiter : DateRangeLimiter {
|
||||
override fun isOutOfRange(year: Int, month: Int, day: Int): Boolean {
|
||||
val date = LocalDate.of(year, month + 1, day)
|
||||
val dayOfWeek = date.dayOfWeek
|
||||
return dayOfWeek == DayOfWeek.SUNDAY || dayOfWeek == DayOfWeek.SATURDAY || date.isHolidays
|
||||
return dayOfWeek == DayOfWeek.SUNDAY || date.isHolidays
|
||||
}
|
||||
|
||||
override fun getStartDate(): Calendar {
|
||||
|
@ -92,8 +92,8 @@ inline val LocalDate.weekDayName: String
|
||||
inline val LocalDate.monday: LocalDate
|
||||
get() = with(MONDAY)
|
||||
|
||||
inline val LocalDate.friday: LocalDate
|
||||
get() = with(FRIDAY)
|
||||
inline val LocalDate.sunday: LocalDate
|
||||
get() = with(SUNDAY)
|
||||
|
||||
/**
|
||||
* [Dz.U. 2016 poz. 1335](http://prawo.sejm.gov.pl/isap.nsf/DocDetails.xsp?id=WDU20160001335)
|
||||
|
@ -38,12 +38,12 @@ class TimeExtensionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fridayTest() {
|
||||
assertEquals(of(2018, 10, 5), of(2018, 10, 2).friday)
|
||||
assertEquals(of(2018, 10, 5), of(2018, 10, 5).friday)
|
||||
assertEquals(of(2018, 10, 5), of(2018, 10, 6).friday)
|
||||
assertEquals(of(2018, 10, 5), of(2018, 10, 7).friday)
|
||||
assertEquals(of(2018, 10, 12), of(2018, 10, 8).friday)
|
||||
fun sundayTestTest() {
|
||||
assertEquals(of(2018, 10, 7), of(2018, 10, 2).sunday)
|
||||
assertEquals(of(2018, 10, 7), of(2018, 10, 5).sunday)
|
||||
assertEquals(of(2018, 10, 7), of(2018, 10, 6).sunday)
|
||||
assertEquals(of(2018, 10, 7), of(2018, 10, 7).sunday)
|
||||
assertEquals(of(2018, 10, 14), of(2018, 10, 8).sunday)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user