-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6524166
commit a407892
Showing
9 changed files
with
250 additions
and
17 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/henryudorji/theater/adapters/MovieListRecyclerAdapter.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.henryudorji.theater.adapters | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.AsyncListDiffer | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.henryudorji.theater.data.model.Movie | ||
import com.henryudorji.theater.databinding.MovieCustomLayoutBinding | ||
import com.henryudorji.theater.utils.Constants.BASE_URL_IMAGE | ||
import com.squareup.picasso.Picasso | ||
|
||
// | ||
// Created by hash on 5/3/2021. | ||
// | ||
class MovieListRecyclerAdapter(): RecyclerView.Adapter<MovieListRecyclerAdapter.MovieViewHolder>() { | ||
|
||
inner class MovieViewHolder(val binding: MovieCustomLayoutBinding): RecyclerView.ViewHolder(binding.root) | ||
|
||
private val differCallback = object: DiffUtil.ItemCallback<Movie>() { | ||
override fun areItemsTheSame(oldItem: Movie, newItem: Movie): Boolean { | ||
return oldItem.id == newItem.id | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: Movie, newItem: Movie): Boolean { | ||
return oldItem == newItem | ||
} | ||
} | ||
val differ = AsyncListDiffer(this, differCallback) | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MovieViewHolder { | ||
val binding = MovieCustomLayoutBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
return MovieViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: MovieViewHolder, position: Int) { | ||
val movie = differ.currentList[position] | ||
|
||
holder.binding.apply { | ||
Picasso.get().load(BASE_URL_IMAGE + movie.posterPath).into(movieImage) | ||
movieTitleText.text = movie.originalTitle | ||
ratingText.text = movie.voteAverage.toString() | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return differ.currentList.size | ||
} | ||
|
||
private var onItemClickListener: ((id: Int) -> Unit) ? = null | ||
|
||
fun setOnItemClickListener(listener: (id: Int) -> Unit) { | ||
onItemClickListener = listener | ||
} | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#FFFFFF" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M11.67,3.87L9.9,2.1 0,12l9.9,9.9 1.77,-1.77L3.54,12z"/> | ||
</vector> |
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
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
Oops, something went wrong.