Skip to content

Commit 4465444

Browse files
committed
Implement getAllPokemonList for querying previous page items
1 parent af2ef27 commit 4465444

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<application
99
android:name=".PokedexApp"
10-
android:allowBackup="true"
10+
android:allowBackup="false"
1111
android:icon="@mipmap/ic_launcher"
1212
android:label="@string/app_name"
1313
android:roundIcon="@mipmap/ic_launcher_round"

app/src/main/java/com/skydoves/pokedex/persistence/PokemonDao.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ interface PokemonDao {
2828
@Insert(onConflict = OnConflictStrategy.REPLACE)
2929
suspend fun insertPokemonList(pokemonList: List<Pokemon>)
3030

31-
@Query("SELECT * FROM Pokemon WHERE page <= :page_")
31+
@Query("SELECT * FROM Pokemon WHERE page = :page_")
3232
suspend fun getPokemonList(page_: Int): List<Pokemon>
33+
34+
@Query("SELECT * FROM Pokemon WHERE page <= :page_")
35+
suspend fun getAllPokemonList(page_: Int): List<Pokemon>
3336
}

app/src/main/java/com/skydoves/pokedex/repository/MainRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class MainRepository @Inject constructor(
4848
pokemons = response.results
4949
pokemons.forEach { pokemon -> pokemon.page = page }
5050
pokemonDao.insertPokemonList(pokemons)
51-
emit(pokemons)
51+
emit(pokemonDao.getAllPokemonList(page))
5252
onSuccess()
5353
}
5454
}
@@ -63,7 +63,7 @@ class MainRepository @Inject constructor(
6363
onError(message())
6464
}
6565
} else {
66-
emit(pokemons)
66+
emit(pokemonDao.getAllPokemonList(page))
6767
onSuccess()
6868
}
6969
}.flowOn(Dispatchers.IO)

0 commit comments

Comments
 (0)