Skip to content

Instantly share code, notes, and snippets.

@sharmadhiraj
Created August 3, 2018 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharmadhiraj/d5f8f51f26f8629fbc3102febecada5a to your computer and use it in GitHub Desktop.
Save sharmadhiraj/d5f8f51f26f8629fbc3102febecada5a to your computer and use it in GitHub Desktop.
Android Paging Library
class ListFooterViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(status: State?) {
itemView.progress_bar.visibility = if (status == State.LOADING) VISIBLE else View.INVISIBLE
itemView.txt_error.visibility = if (status == State.ERROR) VISIBLE else View.INVISIBLE
}
companion object {
fun create(retry: () -> Unit, parent: ViewGroup): ListFooterViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_list_footer, parent, false)
view.txt_error.setOnClickListener { retry() }
return ListFooterViewHolder(view)
}
}
}
class NewsViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(news: News?) {
if (news != null) {
itemView.txt_news_name.text = news.title
Picasso.get().load(news.image).into(itemView.img_news_banner)
}
}
companion object {
fun create(parent: ViewGroup): NewsViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_news, parent, false)
return NewsViewHolder(view)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment