Skip to content
Permalink
Browse files

Replace elementAtOrNull usages with getOrNull

  • Loading branch information
zsmb13 committed Jan 7, 2020
1 parent 96a246b commit 053a1c49a9d9a69ff94d38ba43e6066d9c59d83b
@@ -48,21 +48,21 @@ class DashboardFragment : Fragment() {
activity?.window?.statusBarColor =
PokemonColorUtil(view.context).getPokemonColor(pokemon?.typeofpokemon)

pokemon?.typeofpokemon?.elementAtOrNull(0).let { firstType ->
pokemon?.typeofpokemon?.getOrNull(0).let { firstType ->
textViewType3.text = firstType
if (firstType == null) {
textViewType3.visibility = View.GONE
}
}

pokemon?.typeofpokemon?.elementAtOrNull(1).let { secondType ->
pokemon?.typeofpokemon?.getOrNull(1).let { secondType ->
textViewType2.text = secondType
if (secondType == null) {
textViewType2.visibility = View.GONE
}
}

pokemon?.typeofpokemon?.elementAtOrNull(2).let { thirdType ->
pokemon?.typeofpokemon?.getOrNull(2).let { thirdType ->
textViewType1.text = thirdType
if (thirdType == null) {
textViewType1.visibility = View.GONE
@@ -29,21 +29,21 @@ class PokemonAdapter(
itemView.relativeLayoutBackground.background.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)

item.typeofpokemon?.elementAtOrNull(0).let { firstType ->
item.typeofpokemon?.getOrNull(0).let { firstType ->
itemView.textViewType3.text = firstType
if (firstType == null) {
itemView.textViewType3.visibility = View.GONE
}
}

item.typeofpokemon?.elementAtOrNull(1).let { secondType ->
item.typeofpokemon?.getOrNull(1).let { secondType ->
itemView.textViewType2.text = secondType
if (secondType == null) {
itemView.textViewType2.visibility = View.GONE
}
}

item.typeofpokemon?.elementAtOrNull(2).let { thirdType ->
item.typeofpokemon?.getOrNull(2).let { thirdType ->
itemView.textViewType1.text = thirdType
if (thirdType == null) {
itemView.textViewType1.visibility = View.GONE
@@ -10,7 +10,7 @@ class PokemonColorUtil(var context: Context) {

@ColorInt
fun getPokemonColor(typeOfPokemon: List<String>?): Int {
val type = typeOfPokemon?.elementAtOrNull(0)
val type = typeOfPokemon?.getOrNull(0)
val color = when (type?.toLowerCase()) {
"grass", "bug" -> R.color.lightTeal
"fire" -> R.color.lightRed

0 comments on commit 053a1c4

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