Created
June 11, 2021 03:02
-
-
Save adityawid/8ba537af5bb5ef4308d373f0577dfc85 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
class MoviePagingAdapter : | |
PagingDataAdapter<id.ryolatech.paging3movieapi.data.bean.Movie, MoviePagingAdapter.ViewHolder>(listItemCallback) { | |
class ViewHolder(private val binding: ItemMovieBinding) : | |
RecyclerView.ViewHolder(binding.root) { | |
init { | |
binding.root.setOnClickListener { | |
} | |
} | |
fun bind(movie: id.ryolatech.paging3movieapi.data.bean.Movie) { | |
binding.titleTextView.text = movie.title | |
binding.descriptionTextView.text = movie.overview | |
val posterURL = "https://image.tmdb.org/t/p/w500" + movie.posterPath | |
Glide.with(binding.imageView.context) | |
.load(posterURL) | |
.into(binding.imageView) | |
} | |
} | |
companion object { | |
val listItemCallback = object : DiffUtil.ItemCallback<id.ryolatech.paging3movieapi.data.bean.Movie>() { | |
override fun areItemsTheSame(oldItem: id.ryolatech.paging3movieapi.data.bean.Movie, newItem: id.ryolatech.paging3movieapi.data.bean.Movie): Boolean { | |
return oldItem.id == newItem.id | |
} | |
override fun areContentsTheSame(oldItem: id.ryolatech.paging3movieapi.data.bean.Movie, newItem: id.ryolatech.paging3movieapi.data.bean.Movie): Boolean { | |
return oldItem == newItem | |
} | |
} | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
val data = getItem(position) | |
data?.let { holder.bind(it) } | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val layoutInflater = LayoutInflater.from(parent.context) | |
val binding: ItemMovieBinding = DataBindingUtil.inflate( | |
layoutInflater, | |
R.layout.item_movie, | |
parent, | |
false | |
) | |
return ViewHolder(binding) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment