Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

added evolution navigation to the selected pokemon #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Also available in Play Store

## Contributors

| [<img src="https://avatars3.githubusercontent.com/u/12054216?s=115&v=4" width="48"><br><sub>@zsmb13</sub>](https://github.com/zsmb13) | [<img src="https://avatars0.githubusercontent.com/u/8435541?s=115&v=4" width="48"><br><sub>@aesean</sub>](https://github.com/aesean) | [<img src="https://avatars1.githubusercontent.com/u/988405?s=115&v=4" width="48"><br><sub>@STFBEE</sub>](https://github.com/STFBEE) | [<img src="https://avatars1.githubusercontent.com/u/25616312?s=115&v=4" width="48"><br><sub>@CorneilleEdi</sub>](https://github.com/CorneilleEdi) | [<img src="https://avatars2.githubusercontent.com/u/15768474?s=115&v=4" width="48"><br><sub>@naufalprakoso</sub>](https://github.com/naufalprakoso) | [<img src="https://user-images.githubusercontent.com/95717/60592969-5da81680-9d67-11e9-92a3-8664ee0e2eda.png" width="48"><br><sub>You</sub>](https://github.com/mrcsxsiq/Kotlin-Pokedex/pulls) |
| :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/12054216?s=115&v=4" width="48"><br><sub>@zsmb13</sub>](https://github.com/zsmb13) | [<img src="https://avatars0.githubusercontent.com/u/8435541?s=115&v=4" width="48"><br><sub>@aesean</sub>](https://github.com/aesean) | [<img src="https://avatars1.githubusercontent.com/u/988405?s=115&v=4" width="48"><br><sub>@STFBEE</sub>](https://github.com/STFBEE) | [<img src="https://avatars1.githubusercontent.com/u/25616312?s=115&v=4" width="48"><br><sub>@CorneilleEdi</sub>](https://github.com/CorneilleEdi) | [<img src="https://avatars2.githubusercontent.com/u/15768474?s=115&v=4" width="48"><br><sub>@naufalprakoso</sub>](https://github.com/naufalprakoso) | [<img src="https://avatars1.githubusercontent.com/u/29981475?s=460&u=44d30f0d99736307a7154cabff89e17b2bc9ccc5&v=4" width="48"><br><sub>@guyshoham</sub>](https://github.com/guyshoham) | [<img src="https://user-images.githubusercontent.com/95717/60592969-5da81680-9d67-11e9-92a3-8664ee0e2eda.png" width="48"><br><sub>You</sub>](https://github.com/mrcsxsiq/Kotlin-Pokedex/pulls) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |

## Author

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import dev.marcosfarias.pokedex.R
import dev.marcosfarias.pokedex.utils.PokemonColorUtil
import kotlinx.android.synthetic.main.fragment_dashboard.*
Expand Down Expand Up @@ -62,6 +63,7 @@ class DashboardFragment : Fragment() {
Glide.with(view.context)
.load(pokemon.imageurl)
.placeholder(android.R.color.transparent)
.transition(DrawableTransitionOptions.withCrossFade())
.into(imageView)

val pager = viewPager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import android.graphics.PorterDuffColorFilter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import dev.marcosfarias.pokedex.R
import dev.marcosfarias.pokedex.model.Pokemon
import dev.marcosfarias.pokedex.utils.PokemonColorUtil
import kotlinx.android.synthetic.main.item_pokemon.view.*

class EvolutionAdapter(
private val context: Context
private val context: Context,
private val currentPokemonId: String

) : RecyclerView.Adapter<EvolutionAdapter.ViewHolder>() {

private val list = arrayListOf<Pokemon>()
Expand Down Expand Up @@ -52,6 +57,7 @@ class EvolutionAdapter(
Glide.with(itemView.context)
.load(item.imageurl)
.placeholder(android.R.color.transparent)
.transition(DrawableTransitionOptions.withCrossFade())
.into(itemView.imageView)
}
}
Expand All @@ -64,6 +70,14 @@ class EvolutionAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = list[position]
holder.bindView(item)

holder.itemView.setOnClickListener {
if (currentPokemonId != item.id) {
val bundle = bundleOf("id" to item.id)
it.findNavController()
.navigate(R.id.action_navigation_dashboard_self, bundle)
}
}
}

override fun getItemCount(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ class EvolutionFragment : Fragment() {
val recyclerView = recyclerViewEvolvingPokemon
val layoutManager = LinearLayoutManager(context)
recyclerView.layoutManager = layoutManager
val adapter = EvolutionAdapter(view.context)
val adapter = EvolutionAdapter(view.context, id)
recyclerView.adapter = adapter

dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { pokemonValue ->
pokemonValue?.let { pokemon ->
val evolutions = pokemon.evolutions ?: emptyList()
dashboardViewModel.getPokemonEvolutionsByIds(evolutions).observe(viewLifecycleOwner, Observer {
val pokemons: List<Pokemon> = it
adapter.setList(pokemons)
adapter.notifyDataSetChanged()

if (pokemons.isEmpty())
textNonEvolving.visibility = View.VISIBLE
})
dashboardViewModel.getPokemonEvolutionsByIds(evolutions)
.observe(viewLifecycleOwner, Observer {
val pokemons: List<Pokemon> = it
adapter.setList(pokemons)
adapter.notifyDataSetChanged()

if (pokemons.isEmpty())
textNonEvolving.visibility = View.VISIBLE
})
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.core.view.isVisible
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import dev.marcosfarias.pokedex.R
import dev.marcosfarias.pokedex.model.Pokemon
import dev.marcosfarias.pokedex.utils.PokemonColorUtil
Expand Down Expand Up @@ -48,6 +49,7 @@ class PokemonAdapter(
Glide.with(itemView.context)
.load(item.imageurl)
.placeholder(android.R.color.transparent)
.transition(DrawableTransitionOptions.withCrossFade())
.into(itemView.imageView)

itemView.setOnClickListener {
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/navigation/mobile_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
android:id="@+id/navigation_dashboard"
android:name="dev.marcosfarias.pokedex.ui.dashboard.DashboardFragment"
android:label="@string/app_name"
tools:layout="@layout/fragment_dashboard" />
tools:layout="@layout/fragment_dashboard" >
<action
android:id="@+id/action_navigation_dashboard_self"
app:destination="@id/navigation_dashboard" />
</fragment>

<fragment
android:id="@+id/navigation_about"
Expand All @@ -81,4 +85,4 @@
tools:layout="@layout/fragment_stats" />


</navigation>
</navigation>