Skip to content

Commit

Permalink
Refactor DetailActivity using extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Oct 18, 2020
1 parent c1f21ed commit a7be3e8
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.annotation.VisibleForTesting
import com.skydoves.pokedex.R
import com.skydoves.pokedex.base.DataBindingActivity
import com.skydoves.pokedex.databinding.ActivityDetailBinding
import com.skydoves.pokedex.extensions.argument
import com.skydoves.pokedex.extensions.onTransformationEndContainerApplyParams
import com.skydoves.pokedex.model.Pokemon
import com.skydoves.transformationlayout.TransformationCompat
Expand All @@ -39,29 +40,25 @@ class DetailActivity : DataBindingActivity() {

@VisibleForTesting
val viewModel: DetailViewModel by viewModels {
DetailViewModel.provideFactory(
detailViewModelFactory,
pokemonItem.name
)
DetailViewModel.provideFactory(detailViewModelFactory, pokemonItem.name)
}

private val binding: ActivityDetailBinding by binding(R.layout.activity_detail)

private val pokemonItem: Pokemon
get() = requireNotNull(intent.getParcelableExtra(EXTRA_POKEMON))
private val pokemonItem: Pokemon by argument(EXTRA_POKEMON)

override fun onCreate(savedInstanceState: Bundle?) {
onTransformationEndContainerApplyParams()
super.onCreate(savedInstanceState)
binding.apply {
pokemon = pokemonItem
lifecycleOwner = this@DetailActivity
pokemon = pokemonItem
vm = viewModel
}
}

companion object {
@VisibleForTesting const val EXTRA_POKEMON = "EXTRA_POKEMON"
@VisibleForTesting
const val EXTRA_POKEMON = "EXTRA_POKEMON"

fun startActivity(transformationLayout: TransformationLayout, pokemon: Pokemon) {
val context = transformationLayout.context
Expand Down

0 comments on commit a7be3e8

Please sign in to comment.