1.0.2
🎉 Released a new version 1.0.2
! 🎉
RetainPolicy
We can limit the policy for retaining data on the temporarily internal storage.
The default policy is no retaining any fetched data from the network, but we can set the policy using the dataRetainPolicy
method.
// Retain fetched data on the memory storage temporarily.
// If request again, returns the retained data instead of re-fetching from the network.
dataSource.dataRetainPolicy(DataRetainPolicy.RETAIN)
asLiveData
we can observe fetched data via DataSource
as a LiveData
.
- if the response is successful, it returns a [LiveData] which contains response data.
- if the response is failure or exception, it returns an empty [LiveData].
val posterListLiveData: LiveData<List<Poster>>
init {
posterListLiveData = disneyService.fetchDisneyPosterList().toResponseDataSource()
.retry(3, 5000L)
.dataRetainPolicy(DataRetainPolicy.RETAIN)
.request {
// ...
}.asLiveData()
}
toResponseDataSource
If we use DataSourceCallAdapterFactory
, we can only get the DataSource
interface instead of ResponseDataSource
. So in this release, there is a new way to change DataSource
to ResponseDataSource
.
We can change DataSource
to ResponseDataSource
after getting instance from network call using the below method.
private val dataSource: ResponseDataSource<List<Poster>>
init {
dataSource = disneyService.fetchDisneyPosterList().toResponseDataSource()
//...
}