Add missing sdk initialization in lucky number repository (#752)

This commit is contained in:
Mikołaj Pich 2020-04-04 20:59:44 +02:00 committed by GitHub
parent bf61dd1bad
commit 3612326628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package io.github.wulkanowy.data.repositories.luckynumber
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
import io.github.wulkanowy.data.SdkHelper
import io.github.wulkanowy.data.db.entities.LuckyNumber
import io.github.wulkanowy.data.db.entities.Student
import io.reactivex.Completable
@ -15,11 +16,13 @@ import javax.inject.Singleton
class LuckyNumberRepository @Inject constructor(
private val settings: InternetObservingSettings,
private val local: LuckyNumberLocal,
private val remote: LuckyNumberRemote
private val remote: LuckyNumberRemote,
private val sdkHelper: SdkHelper
) {
fun getLuckyNumber(student: Student, forceRefresh: Boolean = false, notify: Boolean = false): Maybe<LuckyNumber> {
return local.getLuckyNumber(student, LocalDate.now()).filter { !forceRefresh }
return Maybe.just(sdkHelper.init(student)).flatMap {
local.getLuckyNumber(student, LocalDate.now()).filter { !forceRefresh }
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
.flatMapMaybe {
if (it) remote.getLuckyNumber(student)
@ -43,6 +46,7 @@ class LuckyNumberRepository @Inject constructor(
{ local.getLuckyNumber(student, LocalDate.now()) })
)
}
}
fun getNotNotifiedLuckyNumber(student: Student): Maybe<LuckyNumber> {
return local.getLuckyNumber(student, LocalDate.now()).filter { !it.isNotified }