I am using Room database layer with LiveData and PagedList to render a ReceycleView
List of chat messages in my app.
This is how my setup looks like:
DataSource.Factory<Integer, Message> factory = ChatDb.getMessages(conversation);
PagedList.Config config = new PagedList.Config.Builder()
.setPageSize(50)
.build();
LiveData<PagedList<Message>> liveData = new LivePagedListBuilder<>(factory, config)
.build();
liveData.observe(this, adapter::submitList);
When the user moves to a new conversation, I need to re-query Room with a new conversation
object.
What would be the proper way to clean up the old factory
and the liveData
, and is there a way to reuse any of those?