Good article on the architecture but I think you’re not conveying the usage of LiveData to what makes it useful for the architecture.
You should set up your Observer on the MutableLiveData object then call getPopularBlog()
(possibly rename to loadPopularBlog()
and the Observer observe getPopularBlog()
) in the ViewModel. This function would then do your logic and return nothing but would you would then call postValue
instead of setting the the value and returning live data.
This would then update the MutableLiveData and notify its Observer to update the RecyclerView. Which you are also creating a new adapter every time. Check that the adapter is initialised if it isn’t create one else just update the list with the new items. Inside the Observer can also be where you then set the SwipeRefresh to false. And in the OnRefreshListener you can just call the loadPopularBlog()
from the ViewModel again and it will just notify its Observers in the Activity or Fragment again.