mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Improved the deletion feature
This commit is contained in:
parent
517e0ca503
commit
c3b8f6ade3
6 changed files with 102 additions and 37 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.free.nrw.commons.upload
|
package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
@ -7,13 +8,17 @@ 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
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
|
||||||
import fr.free.nrw.commons.media.MediaClient
|
import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.profile.ProfileActivity
|
import fr.free.nrw.commons.profile.ProfileActivity
|
||||||
|
import fr.free.nrw.commons.utils.DialogUtil
|
||||||
|
import fr.free.nrw.commons.utils.ViewUtil
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
|
import java.util.Locale
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,7 +27,6 @@ import javax.inject.Inject
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContract.View {
|
class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContract.View {
|
||||||
// TODO: Rename and change types of parameters
|
|
||||||
private var param1: String? = null
|
private var param1: String? = null
|
||||||
private var param2: String? = null
|
private var param2: String? = null
|
||||||
private val ARG_PARAM1 = "param1"
|
private val ARG_PARAM1 = "param1"
|
||||||
|
|
@ -43,6 +47,15 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
|
|
||||||
var contributionsList = ArrayList<Contribution>()
|
var contributionsList = ArrayList<Contribution>()
|
||||||
|
|
||||||
|
private lateinit var uploadProgressActivity: UploadProgressActivity
|
||||||
|
|
||||||
|
override fun onAttach(context: Context) {
|
||||||
|
super.onAttach(context)
|
||||||
|
if (context is UploadProgressActivity) {
|
||||||
|
uploadProgressActivity = context
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
|
|
@ -82,7 +95,7 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
) { list: PagedList<Contribution?> ->
|
) { list: PagedList<Contribution?> ->
|
||||||
contributionsList = 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) {
|
||||||
contributionsList.add(it)
|
contributionsList.add(it)
|
||||||
}
|
}
|
||||||
|
|
@ -101,15 +114,6 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
|
||||||
* Use this factory method to create a new instance of
|
|
||||||
* this fragment using the provided parameters.
|
|
||||||
*
|
|
||||||
* @param param1 Parameter 1.
|
|
||||||
* @param param2 Parameter 2.
|
|
||||||
* @return A new instance of fragment FailedUploadsFragment.
|
|
||||||
*/
|
|
||||||
// TODO: Rename and change types and number of parameters
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun newInstance(param1: String, param2: String) =
|
fun newInstance(param1: String, param2: String) =
|
||||||
FailedUploadsFragment().apply {
|
FailedUploadsFragment().apply {
|
||||||
|
|
@ -121,8 +125,40 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
}
|
}
|
||||||
|
|
||||||
fun restartUploads() {
|
fun restartUploads() {
|
||||||
if (contributionsList != null){
|
if (contributionsList != null) {
|
||||||
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
pendingUploadsPresenter.restartUploads(
|
||||||
|
contributionsList,
|
||||||
|
0,
|
||||||
|
this.requireContext().applicationContext
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteUploads() {
|
||||||
|
if (contributionsList != null) {
|
||||||
|
DialogUtil.showAlertDialog(
|
||||||
|
requireActivity(),
|
||||||
|
String.format(
|
||||||
|
Locale.getDefault(),
|
||||||
|
getString(R.string.cancelling_all_the_uploads)
|
||||||
|
),
|
||||||
|
String.format(
|
||||||
|
Locale.getDefault(),
|
||||||
|
getString(R.string.are_you_sure_that_you_want_cancel_all_the_uploads)
|
||||||
|
),
|
||||||
|
String.format(Locale.getDefault(), getString(R.string.yes)),
|
||||||
|
String.format(Locale.getDefault(), getString(R.string.no)),
|
||||||
|
{
|
||||||
|
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||||
|
uploadProgressActivity.hidePendingIcons()
|
||||||
|
pendingUploadsPresenter.deleteUploads(
|
||||||
|
contributionsList,
|
||||||
|
0,
|
||||||
|
this.requireContext().applicationContext
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,8 +6,7 @@ import fr.free.nrw.commons.contributions.Contribution;
|
||||||
|
|
||||||
public class PendingUploadsContract {
|
public class PendingUploadsContract {
|
||||||
|
|
||||||
public interface View {
|
public interface View { }
|
||||||
}
|
|
||||||
|
|
||||||
public interface UserActionListener extends
|
public interface UserActionListener extends
|
||||||
BasePresenter<fr.free.nrw.commons.upload.PendingUploadsContract.View> {
|
BasePresenter<fr.free.nrw.commons.upload.PendingUploadsContract.View> {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import fr.free.nrw.commons.profile.ProfileActivity
|
||||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||||
import fr.free.nrw.commons.utils.ViewUtil
|
import fr.free.nrw.commons.utils.ViewUtil
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import timber.log.Timber
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
@ -32,9 +31,6 @@ import javax.inject.Inject
|
||||||
*/
|
*/
|
||||||
class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsContract.View,
|
class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsContract.View,
|
||||||
PendingUploadsAdapter.Callback{
|
PendingUploadsAdapter.Callback{
|
||||||
var isPendingIconsVisible = false
|
|
||||||
|
|
||||||
// TODO: Rename and change types of parameters
|
|
||||||
private var param1: String? = null
|
private var param1: String? = null
|
||||||
private var param2: String? = null
|
private var param2: String? = null
|
||||||
private val ARG_PARAM1 = "param1"
|
private val ARG_PARAM1 = "param1"
|
||||||
|
|
@ -111,8 +107,8 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
) { list: PagedList<Contribution?> ->
|
) { list: PagedList<Contribution?> ->
|
||||||
contributionsSize = list.size
|
contributionsSize = list.size
|
||||||
contributionsList = ArrayList()
|
contributionsList = ArrayList()
|
||||||
var x = 0;
|
var pausedOrQueuedUploads = 0
|
||||||
var y = 0;
|
var failedUploads = 0
|
||||||
list.forEach {
|
list.forEach {
|
||||||
if (it != null){
|
if (it != null){
|
||||||
if (it.state == Contribution.STATE_PAUSED
|
if (it.state == Contribution.STATE_PAUSED
|
||||||
|
|
@ -124,14 +120,14 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
if (it.state == Contribution.STATE_PAUSED
|
if (it.state == Contribution.STATE_PAUSED
|
||||||
|| it.state == Contribution.STATE_QUEUED
|
|| it.state == Contribution.STATE_QUEUED
|
||||||
) {
|
) {
|
||||||
x++
|
pausedOrQueuedUploads++
|
||||||
}
|
}
|
||||||
if (it.state == Contribution.STATE_FAILED){
|
if (it.state == Contribution.STATE_FAILED){
|
||||||
y++
|
failedUploads++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (y == 0){
|
if (failedUploads == 0){
|
||||||
uploadProgressActivity.setErrorIconsVisibility(false)
|
uploadProgressActivity.setErrorIconsVisibility(false)
|
||||||
}else{
|
}else{
|
||||||
uploadProgressActivity.setErrorIconsVisibility(true)
|
uploadProgressActivity.setErrorIconsVisibility(true)
|
||||||
|
|
@ -169,7 +165,7 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
||||||
binding.progressTextView.setText((totalUploads-contributionsList.size).toString() + "/" + totalUploads + " uploaded")
|
binding.progressTextView.setText((totalUploads-contributionsList.size).toString() + "/" + totalUploads + " uploaded")
|
||||||
binding.progressBarPending.progress = totalUploads-contributionsList.size
|
binding.progressBarPending.progress = totalUploads-contributionsList.size
|
||||||
if (x == contributionsList.size) {
|
if (pausedOrQueuedUploads == contributionsList.size) {
|
||||||
uploadProgressActivity.setPausedIcon(true)
|
uploadProgressActivity.setPausedIcon(true)
|
||||||
}else{
|
}else{
|
||||||
uploadProgressActivity.setPausedIcon(false)
|
uploadProgressActivity.setPausedIcon(false)
|
||||||
|
|
@ -201,15 +197,6 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
|
||||||
* Use this factory method to create a new instance of
|
|
||||||
* this fragment using the provided parameters.
|
|
||||||
*
|
|
||||||
* @param param1 Parameter 1.
|
|
||||||
* @param param2 Parameter 2.
|
|
||||||
* @return A new instance of fragment PendingUploadsFragment.
|
|
||||||
*/
|
|
||||||
// TODO: Rename and change types and number of parameters
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun newInstance(param1: String, param2: String) =
|
fun newInstance(param1: String, param2: String) =
|
||||||
PendingUploadsFragment().apply {
|
PendingUploadsFragment().apply {
|
||||||
|
|
@ -232,5 +219,27 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteUploads(){
|
||||||
|
if (contributionsList != null){
|
||||||
|
showAlertDialog(
|
||||||
|
requireActivity(),
|
||||||
|
String.format(
|
||||||
|
Locale.getDefault(),
|
||||||
|
"Cancelling all the uploads..."
|
||||||
|
),
|
||||||
|
String.format(
|
||||||
|
Locale.getDefault(),
|
||||||
|
"Are you sure that you want cancel all the uploads?"
|
||||||
|
),
|
||||||
|
String.format(Locale.getDefault(), getString(R.string.yes)),
|
||||||
|
String.format(Locale.getDefault(), getString(R.string.no)),
|
||||||
|
{
|
||||||
|
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||||
|
uploadProgressActivity.hidePendingIcons()
|
||||||
|
pendingUploadsPresenter.deleteUploads(contributionsList, 0, this.requireContext().applicationContext)
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,6 +139,25 @@ public class PendingUploadsPresenter implements UserActionListener {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteUploads(List<Contribution> l, int index, Context context) {
|
||||||
|
if (index >= l.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Contribution it = l.get(index);
|
||||||
|
compositeDisposable.add(repository
|
||||||
|
.deleteContributionFromDB(it)
|
||||||
|
.subscribeOn(ioThreadScheduler)
|
||||||
|
.doOnComplete(() -> {
|
||||||
|
CommonsApplication.cancelledUploads.add(it.getPageId());
|
||||||
|
deleteUploads(l, index + 1, context);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.subscribe(() ->
|
||||||
|
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
||||||
|
context, ExistingWorkPolicy.KEEP)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public void restartUploads(List<Contribution> l, int index, Context context) {
|
public void restartUploads(List<Contribution> l, int index, Context context) {
|
||||||
if (index >= l.size()) {
|
if (index >= l.size()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ class UploadProgressActivity : BaseActivity() {
|
||||||
if (menu!!.findItem(R.id.cancel_icon) == null) {
|
if (menu!!.findItem(R.id.cancel_icon) == null) {
|
||||||
menu!!.add(Menu.NONE, R.id.cancel_icon, Menu.NONE, "Cancel")
|
menu!!.add(Menu.NONE, R.id.cancel_icon, Menu.NONE, "Cancel")
|
||||||
.setIcon(android.R.drawable.ic_menu_close_clear_cancel).setOnMenuItemClickListener {
|
.setIcon(android.R.drawable.ic_menu_close_clear_cancel).setOnMenuItemClickListener {
|
||||||
hidePendingIcons()
|
pendingUploadsFragment!!.deleteUploads()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
|
||||||
|
|
@ -130,7 +130,7 @@ class UploadProgressActivity : BaseActivity() {
|
||||||
if (menu!!.findItem(R.id.cancel_icon) == null) {
|
if (menu!!.findItem(R.id.cancel_icon) == null) {
|
||||||
menu!!.add(Menu.NONE, R.id.cancel_icon, Menu.NONE, "Cancel")
|
menu!!.add(Menu.NONE, R.id.cancel_icon, Menu.NONE, "Cancel")
|
||||||
.setIcon(android.R.drawable.ic_menu_close_clear_cancel).setOnMenuItemClickListener {
|
.setIcon(android.R.drawable.ic_menu_close_clear_cancel).setOnMenuItemClickListener {
|
||||||
hidePendingIcons()
|
failedUploadsFragment!!.deleteUploads()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM)
|
||||||
|
|
|
||||||
|
|
@ -821,4 +821,6 @@ Upload your first media by tapping on the add button.</string>
|
||||||
<!-- TODO: Remove or change this placeholder text -->
|
<!-- TODO: Remove or change this placeholder text -->
|
||||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||||
<string name="feedback_destination_note">Your feedback gets posted to the following wiki page: <![CDATA[ <a href="https://commons.wikimedia.org/wiki/Commons:Mobile_app/Feedback">Commons:Mobile app/Feedback</a> ]]></string>
|
<string name="feedback_destination_note">Your feedback gets posted to the following wiki page: <![CDATA[ <a href="https://commons.wikimedia.org/wiki/Commons:Mobile_app/Feedback">Commons:Mobile app/Feedback</a> ]]></string>
|
||||||
|
<string name="are_you_sure_that_you_want_cancel_all_the_uploads">Are you sure that you want cancel all the uploads?</string>
|
||||||
|
<string name="cancelling_all_the_uploads">Cancelling all the uploads...</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue