codinginflow / MVVMTodo

187 stars 124 forks source link

Thanks for series ! 👨🏻‍💻 here is quick suggestion #1

Open ch8n opened 3 years ago

ch8n commented 3 years ago

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)
 }
codinginflow commented 3 years ago

Thank you very much for the tips 👍

ch8n commented 3 years ago

Is this repo open for contributions? I can open some PR or put some suggestions that you can use in the future projects?

codinginflow commented 3 years ago

I don't want to change the code of this repo because it would break the tutorial but suggestions are more than welcome!

SeanKotlin commented 3 years ago

Hi CodingInFlow,

Very happy to learn from your excellent tutorial part by part. Now, I have faced some error after added Hiton dagger in your Video 4.

the error code:: as follow

Execution failed for task ':app:kaptDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.InvocationTargetException (no error message)