Skip to content

Instantly share code, notes, and snippets.

@BuiVanNam
Created December 2, 2020 16:10
Show Gist options
  • Save BuiVanNam/922228e9f226233ec30a5e6675cdf4c5 to your computer and use it in GitHub Desktop.
Save BuiVanNam/922228e9f226233ec30a5e6675cdf4c5 to your computer and use it in GitHub Desktop.
/**
* Created by nambv on 11/18/2020
*/
class BookAdapter : RecyclerView.Adapter<BookAdapter.BookViewHolder>() {
//Define function type
var mEventItemBook: ((EventItemBook) -> Unit)? = null
/////Setup for BookAdapter/////////
inner class BookViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val mIconFavorite: ImageView = itemView.findViewById(R.id.favorite)
init {
mIconFavorite.setOnClickListener {
if (isFavorite) {
mEventItemBook?.invoke(EventItemBook.RemoveFavoriteBook(mBook))
} else {
mEventItemBook?.invoke(EventItemBook.AddFavoriteBook(mBook))
}
}
itemView.setOnClickListener {
mEventItemBook?.invoke(EventItemBook.ActionOpenBook(mBook))
}
itemView.setOnLongClickListener {
mEventItemBook?.invoke(EventItemBook.OpenMenuBook(mBook))
false
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment