I have the following SELECT
on the DAO
@Query("SELECT * FROM todo ORDER BY time DESC")
abstract DataSource.Factory<Integer, TodoItem> getAll();
I have a repository that just returns the above. And in the model I have
PagedList.Config config = new PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setInitialLoadSizeHint(40)
.setPageSize(20)
.build();
todos = new LivePagedListBuilder<>(todoRepository.getAll(), config).build();
The Fragment simply observes the above todos
and calls adapter.submitList(items)
on new updates.
I just recently switched to using the androidx.paging
, before I was getting all the data and populating the RecyclerView
with it.
The above code works fine for what it currently is. The problem is that I need support for multiple views. More exactly, I need to add the date on top of the first element with that date. Prior to the upgrade, I was looping the items and adding DateHeader
items where needed (and handling multiple view types in the Adapter), but with this new method I cannot edit what DataSource.Factory
provides.
Using ItemDecoration
or adding the date in every item and changing its visibility are not an option.
I have the date saved in the database as well, so I can group by
and get the item count by date
if that can be of any help.
Is there a way to solve this? Just for reference, there is no network communication here, everything is local and saved only in the database.