Producers in action
To finish this chapter, we are going to update our RSS Reader so that it fetches information on demand. The idea is that we will fetch one feed at the beginning, and from there on we fetch one more feed as the user scrolls down close to the end of the list. That way, we reduce the amount of data consumed.
Having the adapter request more articles
We want to be able to request articles as the user scrolls, so the first step is to connect the adapter with the articles to a listener that can fetch more articles when needed. To do this, we are first going to add an interface to the same file where the class ArticleAdapter
resides:
interface ArticleLoader { suspend fun loadMore() } class ArticleAdapter: RecyclerView.Adapter<ArticleAdapter.ViewHolder>(){ ... }
This interface defines a suspending function that will load more articles if possible. Now we need to have the adapter receive an instance of that interface in the constructor, so that anyone using the adapter...