mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 20:36:05 -06:00
Add checking current student in background services (#295)
This commit is contained in:
parent
36785f019a
commit
316cd2f7f9
@ -11,10 +11,10 @@ cache:
|
||||
- $HOME/.gradle/caches/
|
||||
- $HOME/.gradle/wrapper/
|
||||
|
||||
#branches:
|
||||
# only:
|
||||
# - master
|
||||
# - 0.7.x
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- 0.7.x
|
||||
|
||||
android:
|
||||
licenses:
|
||||
|
@ -34,12 +34,17 @@ class SyncWorker @AssistedInject constructor(
|
||||
) : RxWorker(appContext, workerParameters) {
|
||||
|
||||
override fun createWork(): Single<Result> {
|
||||
return studentRepository.getCurrentStudent()
|
||||
.flatMapCompletable { student ->
|
||||
semesterRepository.getCurrentSemester(student, true)
|
||||
.flatMapCompletable { semester ->
|
||||
Completable.mergeDelayError(works.map { it.create(student, semester) })
|
||||
}
|
||||
return studentRepository.isStudentSaved()
|
||||
.flatMapCompletable { isSaved ->
|
||||
if (isSaved) {
|
||||
studentRepository.getCurrentStudent()
|
||||
.flatMapCompletable { student ->
|
||||
semesterRepository.getCurrentSemester(student)
|
||||
.flatMapCompletable { semester ->
|
||||
Completable.mergeDelayError(works.map { it.create(student, semester) })
|
||||
}
|
||||
}
|
||||
} else Completable.complete()
|
||||
}
|
||||
.toSingleDefault(Result.success())
|
||||
.onErrorReturn {
|
||||
|
@ -17,6 +17,7 @@ import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.data.repositories.timetable.TimetableRepository
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDate
|
||||
import timber.log.Timber
|
||||
|
||||
@ -51,9 +52,13 @@ class TimetableWidgetFactory(
|
||||
?.let { date ->
|
||||
try {
|
||||
lessons = studentRepository.isStudentSaved()
|
||||
.flatMap { studentRepository.getCurrentStudent() }
|
||||
.flatMap { semesterRepository.getCurrentSemester(it) }
|
||||
.flatMap { timetableRepository.getTimetable(it, date, date) }
|
||||
.flatMap { isSaved ->
|
||||
if (isSaved) {
|
||||
studentRepository.getCurrentStudent()
|
||||
.flatMap { semesterRepository.getCurrentSemester(it) }
|
||||
.flatMap { timetableRepository.getTimetable(it, date, date) }
|
||||
} else Single.just(emptyList())
|
||||
}
|
||||
.map { item -> item.sortedBy { it.number } }
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.blockingGet()
|
||||
|
Loading…
Reference in New Issue
Block a user