Android architecture components paging DataSource.Factory error

Special

New Member
#1
I'm trying to make my DataSource.Factory class, but I get an error when trying to return my PageKeyedDataSource implementation.
Mã:
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:
Mã:
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:
Mã:
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???
 

Admin

Administrator
Thành viên BQT
#2
The types don't actually match.

Your factory is for:

Mã:
PageKeyedDataSource<String, List<Children<DataX>>>
But your datasource implements the type:
Mã:
PageKeyedDataSource<String, Children<DataX>>
Notice that one has a list of children on the right side, the other a single child. The one without the List<> should be correct, try removing that part from your code.
 
Top