Make login helper shareable

This commit is contained in:
Mikołaj Pich 2019-01-09 17:12:24 +01:00
parent 3f26ec14d6
commit 18254728da
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA

View file

@ -11,7 +11,9 @@ import io.github.wulkanowy.api.interceptor.NotLoggedInErrorInterceptor
import io.github.wulkanowy.api.interceptor.StudentAndParentInterceptor
import io.github.wulkanowy.api.interceptor.UserAgentInterceptor
import io.github.wulkanowy.api.login.NotLoggedInException
import io.github.wulkanowy.api.register.HomepageResponse
import io.github.wulkanowy.api.repository.LoginRepository
import io.reactivex.Flowable
import okhttp3.Interceptor
import okhttp3.JavaNetCookieJar
import okhttp3.OkHttpClient
@ -115,7 +117,7 @@ class ServiceManager(
.create()) else JspoonConverterFactory.create())
.addCallAdapterFactory(if (!login) RxJava2CallAdapterFactory.create() else
RxJava2ReauthCallAdapterFactory.create(
LoginRepository(loginType, schema, host, symbol, cookies, getLoginService()).login(email, password).toFlowable(),
getLoginHelper(),
{ it is NotLoggedInException }
)
).build()
@ -138,6 +140,13 @@ class ServiceManager(
}
}
private fun getLoginHelper(): Flowable<HomepageResponse> {
return LoginRepository(loginType, schema, host, symbol, cookies, getLoginService())
.login(email, password)
.toFlowable()
.share()
}
class UrlGenerator(private val schema: String, private val host: String, var symbol: String, var schoolId: String) {
enum class Site {