В вашем методе loadInitial
просто установите действие повтора
setRetry(Action { loadInitial(params, callback) })
override fun loadInitial(params: LoadInitialParams<String>, callback: LoadInitialCallback<String, Lab>) {
setRetry(Action { loadInitial(params, callback) })
// Set network state if you want
networkState.postValue(Response(Response.ViewState.ERROR, null, Throwable("")))
initialLoad.postValue(Response(Response.ViewState.ERROR, null, Throwable("")))
}
setRetry
метод
private var retryCompletable: Completable? = null
private fun setRetry(action: Action?) {
if (action == null) {
this.retryCompletable = null
} else {
this.retryCompletable = Completable.fromAction(action)
}
}
И когда вы хотите вызвать loadAfter
, вам нужно invalidate
the sourceFactory
.
fun refresh() = sourceFactory.dataSource.value.invalidate()