1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-23 18:06:01 -06:00

Fix no current student in services after logout all accounts (#342)

This commit is contained in:
Rafał Borcz 2019-05-18 23:42:47 +02:00 committed by Mikołaj Pich
parent 667c4b6af7
commit 0977282a4b
7 changed files with 16 additions and 12 deletions

View File

@ -11,10 +11,10 @@ cache:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
#branches:
# only:
# - master
# - 0.8.x
branches:
only:
- master
- 0.8.x
android:
licenses:

View File

@ -22,6 +22,8 @@ class StudentRepository @Inject constructor(
fun isStudentSaved(): Single<Boolean> = local.getStudents(false).isEmpty.map { !it }
fun isCurrentStudentSet(): Single<Boolean> = local.getCurrentStudent(false).isEmpty.map { !it }
fun getStudents(email: String, password: String, endpoint: String, symbol: String = ""): Single<List<Student>> {
return ReactiveNetwork.checkInternetConnectivity(settings)
.flatMap {

View File

@ -35,7 +35,7 @@ class SyncWorker @AssistedInject constructor(
override fun createWork(): Single<Result> {
Timber.i("SyncWorker is starting")
return studentRepository.isStudentSaved()
return studentRepository.isCurrentStudentSet()
.filter { true }
.flatMap { studentRepository.getCurrentStudent().toMaybe() }
.flatMapCompletable { student ->

View File

@ -100,8 +100,9 @@ class LuckyNumberWidgetProvider : BroadcastReceiver() {
when {
student != null -> Maybe.just(student)
studentId != 0L -> {
studentRepository.getCurrentStudent(false)
.toMaybe()
studentRepository.isCurrentStudentSet()
.filter { true }
.flatMap { studentRepository.getCurrentStudent(false).toMaybe() }
.doOnSuccess { sharedPref.putLong(getStudentWidgetKey(appWidgetId), it.id) }
}
else -> Maybe.empty()

View File

@ -14,7 +14,7 @@ class SplashPresenter @Inject constructor(
override fun onAttachView(view: SplashView) {
super.onAttachView(view)
disposable.add(studentRepository.isStudentSaved()
disposable.add(studentRepository.isCurrentStudentSet()
.subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread)
.subscribe({

View File

@ -161,8 +161,9 @@ class TimetableWidgetProvider : BroadcastReceiver() {
when {
student != null -> Maybe.just(student)
studentId != 0L -> {
studentRepository.getCurrentStudent(false)
.toMaybe()
studentRepository.isCurrentStudentSet()
.filter { true }
.flatMap { studentRepository.getCurrentStudent(false).toMaybe() }
.doOnSuccess { sharedPref.putLong(getStudentWidgetKey(appWidgetId), it.id) }
}
else -> Maybe.empty()

View File

@ -32,14 +32,14 @@ class SplashPresenterTest {
@Test
fun testOpenLoginView() {
doReturn(Single.just(false)).`when`(studentRepository).isStudentSaved()
doReturn(Single.just(false)).`when`(studentRepository).isCurrentStudentSet()
presenter.onAttachView(splashView)
verify(splashView).openLoginView()
}
@Test
fun testMainMainView() {
doReturn(Single.just(true)).`when`(studentRepository).isStudentSaved()
doReturn(Single.just(true)).`when`(studentRepository).isCurrentStudentSet()
presenter.onAttachView(splashView)
verify(splashView).openMainView()
}