Fountain is an Android Kotlin library conceived to make your life easier when dealing with paged endpoint services, where the paging is based on incremental page numbers (e.g. 1, 2, 3, ...). It uses the Google Android Architecture Components, mainly the Android Paging Library to make it easier to work with paged services.
The main goal of the library is to provide a Listing component from a common service specification, where the paginated strategy is based on an incremental page number. It provides an awesome way of displaying the paged entity list and reflecting the network state in the UI. If you use this library, you can create an MVVM architecture app and combine it with the repository pattern. If you get a repository which provides a
Listing component of each paged list, you will be creating a robuster app.
It also provides two ways to go: a mode with network support and a mode with network + cache support.
To use this feature you have to provide a
NetworkDataSourceAdapter<out ListResponse<Value>> to the Listing constructor. The library will use it to handle the paging.
Fountain.createNetworkWithCacheSupportListing(networkDataSourceAdapter = networkDataSourceAdapter,cachedDataSourceAdapter = cachedDataSourceAdapter)
There are two required components
NetworkDataSourceAdapter<out ListResponse<Value>> to fetch all pages.
As in the previous way, there are some optional parameters that you can specify in the
The pagination strategy that Fountain is using can be seen in the following image:
The paging strategy starts with an initial service data request. By default the initial data requested is three pages, but this value can be changed, in the
PagedList.Config, using the
setInitialLoadSizeHint method. This parameter can be set in the
Fountain factory method. When the service data comes, all data is refreshed in the
DataSource using the
CachedDataSourceAdapter. Note that the
Listing component will notify that the data changed.
After that, the Android Paging Library will require pages when the local data is running low. When a new page is required, the paging library will invoke a new service call, and will use the
CachedDataSourceAdapter to save the returned data into the
It's strongly recommended to integrate this component in a MVVM architecture combined with the Repository Pattern. The
Listing component should be provided by the repository. The
ViewModel, can use the different
Listing elements, provided by the repository, to show the data and the network changes in the UI.