mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Improved progress bars
This commit is contained in:
parent
474c3bc01e
commit
cd11e1c009
6 changed files with 51 additions and 39 deletions
|
|
@ -222,11 +222,13 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
uploadErrorCount = 0;
|
||||
pendingUploadsCount = 0;
|
||||
for (int i = 0; i< list.size(); i++){
|
||||
if (list.get(i).getState() != Contribution.STATE_COMPLETED){
|
||||
if (list.get(i).getState() == Contribution.STATE_FAILED){
|
||||
uploadErrorCount++;
|
||||
}else {
|
||||
pendingUploadsCount++;
|
||||
if (list.get(i) != null){
|
||||
if (list.get(i).getState() != Contribution.STATE_COMPLETED){
|
||||
if (list.get(i).getState() == Contribution.STATE_FAILED){
|
||||
uploadErrorCount++;
|
||||
}else {
|
||||
pendingUploadsCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,8 +83,10 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
|||
) { list: PagedList<Contribution?> ->
|
||||
l = ArrayList()
|
||||
list.forEach {
|
||||
if (it!!.state == Contribution.STATE_FAILED) {
|
||||
l.add(it)
|
||||
if (it != null){
|
||||
if (it.state == Contribution.STATE_FAILED) {
|
||||
l.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (l.size == 0) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import java.io.File
|
|||
class PendingUploadsAdapter(items: List<Contribution>, callback: Callback) :
|
||||
RecyclerView.Adapter<PendingUploadsAdapter.ViewHolder>() {
|
||||
private val items: List<Contribution> = items
|
||||
private var callback:Callback = callback
|
||||
private var callback: Callback = callback
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view: View =
|
||||
|
|
@ -34,7 +34,6 @@ class PendingUploadsAdapter(items: List<Contribution>, callback: Callback) :
|
|||
var imageRequest: ImageRequest? = null
|
||||
|
||||
val imageSource: String = item.localUri.toString()
|
||||
Timber.tag("PRINT").e("--"+imageSource)
|
||||
|
||||
if (!TextUtils.isEmpty(imageSource)) {
|
||||
if (URLUtil.isFileUrl(imageSource)) {
|
||||
|
|
@ -48,40 +47,44 @@ class PendingUploadsAdapter(items: List<Contribution>, callback: Callback) :
|
|||
holder.itemImage.setImageRequest(imageRequest)
|
||||
}
|
||||
}
|
||||
|
||||
Timber.tag("PRINT").e(item.state.toString() + " " + item)
|
||||
if (item.state == Contribution.STATE_QUEUED || item.state == Contribution.STATE_PAUSED) {
|
||||
holder.errorTextView.setText("Queued")
|
||||
holder.errorTextView.visibility = View.VISIBLE
|
||||
holder.itemProgress.visibility = View.GONE
|
||||
} else {
|
||||
holder.errorTextView.visibility = View.GONE
|
||||
holder.itemProgress.visibility = View.VISIBLE
|
||||
val total: Long = item.dataLength
|
||||
val transferred: Long = item.transferred
|
||||
if (transferred == 0L || transferred >= total) {
|
||||
holder.itemProgress.setIndeterminate(true)
|
||||
if (item.chunkInfo == null) {
|
||||
holder.errorTextView.setText("Queued")
|
||||
holder.errorTextView.visibility = View.VISIBLE
|
||||
holder.itemProgress.visibility = View.GONE
|
||||
} else {
|
||||
holder.itemProgress.setIndeterminate(false)
|
||||
holder.itemProgress.setProgress(((transferred.toDouble() / total.toDouble()) * 100).toInt())
|
||||
holder.errorTextView.visibility = View.GONE
|
||||
holder.itemProgress.visibility = View.VISIBLE
|
||||
val total: Long = item.dataLength
|
||||
val transferred: Long = item.transferred
|
||||
if (transferred == 0L || transferred >= total) {
|
||||
holder.itemProgress.setIndeterminate(true)
|
||||
} else {
|
||||
holder.itemProgress.setIndeterminate(false)
|
||||
holder.itemProgress.setProgress(((transferred.toDouble() / total.toDouble()) * 100).toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.itemImage.setImageRequest(imageRequest)
|
||||
|
||||
holder.deleteButton.setOnClickListener{
|
||||
holder.deleteButton.setOnClickListener {
|
||||
callback!!.deleteUpload(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return items.size
|
||||
}
|
||||
|
||||
|
||||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var itemImage: com.facebook.drawee.view.SimpleDraweeView = itemView.findViewById(R.id.itemImage)
|
||||
var itemImage: com.facebook.drawee.view.SimpleDraweeView =
|
||||
itemView.findViewById(R.id.itemImage)
|
||||
var titleTextView: TextView = itemView.findViewById<TextView>(R.id.titleTextView)
|
||||
var itemProgress: ProgressBar = itemView.findViewById<ProgressBar>(R.id.itemProgress)
|
||||
var errorTextView: TextView = itemView.findViewById<TextView>(R.id.errorTextView)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
|
||||
private var contributionsSize = 0
|
||||
var l = ArrayList<Contribution>()
|
||||
private var totalUploads = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -109,16 +110,18 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
l = ArrayList()
|
||||
var x = 0;
|
||||
list.forEach {
|
||||
if (it!!.state == Contribution.STATE_PAUSED
|
||||
|| it.state == Contribution.STATE_QUEUED
|
||||
|| it.state == Contribution.STATE_IN_PROGRESS
|
||||
) {
|
||||
l.add(it)
|
||||
}
|
||||
if (it!!.state == Contribution.STATE_PAUSED
|
||||
|| it.state == Contribution.STATE_QUEUED
|
||||
) {
|
||||
x++
|
||||
if (it != null){
|
||||
if (it.state == Contribution.STATE_PAUSED
|
||||
|| it.state == Contribution.STATE_QUEUED
|
||||
|| it.state == Contribution.STATE_IN_PROGRESS
|
||||
) {
|
||||
l.add(it)
|
||||
}
|
||||
if (it.state == Contribution.STATE_PAUSED
|
||||
|| it.state == Contribution.STATE_QUEUED
|
||||
) {
|
||||
x++
|
||||
}
|
||||
}
|
||||
}
|
||||
if (l.size == 0) {
|
||||
|
|
@ -126,12 +129,16 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
binding.pendingUplaodsLl.visibility = View.GONE
|
||||
uploadProgressActivity.hidePendingIcons()
|
||||
} else {
|
||||
if (totalUploads == 0){
|
||||
totalUploads = l.size
|
||||
binding.progressBarPending.max = totalUploads
|
||||
}
|
||||
binding.nopendingTextView.visibility = View.GONE
|
||||
binding.pendingUplaodsLl.visibility = View.VISIBLE
|
||||
val adapter = PendingUploadsAdapter(l, this)
|
||||
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
||||
binding.progressTextView.setText("0/" + l.size + " uploaded")
|
||||
|
||||
binding.progressTextView.setText((totalUploads-l.size).toString() + "/" + totalUploads + " uploaded")
|
||||
binding.progressBarPending.progress = totalUploads-l.size
|
||||
if (x == l.size) {
|
||||
uploadProgressActivity.setPausedIcon(true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
android:id="@+id/titleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="24sp"
|
||||
android:text="RandomTest" />
|
||||
android:textSize="24sp"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/itemProgress"
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
android:id="@+id/titleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="24sp"
|
||||
android:text="RandomTest" />
|
||||
android:textSize="24sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/itemProgress"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue