Skip to content

Instantly share code, notes, and snippets.

@ngima
Created June 9, 2021 04:56
Show Gist options
  • Save ngima/679637bc4c200b96ac3a3b0b9ed6bc73 to your computer and use it in GitHub Desktop.
Save ngima/679637bc4c200b96ac3a3b0b9ed6bc73 to your computer and use it in GitHub Desktop.
Android Live Templates
//radapter
class $adapter$ : androidx.recyclerview.widget.RecyclerView.Adapter<$adapter$.ViewHolder>() {
var data: MutableList<$model$> = mutableListOf()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: android.view.ViewGroup, viewType: Int): ViewHolder =
ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.$item_layout_id$, parent, false))
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(data[position])
override fun getItemCount() = data.size
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(item: $model$) = with(itemView) {
// TODO: Bind the data with View
}
}
}
//sback
com.google.android.material.snackbar.Snackbar.make($parentlayout$, "$message$", Snackbar.LENGTH_LONG)
.show()
//snackaction
com.google.android.material.snackbar.Snackbar.make($parentlayout$, "$message$", Snackbar.LENGTH_LONG)
.setAction("$actionname$", {view->
}
.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment