epoxy
epoxy copied to clipboard
PagingDataEpoxyController never calls addModels() when PagingData is empty
PagingDataEpoxyController is easy to set up and works great however I am facing some issues in displaying a model when the PagingData is empty. I have tried to override the addModels() method but seems it never gets triggered when data is empty. Not sure if I am missing something here.
PS: I am new to Kotlin and Android
Paging model
class PagingModel : ViewModel() {
var repository = PagingRepository()
fun query(query: Query): Flow<PagingData<DocumentSnapshot>> =
repository.query(query).cachedIn(viewModelScope)
}
Paging Repository
class PagingRepository {
fun query(query: Query): Flow<PagingData<DocumentSnapshot>> {
return Pager(
config = PagingConfig(
pageSize = NETWORK_PAGE_SIZE,
prefetchDistance = 1,
enablePlaceholders = false
),
pagingSourceFactory = {
FirestorePagingSource(query, Source.DEFAULT)
}
).flow
}
companion object {
const val NETWORK_PAGE_SIZE = 30
}
}
I am loading data from onCreateView() of fragment
lifecycleScope.launchWhenCreated {
pagingModel.query(query).collectLatest {
Timber.d("before submit data")
recyclerView.setController(controller)
controller.submitData(it)
Timber.d("after submit data") // ==============> THIS IS NEVER PRINTED
}
}
My Controller class
inner class Controller : PagingDataEpoxyController<DocumentSnapshot>() {
override fun addModels(models: List<EpoxyModel<*>>) {
add(photo()) // =============> THIS NEVER GETS CALLED WHEN DATA IS EMPTY
super.addModels(models)
}
override fun buildItemModel(
currentPosition: Int,
item: DocumentSnapshot?
): EpoxyModel<*> {
// my model here
}
}