I need to be able to change the paging source dynamically.
A screen with 2 functions:
- 1st: Initially loads list of data
- 2nd: Search for a particular data
ViewModel:
class BlogsViewModel: BaseViewModel() {
var blogs = Pager(PagingConfig(10)) {
BlogsDataSource()
}.liveData.cachedIn(viewModelScope)
fun search(keyword: String) {
blogs = Pager(PagingConfig(10)) {
BlogsSearchDataSource("testing")
}.liveData.cachedIn(viewModelScope)
}
fun getBlogs() {
blogs = Pager(PagingConfig(10)) {
BlogsDataSource()
}.liveData.cachedIn(viewModelScope)
}
Whenever I call the "search" function nothing changes.
I tried using adapter.refresh() but didn't work