Created
May 21, 2018 12:24
-
-
Save IlyaGulya/0bf8cabbb79b609e56f315242032c090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private abstract class RequestFactoryAdapter<T> { | |
lateinit var paginator: Paginator<T> | |
abstract fun loadPage(page: Int) | |
protected fun onSuccess(data: List<T>) { | |
paginator.currentState.newData(data) | |
} | |
protected fun onError(error: Throwable) { | |
Timber.e("strange error") | |
Timber.e(error) | |
paginator.currentState.fail(error) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class RxJava2Adapter<T>( | |
val requestFactory: (Int) -> io.reactivex.Single<List<T>> | |
) : RequestFactoryAdapter<T>() { | |
var disposable: Disposable? = null | |
override fun loadPage(page: Int) { | |
disposable?.dispose() | |
disposable = requestFactory.invoke(page) | |
.subscribe( | |
{ onSuccess(it) }, | |
{ onError(it) } | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class RxJavaAdapter<T>( | |
val requestFactory: (Int) -> Single<List<T>> | |
) : RequestFactoryAdapter<T>() { | |
var subscription: Subscription? = null | |
override fun loadPage(page: Int) { | |
subscription?.unsubscribe() | |
subscription = requestFactory.invoke(page) | |
.subscribe( | |
{ onSuccess(it) }, | |
{ onError(it) } | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment