Skip to content

Commit

Permalink
Merge pull request #35 from skydoves/migrate/sandwich/1.2.0
Browse files Browse the repository at this point in the history
Migrate Sandwich to 1.2.0
  • Loading branch information
skydoves authored Jun 25, 2021
2 parents f33611f + c8286e7 commit 1177fa3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/skydoves/pokedex/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object NetworkModule {
.client(okHttpClient)
.baseUrl("https://pokeapi.co/api/v2/")
.addConverterFactory(MoshiConverterFactory.create())
.addCallAdapterFactory(CoroutinesResponseCallAdapterFactory())
.addCallAdapterFactory(CoroutinesResponseCallAdapterFactory.create())
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.skydoves.sandwich.map
import com.skydoves.sandwich.onError
import com.skydoves.sandwich.onException
import com.skydoves.sandwich.suspendOnSuccess
import com.skydoves.whatif.whatIfNotNull
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
Expand All @@ -53,10 +52,8 @@ class DetailRepository @Inject constructor(
*/
val response = pokedexClient.fetchPokemonInfo(name = name)
response.suspendOnSuccess {
data.whatIfNotNull { response ->
pokemonInfoDao.insertPokemonInfo(response)
emit(response)
}
pokemonInfoDao.insertPokemonInfo(data)
emit(data)
}
// handles the case when the API request gets an error response.
// e.g., internal server error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.skydoves.sandwich.map
import com.skydoves.sandwich.onError
import com.skydoves.sandwich.onException
import com.skydoves.sandwich.suspendOnSuccess
import com.skydoves.whatif.whatIfNotNull
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
Expand Down Expand Up @@ -55,12 +54,10 @@ class MainRepository @Inject constructor(
*/
val response = pokedexClient.fetchPokemonList(page = page)
response.suspendOnSuccess {
data.whatIfNotNull { response ->
pokemons = response.results
pokemons.forEach { pokemon -> pokemon.page = page }
pokemonDao.insertPokemonList(pokemons)
emit(pokemonDao.getAllPokemonList(page))
}
pokemons = data.results
pokemons.forEach { pokemon -> pokemon.page = page }
pokemonDao.insertPokemonList(pokemons)
emit(pokemonDao.getAllPokemonList(page))
}
// handles the case when the API request gets an error response.
// e.g., internal server error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class ApiAbstract<T> {
return Retrofit.Builder()
.baseUrl(mockWebServer.url("/"))
.addConverterFactory(MoshiConverterFactory.create())
.addCallAdapterFactory(CoroutinesResponseCallAdapterFactory())
.addCallAdapterFactory(CoroutinesResponseCallAdapterFactory.create())
.build()
.create(clazz)
}
Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ext.versions = [
// network
retrofitVersion : '2.9.0',
okhttpVersion : '4.9.0',
sandwichVersion : '1.0.9',
sandwichVersion : '1.2.0',

// moshi
moshiVersion : '1.11.0',
Expand Down

0 comments on commit 1177fa3

Please # to comment.