@@ -14,25 +14,25 @@ import javax.inject.Inject
14
14
private const val PAGE_SIZE = 50
15
15
private const val INITIAL_LOAD_SIZE = 50
16
16
17
- abstract class PageableDataSource <T >(private val liveDataConverter : LiveDataConverter ) {
17
+ abstract class PageableBaseDataSource <T >(private val liveDataConverter : LiveDataConverter ) {
18
18
19
19
lateinit var query: String
20
- private val dataSourceFactoryFactory: () -> SearchDataSourceFactory <T > = {
20
+ private val dataSourceFactoryFactory: () -> PagingDataSourceFactory <T > = {
21
21
dataSourceFactory(_loadingStates , loadFunction)
22
22
}
23
23
private val _loadingStates = PublishProcessor .create<LoadingState >()
24
24
val loadingStates: Flowable <LoadingState > = _loadingStates
25
- private val _searchResults = PublishProcessor .create<LiveData <PagedList <T >>>()
26
- val searchResults : Flowable <LiveData <PagedList <T >>> = _searchResults
25
+ private val _pagingResults = PublishProcessor .create<LiveData <PagedList <T >>>()
26
+ val pagingResults : Flowable <LiveData <PagedList <T >>> = _pagingResults
27
27
private val _noItemsLoadedEvent = PublishProcessor .create<String >()
28
28
val noItemsLoadedQueries: Flowable <String > = _noItemsLoadedEvent
29
- private var currentFactory: SearchDataSourceFactory <T >? = null
29
+ private var currentFactory: PagingDataSourceFactory <T >? = null
30
30
31
31
abstract val loadFunction: LoadFunction <T >
32
32
33
33
fun onQueryUpdated (query : String ) {
34
34
this .query = query
35
- _searchResults .offer(
35
+ _pagingResults .offer(
36
36
liveDataConverter.convert(dataSourceFactoryFactory().also { currentFactory = it }) {
37
37
_noItemsLoadedEvent .offer(query)
38
38
}
@@ -46,7 +46,7 @@ abstract class PageableDataSource<T>(private val liveDataConverter: LiveDataConv
46
46
47
47
class LiveDataConverter @Inject constructor() {
48
48
fun <T > convert (
49
- dataSourceFactory : SearchDataSourceFactory <T >,
49
+ dataSourceFactory : PagingDataSourceFactory <T >,
50
50
zeroItemsLoadedFunction : () -> Unit
51
51
): LiveData <PagedList <T >> {
52
52
return dataSourceFactory.toLiveData(
@@ -65,7 +65,7 @@ class LiveDataConverter @Inject constructor() {
65
65
66
66
}
67
67
68
- abstract class SearchDataSourceFactory <T >(val loadingStates : LoadingStates ) :
68
+ abstract class PagingDataSourceFactory <T >(val loadingStates : LoadingStates ) :
69
69
DataSource .Factory <Int , T >() {
70
70
private var currentDataSource: SearchDataSource <T >? = null
71
71
abstract val loadFunction: LoadFunction <T >
@@ -80,7 +80,7 @@ abstract class SearchDataSourceFactory<T>(val loadingStates: LoadingStates) :
80
80
}
81
81
82
82
fun <T > dataSourceFactory (loadingStates : LoadingStates , loadFunction : LoadFunction <T >) =
83
- object : SearchDataSourceFactory <T >(loadingStates) {
83
+ object : PagingDataSourceFactory <T >(loadingStates) {
84
84
override val loadFunction: LoadFunction <T > = loadFunction
85
85
}
86
86
0 commit comments