mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fixed issue with on going upload deletion
This commit is contained in:
parent
6cf975fe49
commit
517e0ca503
13 changed files with 38 additions and 135 deletions
|
|
@ -721,20 +721,6 @@ public class ContributionsFragment
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pauses the upload
|
|
||||||
*
|
|
||||||
* @param contribution
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void pauseUpload(Contribution contribution) {
|
|
||||||
//Pause the upload in the global singleton
|
|
||||||
CommonsApplication.pauseUploads.put(contribution.getPageId(), true);
|
|
||||||
//Retain the paused state in DB
|
|
||||||
contribution.setState(STATE_PAUSED);
|
|
||||||
contributionsPresenter.saveContribution(contribution);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the viewpager that number of items have changed.
|
* Notify the viewpager that number of items have changed.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -72,14 +72,8 @@ public class ContributionsListAdapter extends
|
||||||
|
|
||||||
void retryUpload(Contribution contribution);
|
void retryUpload(Contribution contribution);
|
||||||
|
|
||||||
void deleteUpload(Contribution contribution);
|
|
||||||
|
|
||||||
void openMediaDetail(int contribution, boolean isWikipediaPageExists);
|
void openMediaDetail(int contribution, boolean isWikipediaPageExists);
|
||||||
|
|
||||||
void addImageToWikipedia(Contribution contribution);
|
void addImageToWikipedia(Contribution contribution);
|
||||||
|
|
||||||
void pauseUpload(Contribution contribution);
|
|
||||||
|
|
||||||
void resumeUpload(Contribution contribution);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,5 @@ public class ContributionsListContract {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface UserActionListener extends BasePresenter<View> {
|
public interface UserActionListener extends BasePresenter<View> {
|
||||||
|
|
||||||
void deleteUpload(Contribution contribution);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -442,23 +442,6 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteUpload(final Contribution contribution) {
|
|
||||||
DialogUtil.showAlertDialog(getActivity(),
|
|
||||||
String.format(Locale.getDefault(),
|
|
||||||
getString(R.string.cancelling_upload)),
|
|
||||||
String.format(Locale.getDefault(),
|
|
||||||
getString(R.string.cancel_upload_dialog)),
|
|
||||||
String.format(Locale.getDefault(), getString(R.string.yes)), String.format(Locale.getDefault(), getString(R.string.no)),
|
|
||||||
() -> {
|
|
||||||
ViewUtil.showShortToast(getContext(), R.string.cancelling_upload);
|
|
||||||
contributionsListPresenter.deleteUpload(contribution);
|
|
||||||
CommonsApplication.cancelledUploads.add(contribution.getPageId());
|
|
||||||
}, () -> {
|
|
||||||
// Do nothing
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openMediaDetail(final int position, boolean isWikipediaButtonDisplayed) {
|
public void openMediaDetail(final int position, boolean isWikipediaButtonDisplayed) {
|
||||||
if (null != callback) {//Just being safe, ideally they won't be called when detached
|
if (null != callback) {//Just being safe, ideally they won't be called when detached
|
||||||
|
|
@ -483,28 +466,6 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pauses the current upload
|
|
||||||
*
|
|
||||||
* @param contribution
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void pauseUpload(Contribution contribution) {
|
|
||||||
ViewUtil.showShortToast(getContext(), R.string.pausing_upload);
|
|
||||||
callback.pauseUpload(contribution);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resumes the current upload
|
|
||||||
*
|
|
||||||
* @param contribution
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void resumeUpload(Contribution contribution) {
|
|
||||||
ViewUtil.showShortToast(getContext(), R.string.resuming_upload);
|
|
||||||
callback.retryUpload(contribution);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display confirmation dialog with instructions when the user tries to add image to wikipedia
|
* Display confirmation dialog with instructions when the user tries to add image to wikipedia
|
||||||
*
|
*
|
||||||
|
|
@ -560,8 +521,6 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
||||||
|
|
||||||
void showDetail(int position, boolean isWikipediaButtonDisplayed);
|
void showDetail(int position, boolean isWikipediaButtonDisplayed);
|
||||||
|
|
||||||
void pauseUpload(Contribution contribution);
|
|
||||||
|
|
||||||
// Notify the viewpager that number of items have changed.
|
// Notify the viewpager that number of items have changed.
|
||||||
void viewPagerNotifyDataSetChanged();
|
void viewPagerNotifyDataSetChanged();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,17 +90,6 @@ public class ContributionsListPresenter implements UserActionListener {
|
||||||
contributionBoundaryCallback.dispose();
|
contributionBoundaryCallback.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a failed contribution from the local db
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void deleteUpload(final Contribution contribution) {
|
|
||||||
compositeDisposable.add(repository
|
|
||||||
.deleteContributionFromDB(contribution)
|
|
||||||
.subscribeOn(ioThreadScheduler)
|
|
||||||
.subscribe());
|
|
||||||
}
|
|
||||||
|
|
||||||
void getTotalContribution(String userName) {
|
void getTotalContribution(String userName) {
|
||||||
final PagedList.Config pagedListConfig =
|
final PagedList.Config pagedListConfig =
|
||||||
(new PagedList.Config.Builder())
|
(new PagedList.Config.Builder())
|
||||||
|
|
|
||||||
|
|
@ -120,18 +120,6 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showWelcomeTip(numberOfUploads: Boolean) {
|
|
||||||
//TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showProgress(shouldShow: Boolean) {
|
|
||||||
//TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showNoContributionsUI(shouldShow: Boolean) {
|
|
||||||
//TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun restartUploads() {
|
fun restartUploads() {
|
||||||
if (contributionsList != null){
|
if (contributionsList != null){
|
||||||
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,6 @@ import fr.free.nrw.commons.contributions.Contribution;
|
||||||
public class PendingUploadsContract {
|
public class PendingUploadsContract {
|
||||||
|
|
||||||
public interface View {
|
public interface View {
|
||||||
|
|
||||||
void showWelcomeTip(boolean numberOfUploads);
|
|
||||||
|
|
||||||
void showProgress(boolean shouldShow);
|
|
||||||
|
|
||||||
void showNoContributionsUI(boolean shouldShow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface UserActionListener extends
|
public interface UserActionListener extends
|
||||||
|
|
|
||||||
|
|
@ -220,18 +220,6 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showWelcomeTip(numberOfUploads: Boolean) {
|
|
||||||
//TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showProgress(shouldShow: Boolean) {
|
|
||||||
//TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showNoContributionsUI(shouldShow: Boolean) {
|
|
||||||
//TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun restartUploads() {
|
fun restartUploads() {
|
||||||
if (contributionsList != null){
|
if (contributionsList != null){
|
||||||
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
||||||
|
|
|
||||||
|
|
@ -118,16 +118,6 @@ public class PendingUploadsPresenter implements UserActionListener {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveContribution(Contribution contribution, Context context) {
|
|
||||||
compositeDisposable.add(repository
|
|
||||||
.save(contribution)
|
|
||||||
.subscribeOn(ioThreadScheduler)
|
|
||||||
.subscribe(() ->
|
|
||||||
WorkRequestHelper.Companion.makeOneTimeWorkRequest(
|
|
||||||
context, ExistingWorkPolicy.KEEP)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pauseUploads(List<Contribution> l, int index, Context context) {
|
public void pauseUploads(List<Contribution> l, int index, Context context) {
|
||||||
if (index >= l.size()) {
|
if (index >= l.size()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,6 @@ data class StashUploadResult(
|
||||||
enum class StashUploadState {
|
enum class StashUploadState {
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
PAUSED,
|
PAUSED,
|
||||||
FAILED
|
FAILED,
|
||||||
|
CANCELLED
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,15 +78,23 @@ class UploadClient @Inject constructor(
|
||||||
compositeDisposable.add(
|
compositeDisposable.add(
|
||||||
Observable.fromIterable(fileChunks).forEach { chunkFile: File ->
|
Observable.fromIterable(fileChunks).forEach { chunkFile: File ->
|
||||||
if (canProcess(contribution, failures)) {
|
if (canProcess(contribution, failures)) {
|
||||||
processChunk(
|
if (CommonsApplication.cancelledUploads.contains(contribution.pageId)) {
|
||||||
filename, contribution, notificationUpdater, chunkFile,
|
compositeDisposable.clear()
|
||||||
failures, chunkInfo, index, errorMessage, mediaType!!, file!!, fileChunks.size
|
return@forEach
|
||||||
)
|
}else{
|
||||||
|
processChunk(
|
||||||
|
filename, contribution, notificationUpdater, chunkFile,
|
||||||
|
failures, chunkInfo, index, errorMessage, mediaType!!, file!!, fileChunks.size
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
|
CommonsApplication.cancelledUploads.contains(contribution.pageId) -> {
|
||||||
|
return Observable.just(StashUploadResult(StashUploadState.CANCELLED, null, "Upload cancelled"))
|
||||||
|
}
|
||||||
contribution.isPaused() -> {
|
contribution.isPaused() -> {
|
||||||
Timber.d("Upload stash paused %s", contribution.pageId)
|
Timber.d("Upload stash paused %s", contribution.pageId)
|
||||||
Observable.just(StashUploadResult(StashUploadState.PAUSED, null, null))
|
Observable.just(StashUploadResult(StashUploadState.PAUSED, null, null))
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
||||||
.blockingGet()
|
.blockingGet()
|
||||||
//Showing initial notification for the number of uploads being processed
|
//Showing initial notification for the number of uploads being processed
|
||||||
|
|
||||||
Timber.e("Queued Contributions: " + queuedContributions.size)
|
Timber.tag("PRINT").e("Queued Contributions: " + queuedContributions.size)
|
||||||
|
|
||||||
processingUploads.setContentTitle(appContext.getString(R.string.starting_uploads))
|
processingUploads.setContentTitle(appContext.getString(R.string.starting_uploads))
|
||||||
processingUploads.setContentText(
|
processingUploads.setContentText(
|
||||||
|
|
@ -344,7 +344,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
||||||
).onErrorReturn{
|
).onErrorReturn{
|
||||||
return@onErrorReturn StashUploadResult(StashUploadState.FAILED,fileKey = null,errorMessage = it.message)
|
return@onErrorReturn StashUploadResult(StashUploadState.FAILED,fileKey = null,errorMessage = it.message)
|
||||||
}.blockingSingle()
|
}.blockingSingle()
|
||||||
|
Timber.tag("PRINT").e("-- "+stashUploadResult.state)
|
||||||
when (stashUploadResult.state) {
|
when (stashUploadResult.state) {
|
||||||
StashUploadState.SUCCESS -> {
|
StashUploadState.SUCCESS -> {
|
||||||
//If the stash upload succeeds
|
//If the stash upload succeeds
|
||||||
|
|
@ -404,6 +404,9 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
||||||
contribution.state = Contribution.STATE_PAUSED
|
contribution.state = Contribution.STATE_PAUSED
|
||||||
contributionDao.saveSynchronous(contribution)
|
contributionDao.saveSynchronous(contribution)
|
||||||
}
|
}
|
||||||
|
StashUploadState.CANCELLED -> {
|
||||||
|
showCancelledNotification(contribution)
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
Timber.e("""upload file to stash failed with status: ${stashUploadResult.state}""")
|
Timber.e("""upload file to stash failed with status: ${stashUploadResult.state}""")
|
||||||
showInvalidLoginNotification(contribution)
|
showInvalidLoginNotification(contribution)
|
||||||
|
|
@ -622,6 +625,25 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify that the current upload is cancelled
|
||||||
|
* @param contribution
|
||||||
|
*/
|
||||||
|
private fun showCancelledNotification(contribution: Contribution) {
|
||||||
|
val displayTitle = contribution.media.displayTitle
|
||||||
|
curentNotification.setContentIntent(getPendingIntent(UploadProgressActivity::class.java))
|
||||||
|
curentNotification.setContentTitle(
|
||||||
|
displayTitle
|
||||||
|
)
|
||||||
|
.setContentText("Upload has been cancelled!")
|
||||||
|
.setProgress(0, 0, false)
|
||||||
|
.setOngoing(false)
|
||||||
|
notificationManager!!.notify(
|
||||||
|
currentNotificationTag, currentNotificationID,
|
||||||
|
curentNotification.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method used to get Pending intent for opening different screen after clicking on notification
|
* Method used to get Pending intent for opening different screen after clicking on notification
|
||||||
* @param toClass
|
* @param toClass
|
||||||
|
|
|
||||||
|
|
@ -137,20 +137,6 @@ class ContributionsListFragmentUnitTests {
|
||||||
method.invoke(fragment, contribution)
|
method.invoke(fragment, contribution)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testResumeUpload() {
|
|
||||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
|
||||||
fragment.resumeUpload(contribution)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testPauseUpload() {
|
|
||||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
|
||||||
fragment.pauseUpload(contribution)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testAddImageToWikipedia() {
|
fun testAddImageToWikipedia() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue