Created
November 6, 2019 22:47
-
-
Save francescogatto/c3907752503059851742862df95e5a9e to your computer and use it in GitHub Desktop.
#kkt
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
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 | |
textProgress.isVisible = dummy.isDownloading | |
setOnClickListener { | |
listener(dummy) | |
} | |
} | |
} | |
override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads: MutableList<Any>) { | |
super.onBindViewHolder(holder, position, payloads) | |
if (payloads.firstOrNull() != null) { | |
with(holder.itemView) { | |
(payloads.first() as Bundle).getInt("progress").also { | |
progressBarDocument.progress = it | |
progressBarDocument.isVisible = it < 99 | |
textProgress.isVisible = it < 99 | |
textProgress.text = "$it %" | |
} | |
} | |
} | |
} | |
fun setDownloading(dummy: DummyData, isDownloading: Boolean) { | |
getDummy(dummy)?.isDownloading = isDownloading | |
notifyItemChanged(dummyes.indexOf(dummy)) | |
} | |
fun setProgress(dummy: DummyData, progress: Int) { | |
getDummy(dummy)?.progress = progress | |
notifyItemChanged(dummyes.indexOf(dummy), Bundle().apply { putInt("progress", progress) }) | |
} | |
private fun getDummy(dummy: DummyData) = dummyes.find { dummy.id == it.id } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment