-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Description
Hi, @codinginflow Nice tutorial series,
Just a suggestion you can reduce some nesting using this with
than apply
class TasksViewHolder(private val binding: ItemTaskBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(task: Task) {
binding.apply {
checkBoxCompleted.isChecked = task.completed
textViewName.text = task.name
textViewName.paint.isStrikeThruText = task.completed
labelPriority.isVisible = task.important
}
}
}
class TasksViewHolder(private val binding: ItemTaskBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(task: Task) = with(binding) {
checkBoxCompleted.isChecked = task.completed
textViewName.text = task.name
textViewName.paint.isStrikeThruText = task.completed
labelPriority.isVisible = task.important
}
}
[Edit1]
Nested scoped extension chaining is are considered not a good practice, checkout some awesome kotlin tips be from Huyen
talk KotlinConf 2019
youtube.com/watch?v=YeqGfKmJM_g
//TaskFragment
binding.apply {
recyclerViewTasks.apply {
adapter = taskAdapter
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
}
}
to
//TaskFragment
binding.recyclerViewTasks.apply {
adapter = taskAdapter
layoutManager = LinearLayoutManager(requireContext())
setHasFixedSize(true)
}
kseyko35
Metadata
Metadata
Assignees
Labels
No labels