Skip to content
Permalink
Browse files

Simplify convertColor function, add support annotations

  • Loading branch information
zsmb13 committed Jan 7, 2020
1 parent 3916b47 commit e9625b197a0b78b071cc5188f25a4475973c1612
@@ -34,7 +34,7 @@ class HomeFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.window?.statusBarColor = PokemonColorUtil(view.context).covertColor(R.color.red)
activity?.window?.statusBarColor = PokemonColorUtil(view.context).convertColor(R.color.red)

val recyclerViewMenu = recyclerViewMenu
val recyclerViewNews = recyclerViewNews
@@ -22,7 +22,7 @@ class MenuAdapter(
fun bindView(item: Menu) {
itemView.textViewName.text = item.name

val color = PokemonColorUtil(itemView.context).covertColor(item.color)
val color = PokemonColorUtil(itemView.context).convertColor(item.color)
itemView.relativeLayoutBackground.background.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)

@@ -21,7 +21,8 @@ class NewsDetailFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.window?.statusBarColor = PokemonColorUtil(view.context).covertColor(R.color.white)
activity?.window?.statusBarColor =
PokemonColorUtil(view.context).convertColor(R.color.white)
}

}
@@ -36,7 +36,7 @@ class PokedexFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.window?.statusBarColor =
PokemonColorUtil(view.context).covertColor(R.color.background)
PokemonColorUtil(view.context).convertColor(R.color.background)

val progressBar = progressBar
val recyclerView = recyclerView
@@ -1,7 +1,8 @@
package dev.marcosfarias.pokedex.utils

import android.content.Context
import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import dev.marcosfarias.pokedex.R

@@ -19,11 +20,12 @@ class PokemonColorUtil(var context: Context) {
"dark" -> R.color.black
else -> return R.color.lightBlue
}
return covertColor(color)
return convertColor(color)
}

fun covertColor(color: Int): Int {
return Color.parseColor("#" + Integer.toHexString(ContextCompat.getColor(context, color)))
@ColorInt
fun convertColor(@ColorRes color: Int): Int {
return ContextCompat.getColor(context, color)
}

}

0 comments on commit e9625b1

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