-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0108d4c
commit a4fe667
Showing
9 changed files
with
138 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/src/main/java/dev/marcosfarias/pokedex/ui/dashboard/evolution/EvolutionAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package dev.marcosfarias.pokedex.ui.dashboard.evolution | ||
|
||
import android.content.Context | ||
import android.graphics.PorterDuff | ||
import android.graphics.PorterDuffColorFilter | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
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 | ||
) : RecyclerView.Adapter<EvolutionAdapter.ViewHolder>() { | ||
|
||
private val list = arrayListOf<Pokemon>() | ||
|
||
fun setList(list: List<Pokemon>) { | ||
this.list.clear() | ||
this.list.addAll(list) | ||
} | ||
|
||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
fun bindView(item: Pokemon) { | ||
itemView.textViewName.text = item.name | ||
itemView.textViewID.text = item.id | ||
|
||
val color = PokemonColorUtil(itemView.context).getPokemonColor(item.typeofpokemon) | ||
itemView.relativeLayoutBackground.background.colorFilter = | ||
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP) | ||
|
||
item.typeofpokemon?.getOrNull(0).let { firstType -> | ||
itemView.textViewType3.text = firstType | ||
itemView.textViewType3.isVisible = firstType != null | ||
} | ||
|
||
item.typeofpokemon?.getOrNull(1).let { secondType -> | ||
itemView.textViewType2.text = secondType | ||
itemView.textViewType2.isVisible = secondType != null | ||
} | ||
|
||
item.typeofpokemon?.getOrNull(2).let { thirdType -> | ||
itemView.textViewType1.text = thirdType | ||
itemView.textViewType1.isVisible = thirdType != null | ||
} | ||
|
||
Glide.with(itemView.context) | ||
.load(item.imageurl) | ||
.placeholder(android.R.color.transparent) | ||
.into(itemView.imageView) | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = LayoutInflater.from(context).inflate(R.layout.item_pokemon, parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val item = list[position] | ||
holder.bindView(item) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return list.size | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/textNonEvolving" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="100dp" | ||
android:text="@string/in_progress" | ||
android:text="@string/non_evolving_pokemon" | ||
android:textAlignment="center" | ||
android:textSize="20sp" /> | ||
</LinearLayout> | ||
android:textSize="20sp" | ||
android:visibility="gone" /> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recyclerViewEvolvingPokemon" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_marginStart="@dimen/activity_horizontal_margin" | ||
android:layout_marginEnd="@dimen/activity_horizontal_margin" /> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters