Skip to content

Commit

Permalink
Release version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed May 7, 2020
1 parent c7ae03a commit 1e758d3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,46 @@ class MainViewModel constructor(
}
```

####
### DataSourceCallAdapterFactory
We can get the `DataSource` directly from the Retrofit service. <br>
Add call adapter factory `DataSourceCallAdapterFactory` to your Retrofit builder. <br>
And change the return type of your service `Call` to `DataSource`.
```kotlin
Retrofit.Builder()
...
.addCallAdapterFactory(DataSourceCallAdapterFactory())
.build()

interface DisneyService {
@GET("DisneyPosters.json")
fun fetchDisneyPosterList(): DataSource<List<Poster>>
}
```
Here is the exmaple of the `DataSource` in the MainViewModel.
```kotlin
class MainViewModel constructor(disneyService: DisneyService) : ViewModel() {

// request API call Asynchronously and holding successful response data.
private val dataSource: DataSource<List<Poster>>

init {
Timber.d("initialized MainViewModel.")

dataSource = disneyService.fetchDisneyPosterList()
// retry fetching data 3 times with 5000L interval when the request gets failure.
.retry(3, 5000L)
.observeResponse(object : ResponseObserver<List<Poster>> {
override fun observe(response: ApiResponse<List<Poster>>) {
// handle the case when the API request gets a success response.
response.onSuccess {
Timber.d("$data")
posterListLiveData.postValue(data)
}
}
})
.request() // must call request()
```


## Find this library useful? :heart:
Support it by joining __[stargazers](https://github.com/skydoves/sandwich/stargazers)__ for this repository. :star: <br>
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext.versions = [
minSdk : 16,
compileSdk : 29,
versionCode : 1,
versionName : '1.0.0',
versionCode : 2,
versionName : '1.0.1',

gradleBuildTool : '3.6.3',
spotlessGradle : '3.28.1',
Expand Down

0 comments on commit 1e758d3

Please sign in to comment.