I'm trying to make my DataSource.Factory
class, but I get an error when trying to return my PageKeyedDataSource
implementation.
class SubredditPageKeyedDataSource(private val service: LedditService,
private val subredditName: String): PageKeyedDataSource<String, Children<DataX>>() {
@SuppressLint("CheckResult")
override fun loadInitial(params: LoadInitialParams<String>, callback: LoadInitialCallback<String, Children<DataX>>) {
service.getSubredditTopics(subredditName).subscribe { result -> callback.onResult(result.data.children, result.data.before, result.data.after) }
}
@SuppressLint("CheckResult")
override fun loadAfter(params: LoadParams<String>, callback: LoadCallback<String, Children<DataX>>) {
service.getSubredditTopicsAfter(subredditName, after = params.key).subscribe {result -> callback.onResult(result.data.children, result.data.after)}
}
override fun loadBefore(params: LoadParams<String>, callback: LoadCallback<String, Children<DataX>>) {
// ignored, since we only ever append to our initial load
}
}
Now heres my factory:
class SubredditDataSourceFactory(private val service: LedditService,
private val subredditName: String): DataSource.Factory<String, List<Children<DataX>>>() {
override fun create(): DataSource<String, List<Children<DataX>>> {
return SubredditPageKeyedDataSource(service, subredditName)
}
}
When returning my DataSource in the above create()
method, AndroidStudio gives me an IDE error:
Type mismatch.
Required: DataSource<String, List<Children<DataX>>>
Found: SubredditPageKeyedDataSource
Am I going insane? PageKeyedDataSource
extends from ContiguousDataSource
which is a DataSource
. Why am I getting a type mismatch? I've checked 2 different examples of the paging library and their implementation is exactly like mine. Unless I missed something???