3

I am building chat app where i am using Room,ViewModel,PagedListAdapter and it's works perfectly but now i want to upgrade my app to Paging Library 3 which caused real pain. I tried to follow official guide of Android but still not able to migrate from lib 2 to version 3 of paging and most of the tutorial are in kotlin when i am using Java in my project.

I start from changing PagedListAdapter to PagingDataAdapter which cause error at main activity

Chat_ViewModel viewModel = new ViewModelProvider(this).get(Chat_ViewModel.class);

       viewModel.chatList.observe(getViewLifecycleOwner(), new Observer<PagedList<ChatEntity_TableColums>>() {

            @Override
            public void onChanged(PagedList<ChatEntity_TableColums> chatEntity_tableColums) {
                Log.d(TAG, "onChanged: Chat Entity = " + chatEntity_tableColums.size());
                adapter.submitList(chatEntity_tableColums); // cannot resolve Submitlist
            }
        });

Then i also tried to upgrade Viewmodel by changing public final LiveData<PagedList<ChatEntity_TableColums>> chatList; to LiveData<PagingData<ChatEntity_TableColums>> chatList; then it cause error in it's constructor,where i cannot find replacement.

public class Chat_ViewModel extends ViewModel {
   private static final String TAG = "Chat View Model";
    public final LiveData<PagedList<ChatEntity_TableColums>> chatList;


    public Chat_ViewModel() {
        chatList = new LivePagedListBuilder<>(
                ChatRoomDatabase.getInstance(MyApplication.getmContext(),1).chatDAO().getPaginationChat(String.valueOf(Session.getOtherUserID())),20).build();
}

    }

This is a query from where i am retrieving the data. I am using default DataSource.Factory to get data from Room @Query("SELECT * FROM Chat WHERE RECEIVER_USER_ID = :UserID ORDER BY ID DESC") DataSource.Factory<Integer, ChatEntity_TableColums> getPaginationChat(String UserID);

Please guide me bit to update my project into paging library 3 with Java

Ritu
  • 518
  • 2
  • 12
  • 35
  • Can you share the error you are getting or can you share your codebase somewhere in Github that way it is easier to help fix all the issues you might be getting? – Dinkar Kumar Jun 29 '21 at 04:12
  • @DinkarKumar please look at this, I will add more code if needed https://github.com/varun7952/pager – Ritu Jun 29 '21 at 14:09

0 Answers0