Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite character in names #91 #146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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