Glimpse: Use itemView in ThumbnailViewHolder

Also set the click listener only once we have the data binded

Change-Id: Id74c564f5f1a44f4c44b386b3e1ed57d7f3dc676
This commit is contained in:
Luca Stefani 2023-09-03 16:05:43 +02:00
parent cf2046c092
commit 4b0abb7cf4
1 changed files with 7 additions and 9 deletions

View File

@ -127,27 +127,25 @@ class ThumbnailAdapter(
}
class ThumbnailViewHolder(
private val view: View,
view: View,
private val onItemSelected: (media: Media, position: Int) -> Unit,
) : RecyclerView.ViewHolder(view) {
// Views
private val videoOverlayImageView =
view.findViewById<ImageView>(R.id.videoOverlayImageView)!!
private val thumbnailImageView = view.findViewById<ImageView>(R.id.thumbnailImageView)!!
itemView.findViewById<ImageView>(R.id.videoOverlayImageView)!!
private val thumbnailImageView = itemView.findViewById<ImageView>(R.id.thumbnailImageView)!!
private lateinit var media: Media
private var position = -1
init {
view.setOnClickListener {
onItemSelected(media, position)
}
}
fun bind(media: Media, position: Int) {
this.media = media
this.position = position
itemView.setOnClickListener {
onItemSelected(media, position)
}
thumbnailImageView.load(media.externalContentUri) {
memoryCacheKey("thumbnail_${media.id}")
size(DisplayAwareGridLayoutManager.MAX_THUMBNAIL_SIZE)