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

Kotlinx synthetic not working #95

Closed
P1NG2WIN opened this issue Sep 7, 2020 · 0 comments
Closed

Kotlinx synthetic not working #95

P1NG2WIN opened this issue Sep 7, 2020 · 0 comments

Comments

@P1NG2WIN
Copy link

P1NG2WIN commented Sep 7, 2020

This is my adapter

import androidx.recyclerview.widget.DiffUtil
import com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateLayoutContainer
import kotlinx.android.synthetic.main.item_skill.*


class SkillsAdapter {

    fun createAdapter(click: (Skill) -> Unit) = AsyncListDifferDelegationAdapter(
        createDiffCallback(),
        AdapterDelegatesManager<List<Skill>>()
            .addDelegate(createSkillsDelegate(click))
    )

    private fun createSkillsDelegate(click: (Skill) -> Unit) =
        adapterDelegateLayoutContainer<Skill, Skill>(R.layout.item_skill) {
            chp_item_skill.setOnClickListener {
                item.isSelected = !item.isSelected
                chp_item_skill.isChecked = item.isSelected
                click(item)
            }

            bind {
                chp_item_skill.text = item.name
                chp_item_skill.isChecked = item.isSelected
            }
        }

    private fun createDiffCallback() =
        object : DiffUtil.ItemCallback<Skill>() {

            override fun areItemsTheSame(oldItem: Skill, newItem: Skill) =
                newItem.id == oldItem.id

            override fun areContentsTheSame(oldItem: Skill, newItem: Skill) =
                oldItem == newItem

        }
}

You can see that i use adapterDelegateLayoutContainer that must replace findViewById with findCachedViewById but in bytecode we can see that it's still use findViewById

image

@P1NG2WIN P1NG2WIN closed this as completed Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant