Created
December 2, 2020 16:10
-
-
Save BuiVanNam/922228e9f226233ec30a5e6675cdf4c5 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
/** | |
* 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