Skip to content

Instantly share code, notes, and snippets.

@1jGabriel
Last active November 14, 2020 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1jGabriel/fa728bf03780aad28cb7b3fa519f3643 to your computer and use it in GitHub Desktop.
Save 1jGabriel/fa728bf03780aad28cb7b3fa519f3643 to your computer and use it in GitHub Desktop.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.View.OnClickListener
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
class ${NAME}(
private val click: () -> Unit
) : ListAdapter<${Model_Class}, ${NAME}.${ViewHolder_Class}>(
${Model_Class}DC()
) {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
) = ${ViewHolder_Class}(
${Binding_view}.inflate(
LayoutInflater.from(
parent.context
),
parent,
false
),
action
)
override fun onBindViewHolder(
holder: ${ViewHolder_Class},
position: Int
) = holder.bind(
getItem(position)
)
inner class ${ViewHolder_Class}(
itemView: ${Binding_view},
private val action: () -> Unit
) : RecyclerView.ViewHolder(itemView.root) {
fun bind(item: ${Model_Class}) {
with(itemView) {
// TODO: Bind the data with View
}
}
}
}
private class ${Model_Class}DC : DiffUtil.ItemCallback<${Model_Class}>() {
override fun areItemsTheSame(
oldItem: ${Model_Class},
newItem: ${Model_Class}
): Boolean {
TODO(
"not implemented"
)
}
override fun areContentsTheSame(
oldItem: ${Model_Class},
newItem: ${Model_Class}
): Boolean {
TODO(
"not implemented"
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment