Fixed progress bar issue

This commit is contained in:
Kanahia 2024-07-20 12:49:15 +05:30
parent a01263a6e8
commit 170d0b156e

View file

@ -32,9 +32,9 @@ class PendingUploadsAdapter(private val callback: Callback) :
when (val latestPayload = payloads.lastOrNull()) { when (val latestPayload = payloads.lastOrNull()) {
is ContributionChangePayload.Progress -> holder.bindProgress( is ContributionChangePayload.Progress -> holder.bindProgress(
latestPayload.transferred, latestPayload.transferred,
latestPayload.total latestPayload.total,
getItem(position)!!.state
) )
is ContributionChangePayload.State -> holder.bindState(latestPayload.state) is ContributionChangePayload.State -> holder.bindState(latestPayload.state)
else -> onBindViewHolder(holder, position) else -> onBindViewHolder(holder, position)
} }
@ -81,7 +81,7 @@ class PendingUploadsAdapter(private val callback: Callback) :
} }
bindState(contribution.state) bindState(contribution.state)
bindProgress(contribution.transferred, contribution.dataLength) bindProgress(contribution.transferred, contribution.dataLength, contribution.state)
} }
fun bindState(state: Int) { fun bindState(state: Int) {
@ -95,20 +95,26 @@ class PendingUploadsAdapter(private val callback: Callback) :
} }
} }
fun bindProgress(transferred: Long, total: Long) { fun bindProgress(transferred: Long, total: Long, state: Int) {
if (transferred == 0L) { if (transferred == 0L) {
errorTextView.text = "Queued" errorTextView.text = "Queued"
errorTextView.visibility = View.VISIBLE errorTextView.visibility = View.VISIBLE
itemProgress.visibility = View.GONE itemProgress.visibility = View.GONE
} else { } else {
errorTextView.visibility = View.GONE if (state == Contribution.STATE_QUEUED){
itemProgress.visibility = View.VISIBLE errorTextView.text = "Queued"
if (transferred >= total) { errorTextView.visibility = View.VISIBLE
itemProgress.isIndeterminate = true itemProgress.visibility = View.GONE
} else { } else{
itemProgress.isIndeterminate = false errorTextView.visibility = View.GONE
itemProgress.progress = itemProgress.visibility = View.VISIBLE
((transferred.toDouble() / total.toDouble()) * 100).toInt() if (transferred >= total) {
itemProgress.isIndeterminate = true
} else {
itemProgress.isIndeterminate = false
itemProgress.progress =
((transferred.toDouble() / total.toDouble()) * 100).toInt()
}
} }
} }
} }