Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Migrate Sandwich to 1.2.0 #35

Merged
merged 4 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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