这是我在View中的 movieList 观察者
compositeDisposable.add(
viewmodel.movieRemoteList.observeOn(asyncManager.main())
.subscribe({
Log.i("RESPONSE :: ", it.toString())
adapter.add(it)
}, {
Log.i("MOVIEERR :: ", it.message.toString())
})
)
这是数据源工厂
class HomeDataFactory constructor(
var remoteRepository: RemoteRepository, var filter: FilterModel
) : DataSource.Factory<Int, MovieRemote>() {
lateinit var homeDataSource: HomeDataSource
override fun create(): DataSource<Int, MovieRemote> {
homeDataSource = HomeDataSource(remoteRepository, filter)
return homeDataSource
}
}
这是数据源
override fun getKey(item: MovieRemote): Int = item.id!!
override fun loadInitial(
params: LoadInitialParams<Int>,
callback: LoadInitialCallback<MovieRemote>
) {
initialNetworkState.onNext(NetworkLoading)
compositeDisposable.add(
remoteRepository.getMovieList(
newDate, genre, type, filter.startYear, orderBy, audioSubtitleAndOr,
filter.startRating,
limit, filter.endRating, subtitle, selectedCountryList, filter.query, audio,
countryAndOrUnique, offset, filter.endYear
)
.subscribe({
page++
Log.i("LOAD INITIAL :: ", it.toString()+" FK DICK")
it?.let {
it.movieList?.let { movList ->
callback.onResult(movList)
}
}
Log.i("LOAD INITIAL", it.toString())
}, {
initialNetworkState.onNext(NetworkError("FK"))
Log.i("LOAD INITIAL", it.message.toString())
})
)
}
override fun loadAfter(params: LoadParams<Int>, callback: LoadCallback<MovieRemote>) {
this.params = params
this.callback = callback
networkState.onNext(NetworkLoading)
compositeDisposable.add(
remoteRepository.getMovieList(
newDate, genre, type, startYear, orderBy, audioSubtitleAndOr, startRating,
limit, endRating, subtitle, selectedCountryList, filter.query, audio,
countryAndOrUnique, (page * limit.toInt() + 1).toString(), endYear
)
.subscribe({
page++
it?.let {
it.movieList?.let { movList ->
callback.onResult(movList)
}
}
Log.i("LOAD AFTER", "IT IS HERE")
}, {
networkState.onNext(NetworkError("EMPTY"))
Log.i("LOAD AFTER", it.message.toString())
})
)
}
override fun loadBefore(params: LoadParams<Int>, callback: LoadCallback<MovieRemote>) {
}
我已经关闭了互联网并启动了应用程序,调用了 loadInitial() 方法并捕获了错误。之后,在ViewModel中调用movieRemoteList 。我已经搜索了答案,但它并没有解决我的问题。请帮我解决一下这个。