mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Fixed issue with sorting when adding more pictures during an upload
This commit is contained in:
parent
d825cd76fa
commit
51bdd2bca0
5 changed files with 83 additions and 32 deletions
|
|
@ -134,4 +134,9 @@ data class Contribution constructor(
|
||||||
fun unpause() {
|
fun unpause() {
|
||||||
CommonsApplication.pauseUploads[pageId] = false
|
CommonsApplication.pauseUploads[pageId] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dateModifiedInMillis(): Long {
|
||||||
|
return dateModified!!.time
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.paging.PagedList
|
import androidx.paging.PagedList
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import fr.free.nrw.commons.R
|
|
||||||
import fr.free.nrw.commons.auth.SessionManager
|
import fr.free.nrw.commons.auth.SessionManager
|
||||||
import fr.free.nrw.commons.contributions.Contribution
|
import fr.free.nrw.commons.contributions.Contribution
|
||||||
import fr.free.nrw.commons.databinding.FragmentFailedUploadsBinding
|
import fr.free.nrw.commons.databinding.FragmentFailedUploadsBinding
|
||||||
|
|
@ -42,7 +41,7 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
|
|
||||||
lateinit var binding: FragmentFailedUploadsBinding
|
lateinit var binding: FragmentFailedUploadsBinding
|
||||||
|
|
||||||
var l = ArrayList<Contribution>()
|
var contributionsList = ArrayList<Contribution>()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -81,21 +80,21 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
pendingUploadsPresenter!!.totalContributionList.observe(
|
pendingUploadsPresenter!!.totalContributionList.observe(
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) { list: PagedList<Contribution?> ->
|
) { list: PagedList<Contribution?> ->
|
||||||
l = ArrayList()
|
contributionsList = ArrayList()
|
||||||
list.forEach {
|
list.forEach {
|
||||||
if (it != null){
|
if (it != null){
|
||||||
if (it.state == Contribution.STATE_FAILED) {
|
if (it.state == Contribution.STATE_FAILED) {
|
||||||
l.add(it)
|
contributionsList.add(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (l.size == 0) {
|
if (contributionsList.size == 0) {
|
||||||
binding.nofailedTextView.visibility = View.VISIBLE
|
binding.nofailedTextView.visibility = View.VISIBLE
|
||||||
binding.failedUplaodsLl.visibility = View.GONE
|
binding.failedUplaodsLl.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
binding.nofailedTextView.visibility = View.GONE
|
binding.nofailedTextView.visibility = View.GONE
|
||||||
binding.failedUplaodsLl.visibility = View.VISIBLE
|
binding.failedUplaodsLl.visibility = View.VISIBLE
|
||||||
val adapter = FailedUploadsAdapter(l)
|
val adapter = FailedUploadsAdapter(contributionsList)
|
||||||
binding.failedUploadsRecyclerView.setAdapter(adapter)
|
binding.failedUploadsRecyclerView.setAdapter(adapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -132,4 +131,10 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
override fun showNoContributionsUI(shouldShow: Boolean) {
|
override fun showNoContributionsUI(shouldShow: Boolean) {
|
||||||
//TODO("Not yet implemented")
|
//TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun restartUploads() {
|
||||||
|
if (contributionsList != null){
|
||||||
|
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,7 @@ class PendingUploadsAdapter(items: List<Contribution>, callback: Callback) :
|
||||||
holder.errorTextView.visibility = View.VISIBLE
|
holder.errorTextView.visibility = View.VISIBLE
|
||||||
holder.itemProgress.visibility = View.GONE
|
holder.itemProgress.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
if (item.chunkInfo == null) {
|
if (item.transferred == 0L) {
|
||||||
holder.errorTextView.setText("Queued")
|
holder.errorTextView.setText("Queued")
|
||||||
holder.errorTextView.visibility = View.VISIBLE
|
holder.errorTextView.visibility = View.VISIBLE
|
||||||
holder.itemProgress.visibility = View.GONE
|
holder.itemProgress.visibility = View.GONE
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package fr.free.nrw.commons.upload
|
package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Build.VERSION
|
||||||
|
import android.os.Build.VERSION_CODES
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
@ -22,6 +24,7 @@ import timber.log.Timber
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple [Fragment] subclass.
|
* A simple [Fragment] subclass.
|
||||||
* Use the [PendingUploadsFragment.newInstance] factory method to
|
* Use the [PendingUploadsFragment.newInstance] factory method to
|
||||||
|
|
@ -53,7 +56,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
private lateinit var uploadProgressActivity: UploadProgressActivity
|
private lateinit var uploadProgressActivity: UploadProgressActivity
|
||||||
|
|
||||||
private var contributionsSize = 0
|
private var contributionsSize = 0
|
||||||
var l = ArrayList<Contribution>()
|
var contributionsList = ArrayList<Contribution>()
|
||||||
private var totalUploads = 0
|
private var totalUploads = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
@ -107,39 +110,66 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) { list: PagedList<Contribution?> ->
|
) { list: PagedList<Contribution?> ->
|
||||||
contributionsSize = list.size
|
contributionsSize = list.size
|
||||||
l = ArrayList()
|
contributionsList = ArrayList()
|
||||||
var x = 0;
|
var x = 0;
|
||||||
|
var y = 0;
|
||||||
list.forEach {
|
list.forEach {
|
||||||
if (it != null){
|
if (it != null){
|
||||||
if (it.state == Contribution.STATE_PAUSED
|
if (it.state == Contribution.STATE_PAUSED
|
||||||
|| it.state == Contribution.STATE_QUEUED
|
|| it.state == Contribution.STATE_QUEUED
|
||||||
|| it.state == Contribution.STATE_IN_PROGRESS
|
|| it.state == Contribution.STATE_IN_PROGRESS
|
||||||
) {
|
) {
|
||||||
l.add(it)
|
contributionsList.add(it)
|
||||||
}
|
}
|
||||||
if (it.state == Contribution.STATE_PAUSED
|
if (it.state == Contribution.STATE_PAUSED
|
||||||
|| it.state == Contribution.STATE_QUEUED
|
|| it.state == Contribution.STATE_QUEUED
|
||||||
) {
|
) {
|
||||||
x++
|
x++
|
||||||
}
|
}
|
||||||
|
if (it.state == Contribution.STATE_FAILED){
|
||||||
|
y++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (l.size == 0) {
|
}
|
||||||
|
if (y == 0){
|
||||||
|
uploadProgressActivity.setErrorIconsVisibility(false)
|
||||||
|
}else{
|
||||||
|
uploadProgressActivity.setErrorIconsVisibility(true)
|
||||||
|
}
|
||||||
|
if (contributionsList.size == 0) {
|
||||||
binding.nopendingTextView.visibility = View.VISIBLE
|
binding.nopendingTextView.visibility = View.VISIBLE
|
||||||
binding.pendingUplaodsLl.visibility = View.GONE
|
binding.pendingUplaodsLl.visibility = View.GONE
|
||||||
uploadProgressActivity.hidePendingIcons()
|
uploadProgressActivity.hidePendingIcons()
|
||||||
} else {
|
} else {
|
||||||
if (totalUploads == 0){
|
if (totalUploads == 0){
|
||||||
totalUploads = l.size
|
totalUploads = contributionsList.size
|
||||||
binding.progressBarPending.max = totalUploads
|
binding.progressBarPending.max = totalUploads
|
||||||
}
|
}
|
||||||
binding.nopendingTextView.visibility = View.GONE
|
binding.nopendingTextView.visibility = View.GONE
|
||||||
binding.pendingUplaodsLl.visibility = View.VISIBLE
|
binding.pendingUplaodsLl.visibility = View.VISIBLE
|
||||||
val adapter = PendingUploadsAdapter(l, this)
|
|
||||||
|
val sortedContributionsList: List<Contribution> = if (VERSION.SDK_INT >= VERSION_CODES.N) {
|
||||||
|
contributionsList.sortedByDescending { it.dateModifiedInMillis() }
|
||||||
|
} else {
|
||||||
|
contributionsList.sortedBy { it.dateModifiedInMillis() }.reversed()
|
||||||
|
}
|
||||||
|
|
||||||
|
val newContributionList: MutableList<Contribution> = sortedContributionsList.toMutableList()
|
||||||
|
val listOfRemoved: MutableList<Contribution> = mutableListOf()
|
||||||
|
val last = sortedContributionsList.last()
|
||||||
|
for (i in sortedContributionsList.indices) {
|
||||||
|
val current = sortedContributionsList[i]
|
||||||
|
if (current.transferred == 0L && (current.dateModifiedInMillis() / 100) > (last.dateModifiedInMillis() / 100)){
|
||||||
|
listOfRemoved.add(current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newContributionList.removeAll(listOfRemoved)
|
||||||
|
newContributionList.addAll(listOfRemoved)
|
||||||
|
val adapter = PendingUploadsAdapter(newContributionList, this)
|
||||||
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
||||||
binding.progressTextView.setText((totalUploads-l.size).toString() + "/" + totalUploads + " uploaded")
|
binding.progressTextView.setText((totalUploads-contributionsList.size).toString() + "/" + totalUploads + " uploaded")
|
||||||
binding.progressBarPending.progress = totalUploads-l.size
|
binding.progressBarPending.progress = totalUploads-contributionsList.size
|
||||||
if (x == l.size) {
|
if (x == contributionsList.size) {
|
||||||
uploadProgressActivity.setPausedIcon(true)
|
uploadProgressActivity.setPausedIcon(true)
|
||||||
}else{
|
}else{
|
||||||
uploadProgressActivity.setPausedIcon(false)
|
uploadProgressActivity.setPausedIcon(false)
|
||||||
|
|
@ -203,14 +233,14 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
}
|
}
|
||||||
|
|
||||||
fun restartUploads() {
|
fun restartUploads() {
|
||||||
if (l != null){
|
if (contributionsList != null){
|
||||||
pendingUploadsPresenter.restartUploads(l, 0 , this.requireContext().applicationContext)
|
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseUploads() {
|
fun pauseUploads() {
|
||||||
if (l != null){
|
if (contributionsList != null){
|
||||||
pendingUploadsPresenter.pauseUploads(l, 0, this.requireContext().applicationContext)
|
pendingUploadsPresenter.pauseUploads(contributionsList, 0, this.requireContext().applicationContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class UploadProgressActivity : BaseActivity() {
|
||||||
val titleList: MutableList<String> = ArrayList()
|
val titleList: MutableList<String> = ArrayList()
|
||||||
var isPaused = true
|
var isPaused = true
|
||||||
var isPendingIconsVisible = true
|
var isPendingIconsVisible = true
|
||||||
|
var isErrorIconsVisisble = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -117,9 +118,13 @@ class UploadProgressActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (currentPosition == 1) {
|
} else if (currentPosition == 1) {
|
||||||
|
if (isErrorIconsVisisble){
|
||||||
if (menu!!.findItem(R.id.retry_icon) == null) {
|
if (menu!!.findItem(R.id.retry_icon) == null) {
|
||||||
menu!!.add(Menu.NONE, R.id.retry_icon, Menu.NONE, "Retry")
|
menu!!.add(Menu.NONE, R.id.retry_icon, Menu.NONE, "Retry")
|
||||||
.setIcon(R.drawable.ic_refresh_white_24dp)
|
.setIcon(R.drawable.ic_refresh_white_24dp).setOnMenuItemClickListener {
|
||||||
|
failedUploadsFragment!!.restartUploads()
|
||||||
|
true
|
||||||
|
}
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
|
||||||
}
|
}
|
||||||
if (menu!!.findItem(R.id.cancel_icon) == null) {
|
if (menu!!.findItem(R.id.cancel_icon) == null) {
|
||||||
|
|
@ -132,6 +137,7 @@ class UploadProgressActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun hidePendingIcons() {
|
fun hidePendingIcons() {
|
||||||
isPendingIconsVisible = false
|
isPendingIconsVisible = false
|
||||||
|
|
@ -143,4 +149,9 @@ class UploadProgressActivity : BaseActivity() {
|
||||||
updateMenuItems(binding.uploadProgressViewPager.currentItem)
|
updateMenuItems(binding.uploadProgressViewPager.currentItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setErrorIconsVisibility(visible : Boolean){
|
||||||
|
isErrorIconsVisisble = visible
|
||||||
|
updateMenuItems(binding.uploadProgressViewPager.currentItem)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue