Last active
August 4, 2022 10:37
-
-
Save mitchtabian/a0d6829c395daac8d317097602d48f3d 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 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 | |
#parse("File Header.java") | |
class ${NAME}(private val interaction: Interaction? = null) : | |
ListAdapter<${Model_Class}, ${NAME}.${ViewHolder_Class}>(${Model_Class}DiffCallback()) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ${ViewHolder_Class}( | |
LayoutInflater.from(parent.context) | |
.inflate(R.layout.${Item_Layout_ID}, parent, false), interaction | |
) | |
override fun onBindViewHolder(holder: BlogPostViewHolder, position: Int) { | |
holder.bind(getItem(position)) | |
} | |
inner class ${ViewHolder_Class}(itemView: View, | |
private val interaction: Interaction?) : RecyclerView.ViewHolder(itemView), OnClickListener { | |
init { | |
itemView.setOnClickListener(this) | |
} | |
override fun onClick(v: View?) { | |
if (adapterPosition == RecyclerView.NO_POSITION) return | |
interaction?.onItemSelected(adapterPosition, getItem(adapterPosition)) | |
} | |
fun bind(item: ${Model_Class}) = with(itemView) { | |
// TODO: Bind the data with View | |
} | |
} | |
interface Interaction { | |
fun onItemSelected(position: Int, item: ${Model_Class}) | |
} | |
private class ${Model_Class}DiffCallback : 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