0

I'm working in a project (using Android's Room Persistence Library) where i want to implement the recent Paging Library by Google. I have tried to approach this without using it, and all is working fine, but when I try to use it by following some tutorials I don't receive any data. Can you guys please help me? I have no idea what I'm doing wrong.

NavigationDao:

    @Query("SELECT chapters.number, chapter, verses.verse_number, name, text  FROM verses INNER JOIN chapters ON chapters.chapter = verses.chapters " +
        "INNER JOIN books ON books._id = chapters.books WHERE text LIKE :keywords AND verses.types_of_verse = 1 ORDER BY verses._id")
    DataSource.Factory<Integer, SearchReference> getSearchResultPagedList(String keywords);

Repository:

    public DataSource.Factory<Integer, SearchReference> getPagedListSearchResult(String keyword){
    return mNavigationDao.getSearchResultPagedList(keyword);
}

ViewModel:

    public LiveData<PagedList<SearchReference>> searchReferencePagedList;
    private SearchKeywordRepository mRepository;

    public SearchKeywordViewModel(SearchKeywordRepository repository, final String keyword){
    this.mRepository = repository;

    allSearchReferenceList = new ArrayList<>();

}

        public void init(String keyword)

    searchReferencePagedList = new LivePagedListBuilder<>(mRepository.getPagedListSearchResult(keyword), 20).build();

}

UI Fragment

    private void observeKeywordQuery(String keywords) {

    mViewModel.init(keywords);

    mViewModel.searchReferencePagedList.observe(this, searchReferenceList -> {
        if (searchReferenceList != null && searchReferenceList.size() > 0) {

            mRecyclerAdapter.submitList(searchReferenceList);

        } else {
            Log.d(LOG_TAG, "No verses retrieved");
        }
    });
}
Daniel Beleza
  • 389
  • 1
  • 15

1 Answers1

0

After a lot of struggle, I found a solution. And that was so straight forward that I'm ashamed.

To debug I would input the chars "deu", directly in View Model. The problem was I forgot to add the '%' sign. So, the moment I inputed "%deu%", everything worked, and I had all results as expected.

Daniel Beleza
  • 389
  • 1
  • 15