Is it possible to get specific rows from Room with LiveData? My goal is to retrieve certain items from data base, when each item is conditioned by to columns ("page" and "category"). The problem is that in LiveData observer I always receive the same page - that livedata object had been initiated with it in the beginning. It has no effect if I change it afterwards in the ViewModel:
private fun requestNextPageFromDB(page: Int) {
filmsListLiveData = interactor.getPageOfFilmsFromDB(page)
}
I create the LiveData object in init block of my ViewModel:
var filmsListLiveData: LiveData<List<Film>>
init {
filmsListLiveData = interactor.getPageOfFilmsFromDB(2)
The method in Interactor class I initiate the livedata object:
fun getPageOfFilmsFromDB(page: Int): LiveData<List<Film>> =
repo.getPageOfFilmsInCategoryFromDB(page, getFilmsCategoryFromPreferences())
Next method in the repository:
fun getPageOfFilmsInCategoryFromDB(page: Int, category: String): LiveData<List<Film>> {
return filmDao.getCachedFilmsByPageAndCategory(page, category)
}
And the last one in the Dao Intertface:
@Query("SELECT * FROM cached_films WHERE page=:requestedPage AND category=:requestedCategory")
fun getCachedFilmsByPageAndCategory(requestedPage: Int, requestedCategory:String): LiveData<List<Film>>
All the methods above are invoked properly when the page number changes in livedata object.
Thanks a lot in advance.