Skip to content
Permalink
Browse files

Replace .let calls for arguments with checkNotNull checks

  • Loading branch information
zsmb13 committed Jan 7, 2020
1 parent 12b51db commit d38005167623cb1c73ad88e8247ceb3e1964fbd0
@@ -34,52 +34,47 @@ class DashboardFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.getString("id").let {
dashboardViewModel.getPokemonById(it).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
textViewID.text = pokemon?.id
textViewName.text = pokemon?.name

val color =
PokemonColorUtil(view.context).getPokemonColor(pokemon?.typeofpokemon)
app_bar.background.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
toolbar_layout.contentScrim?.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
activity?.window?.statusBarColor =
PokemonColorUtil(view.context).getPokemonColor(pokemon?.typeofpokemon)

pokemon?.typeofpokemon?.getOrNull(0).let { firstType ->
textViewType3.text = firstType
textViewType3.isVisible = firstType != null
}

pokemon?.typeofpokemon?.getOrNull(1).let { secondType ->
textViewType2.text = secondType
textViewType2.isVisible = secondType != null
}

pokemon?.typeofpokemon?.getOrNull(2).let { thirdType ->
textViewType1.text = thirdType
textViewType1.isVisible = thirdType != null
}

Glide.with(view.context)
.load(pokemon?.imageurl)
.placeholder(android.R.color.transparent)
.into(imageView)

val pager = viewPager
val tabs = tabs
pager.adapter = ViewPagerAdapter(fragmentManager!!, context!!, pokemon?.id!!)
tabs.setupWithViewPager(pager)
val id = checkNotNull(arguments?.getString("id"))
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
textViewID.text = pokemon?.id
textViewName.text = pokemon?.name

val color =
PokemonColorUtil(view.context).getPokemonColor(pokemon?.typeofpokemon)
app_bar.background.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
toolbar_layout.contentScrim?.colorFilter =
PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
activity?.window?.statusBarColor =
PokemonColorUtil(view.context).getPokemonColor(pokemon?.typeofpokemon)

pokemon?.typeofpokemon?.getOrNull(0).let { firstType ->
textViewType3.text = firstType
textViewType3.isVisible = firstType != null
}

pokemon?.typeofpokemon?.getOrNull(1).let { secondType ->
textViewType2.text = secondType
textViewType2.isVisible = secondType != null
}

})

pokemon?.typeofpokemon?.getOrNull(2).let { thirdType ->
textViewType1.text = thirdType
textViewType1.isVisible = thirdType != null
}

}
Glide.with(view.context)
.load(pokemon?.imageurl)
.placeholder(android.R.color.transparent)
.into(imageView)

val pager = viewPager
val tabs = tabs
pager.adapter = ViewPagerAdapter(fragmentManager!!, context!!, pokemon?.id!!)
tabs.setupWithViewPager(pager)
}
})
}

}
@@ -39,17 +39,16 @@ class AboutFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.getString("id").let {
dashboardViewModel.getPokemonById(it).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
textViewDescription.text = pokemon?.xdescription
textViewHeight.text = pokemon?.height
textViewWeight.text = pokemon?.weight
textViewEggCycle.text = pokemon?.cycles
textViewEggGroups.text = pokemon?.egg_groups
textViewBaseEXP.text = pokemon?.base_exp
}
})
}
val id = checkNotNull(arguments?.getString("id"))
dashboardViewModel.getPokemonById(id).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
textViewDescription.text = pokemon?.xdescription
textViewHeight.text = pokemon?.height
textViewWeight.text = pokemon?.weight
textViewEggCycle.text = pokemon?.cycles
textViewEggGroups.text = pokemon?.egg_groups
textViewBaseEXP.text = pokemon?.base_exp
}
})
}
}
@@ -40,29 +40,27 @@ class StatsFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

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

dashboardViewModel.getPokemonById(it).observe(viewLifecycleOwner, Observer { list ->
list?.get(0).let { pokemon ->
textViewTypeDefenses.text = pokemon?.ydescription
textViewHP.text = pokemon?.hp.toString()
textViewAttack.text = pokemon?.attack.toString()
textViewDefense.text = pokemon?.defense.toString()
textViewSpAtk.text = pokemon?.special_attack.toString()
textViewSpDef.text = pokemon?.special_defense.toString()
textViewSpeed.text = pokemon?.speed.toString()
textViewTotal.text = pokemon?.total.toString()

textViewHP.text = pokemon?.hp.toString()
textViewAttack.text = pokemon?.attack.toString()
textViewDefense.text = pokemon?.defense.toString()
textViewSpAtk.text = pokemon?.special_attack.toString()
textViewSpDef.text = pokemon?.special_defense.toString()
textViewSpeed.text = pokemon?.speed.toString()
textViewTotal.text = pokemon?.total.toString()

progressBarHP.progress = pokemon?.hp ?: 0
progressBarAttack.progress = pokemon?.attack ?: 0
progressBarDefense.progress = pokemon?.defense ?: 0
progressBarSpAtk.progress = pokemon?.special_attack ?: 0
progressBarSpDef.progress = pokemon?.special_defense ?: 0
progressBarSpeed.progress = pokemon?.speed ?: 0
progressBarTotal.progress = pokemon?.total ?: 0
}
})
}
progressBarHP.progress = pokemon?.hp ?: 0
progressBarAttack.progress = pokemon?.attack ?: 0
progressBarDefense.progress = pokemon?.defense ?: 0
progressBarSpAtk.progress = pokemon?.special_attack ?: 0
progressBarSpDef.progress = pokemon?.special_defense ?: 0
progressBarSpeed.progress = pokemon?.speed ?: 0
progressBarTotal.progress = pokemon?.total ?: 0
}
})
}
}

0 comments on commit d380051

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