I have an android app in which i want to implement Kotlin Couroutines, the confusion I am having is where do I use the coroutine. I have the viewModel as-
class PostViewModel : ViewModel() {
var postPagedList: LiveData<PagedList<UnsplashImageDetails>>? = null
private var postLiveDataSource: LiveData<PageKeyedDataSource<Int, UnsplashImageDetails>>? = null
var popularPagedList: LiveData<PagedList<UnsplashImageDetails>>? = null
private var popularLiveDataSource: LiveData<PageKeyedDataSource<Int, UnsplashImageDetails>>? = null
init {
val postDataSourceFactory = PostDataSourceFactory()
val popularDataSourceFactory = PopularDataSourceFactory()
postLiveDataSource = postDataSourceFactory.getPostLiveDataSource()
popularLiveDataSource = popularDataSourceFactory.getPopularLiveDataSource()
val config: PagedList.Config = (PagedList.Config.Builder()).setEnablePlaceholders(false)
.setPageSize(PostDataSource().PAGE_SIZE).build()
val configPop: PagedList.Config = (PagedList.Config.Builder()).setEnablePlaceholders(false)
.setPageSize(PopularDataSource().PAGE_SIZE).build()
postPagedList = LivePagedListBuilder(postDataSourceFactory, config).build()
popularPagedList = LivePagedListBuilder(popularDataSourceFactory, configPop).build()
}
}
where should I use the async method, within this activity or in the repository class where I fetch data through retrofit.