To remove synthetic binding and use View Binding in your Kotlin Adapter, first, make sure that view binding is enabled in your build.gradle (app level) file:
android {
...
buildFeatures {
viewBinding = true
}
}
After enabling view binding, you then modify your adapter class to use it. Here is how you could modify your PodcastBlockListAdapter class:
package com.medicdigital.jjpodcasts.presentation.podcasts.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.medicdigital.jjpodcasts.R
import com.medicdigital.jjpodcasts.data.remote.response.NodeItem
import com.medicdigital.jjpodcasts.databinding.ItemPodcastBlockBinding
import com.medicdigital.jjpodcasts.presentation.extentions.getRoundedOutlineProvider
import com.medicdigital.jjpodcasts.presentation.utils.showImage
class PodcastBlockListAdapter(private val onPodcastItemClickListener: OnPodcastItemClickListener?) : BaseQuickAdapter<NodeItem, PodcastBlockListAdapter.PodcastViewHolder>(R.layout.item_podcast_block), View.OnClickListener {
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): PodcastViewHolder {
val binding = ItemPodcastBlockBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return PodcastViewHolder(binding)
}
override fun convert(holder: PodcastViewHolder, item: NodeItem) {
holder.bind(item)
}
inner class PodcastViewHolder(private val binding: ItemPodcastBlockBinding) : BaseViewHolder(binding.root), View.OnClickListener {
init {
binding.vgItemPodcastBlockLogo.setOnClickListener(this)
}
fun bind(item: NodeItem) {
with(binding) {
showImage(context, item.assets, ivItemPodcastBlockLogo)
txtItemPodcastBlockName.text = item.name
vgItemPodcastBlockLogo.apply {
tag = item
outlineProvider = context.getRoundedOutlineProvider(alpha = .3f, cornerRadius = R.dimen.corner_4)
}
}
}
override fun onClick(view: View) {
when (view.id) {
R.id.vg_item_podcast_block_logo -> {
val nodeItem = view.tag as? NodeItem
nodeItem?.let { onPodcastItemClickListener?.onPodcastItemClick(it) }
}
}
}
}
interface OnPodcastItemClickListener {
fun onPodcastItemClick(nodeItem: NodeItem)
}
}
Please note that I have made the following adjustments to your code:
- The import statements referring to
kotlinx.android.synthetic.* should be removed because they are related to synthetic binding.
- Created a
PodcastViewHolder class inside your adapter class to manage the view bindings. This class uses ItemPodcastBlockBinding to bind UI components, which is generated automatically from the layout file name (item_podcast_block.xml).
- Adjusted view references in
bind to use the binding object instead of directly referencing views.
- I have assumed the correction for the typo in import statement
com.medicdigital.jjpodcasts.data.remote.responce.NodeItem to com.medicdigital.jjpodcasts.data.remote.response.NodeItem.
Make sure your item_podcast_block.xml layout file is correctly placed in the res/layout directory for ItemPodcastBlockBinding to be generated.