Skip to content

Commit

Permalink
Overwrite character in names skydoves#91
Browse files Browse the repository at this point in the history
I do the issue skydoves#91
I hope it will be accepted
  • Loading branch information
flicker71 committed Feb 22, 2024
1 parent e481ed8 commit 8590dca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ class DetailActivity : BindingActivity<ActivityDetailBinding>(R.layout.activity_
internal val viewModel: DetailViewModel by viewModels {
DetailViewModel.provideFactory(detailViewModelFactory, pokemon.name)
}

private val pokemon: Pokemon by bundleNonNull(EXTRA_POKEMON)

override fun onCreate(savedInstanceState: Bundle?) {
onTransformationEndContainerApplyParams(this)
super.onCreate(savedInstanceState)
binding.pokemon = pokemon
// I create a temporary Pokemon variable 'pokemonBis' for modifying the name before binding.
// I needed for that to change the data class Pokemon here Pokemon.kt
var pokemonBis = pokemon
// I do a replace for the name only
pokemonBis.name = pokemon.name.replace("-", " ")
// And i change set the value of binding.pokemon
binding.pokemon = pokemonBis
binding.vm = viewModel
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ class PokemonAdapter : BindingListAdapter<Pokemon, PokemonAdapter.PokemonViewHol
}

fun bindPokemon(pokemon: Pokemon) {
binding.pokemon = pokemon
// I create a temporary Pokemon variable 'pokemonBis' for modifying the name before binding.
// I needed for that to change the data class Pokemon here Pokemon.kt
val modifiedPokemon = Pokemon(
page = pokemon.page,
// I do a replace for the name only
name = pokemon.name.replace("-", " "),
url = pokemon.url
)

// And i change set the value of binding.pokemon
binding.pokemon = modifiedPokemon
binding.executePendingBindings()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import kotlinx.parcelize.Parcelize
data class Pokemon(
var page: Int = 0,
@field:Json(name = "name")
val name: String,
// In Kotlin, the keyword val is used to declare an immutable variable. Once a value is assigned to a val variable, it cannot be changed or reassigned.
// That why i needed to change it
var name: String,
@field:Json(name = "url") val url: String,
) : Parcelable {

Expand Down

0 comments on commit 8590dca

Please sign in to comment.