Skip to content

Instantly share code, notes, and snippets.

@francescogatto
Created October 13, 2019 20:08
Show Gist options
  • Save francescogatto/0734f3c11ec1150ccdcd15fc23867f24 to your computer and use it in GitHub Desktop.
Save francescogatto/0734f3c11ec1150ccdcd15fc23867f24 to your computer and use it in GitHub Desktop.
class AttachmentAdapter(var dummyes: Array<DummyData>, val listener: (DummyData) -> Unit) : RecyclerView.Adapter<ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_list, parent, false))
override fun getItemCount(): Int = dummyes.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val dummy = dummyes[position]
with(holder.itemView) {
title.text = dummy.title
downloadIcon.isVisible = !dummy.file.exists()
documentTypeIcon.isVisible = dummy.file.exists()
progressBarDocument.isVisible = dummy.isDownloading
setOnClickListener {
listener(dummy)
}
}
}
fun setDownload(dummy: DummyData, isDownloading: Boolean) {
dummyes.find { dummy.id == it.id }?.isDownloading = isDownloading
notifyDataSetChanged()
}
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment