Created
October 13, 2019 20:08
-
-
Save francescogatto/0734f3c11ec1150ccdcd15fc23867f24 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 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