Skip to content
Permalink
Browse files

Return single value from getPokemonById database query

  • Loading branch information
zsmb13 committed Jan 7, 2020
1 parent d380051 commit 595f1e4bb7a7d9c37e4f9d33ba7a13116aa20056
@@ -8,7 +8,7 @@ import dev.marcosfarias.pokedex.model.Pokemon
interface PokemonDAO {

@Query("SELECT * FROM pokemon WHERE id = :id")
fun getById(id: String?): LiveData<List<Pokemon?>?>
fun getById(id: String?): LiveData<Pokemon>

@Query("SELECT * FROM pokemon")
fun all(): LiveData<List<Pokemon>>
@@ -35,8 +35,8 @@ class DashboardFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val id = checkNotNull(arguments?.getString("id"))
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { pokemonValue ->
pokemonValue.let { pokemon ->
textViewID.text = pokemon?.id
textViewName.text = pokemon?.name

@@ -10,7 +10,7 @@ class DashboardViewModel : ViewModel() {

private val pokemonDAO: PokemonDAO = App.database.pokemonDAO()

fun getPokemonById(id: String?): LiveData<List<Pokemon?>?> {
fun getPokemonById(id: String?): LiveData<Pokemon> {
return pokemonDAO.getById(id)
}

@@ -40,8 +40,8 @@ class AboutFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val id = checkNotNull(arguments?.getString("id"))
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { pokemonValue ->
pokemonValue.let { pokemon ->
textViewDescription.text = pokemon?.xdescription
textViewHeight.text = pokemon?.height
textViewWeight.text = pokemon?.weight
@@ -41,8 +41,8 @@ class StatsFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

val id = checkNotNull(arguments?.getString("id"))
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { pokemonValue ->
pokemonValue.let { pokemon ->
textViewTypeDefenses.text = pokemon?.ydescription

textViewHP.text = pokemon?.hp.toString()

0 comments on commit 595f1e4

Please sign in to comment.
You can’t perform that action at this time.