Created
April 11, 2021 08:16
-
-
Save konk3r/98678e268d64fb42eca190092bbc6b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end | |
import android.support.v7.recyclerview.extensions.ListAdapter | |
import android.support.v7.util.DiffUtil | |
import android.support.v7.widget.RecyclerView | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
class ${NAME} : ListAdapter<${Model_Class}, ${NAME}.ItemViewHolder>(DiffCallback()) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewholder { | |
return ItemViewHolder( | |
LayoutInflater.from(parent.context) | |
.inflate(R.layout.${Item_Layout_ID}, parent, false) | |
) | |
} | |
override fun onBindViewHolder(holder: ${NAME}.ItemViewHolder, position: Int) { | |
holder.bind(getItem(position)) | |
} | |
class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
fun bind(item: ${Model_Class}) = with(itemView) { | |
// TODO: Bind the data with View | |
setOnClickListener { | |
// TODO: Handle on click | |
} | |
} | |
} | |
} | |
class DiffCallback : DiffUtil.ItemCallback<${Model_Class}>() { | |
override fun areItemsTheSame(oldItem: ${Model_Class}, newItem: ${Model_Class}): Boolean { | |
return oldItem.id == newItem.id | |
} | |
override fun areContentsTheSame(oldItem: ${Model_Class}, newItem: ${Model_Class}): Boolean { | |
return oldItem == newItem | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment