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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -72,14 +72,8 @@ public class ContributionsListAdapter extends
|
|||
|
||||
void retryUpload(Contribution contribution);
|
||||
|
||||
void deleteUpload(Contribution contribution);
|
||||
|
||||
void openMediaDetail(int contribution, boolean isWikipediaPageExists);
|
||||
|
||||
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> {
|
||||
|
||||
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
|
||||
public void openMediaDetail(final int position, boolean isWikipediaButtonDisplayed) {
|
||||
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
|
||||
*
|
||||
|
|
@ -560,8 +521,6 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
|
||||
void showDetail(int position, boolean isWikipediaButtonDisplayed);
|
||||
|
||||
void pauseUpload(Contribution contribution);
|
||||
|
||||
// Notify the viewpager that number of items have changed.
|
||||
void viewPagerNotifyDataSetChanged();
|
||||
|
||||
|
|
|
|||
|
|
@ -90,17 +90,6 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
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) {
|
||||
final PagedList.Config pagedListConfig =
|
||||
(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() {
|
||||
if (contributionsList != null){
|
||||
pendingUploadsPresenter.restartUploads(contributionsList, 0 , this.requireContext().applicationContext)
|
||||
|
|
|
|||
|
|
@ -7,12 +7,6 @@ import fr.free.nrw.commons.contributions.Contribution;
|
|||
public class PendingUploadsContract {
|
||||
|
||||
public interface View {
|
||||
|
||||
void showWelcomeTip(boolean numberOfUploads);
|
||||
|
||||
void showProgress(boolean shouldShow);
|
||||
|
||||
void showNoContributionsUI(boolean shouldShow);
|
||||
}
|
||||
|
||||
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() {
|
||||
if (contributionsList != null){
|
||||
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) {
|
||||
if (index >= l.size()) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ data class StashUploadResult(
|
|||
enum class StashUploadState {
|
||||
SUCCESS,
|
||||
PAUSED,
|
||||
FAILED
|
||||
FAILED,
|
||||
CANCELLED
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,15 +78,23 @@ class UploadClient @Inject constructor(
|
|||
compositeDisposable.add(
|
||||
Observable.fromIterable(fileChunks).forEach { chunkFile: File ->
|
||||
if (canProcess(contribution, failures)) {
|
||||
if (CommonsApplication.cancelledUploads.contains(contribution.pageId)) {
|
||||
compositeDisposable.clear()
|
||||
return@forEach
|
||||
}else{
|
||||
processChunk(
|
||||
filename, contribution, notificationUpdater, chunkFile,
|
||||
failures, chunkInfo, index, errorMessage, mediaType!!, file!!, fileChunks.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return when {
|
||||
CommonsApplication.cancelledUploads.contains(contribution.pageId) -> {
|
||||
return Observable.just(StashUploadResult(StashUploadState.CANCELLED, null, "Upload cancelled"))
|
||||
}
|
||||
contribution.isPaused() -> {
|
||||
Timber.d("Upload stash paused %s", contribution.pageId)
|
||||
Observable.just(StashUploadResult(StashUploadState.PAUSED, null, null))
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
.blockingGet()
|
||||
//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.setContentText(
|
||||
|
|
@ -344,7 +344,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
).onErrorReturn{
|
||||
return@onErrorReturn StashUploadResult(StashUploadState.FAILED,fileKey = null,errorMessage = it.message)
|
||||
}.blockingSingle()
|
||||
|
||||
Timber.tag("PRINT").e("-- "+stashUploadResult.state)
|
||||
when (stashUploadResult.state) {
|
||||
StashUploadState.SUCCESS -> {
|
||||
//If the stash upload succeeds
|
||||
|
|
@ -404,6 +404,9 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
contribution.state = Contribution.STATE_PAUSED
|
||||
contributionDao.saveSynchronous(contribution)
|
||||
}
|
||||
StashUploadState.CANCELLED -> {
|
||||
showCancelledNotification(contribution)
|
||||
}
|
||||
else -> {
|
||||
Timber.e("""upload file to stash failed with status: ${stashUploadResult.state}""")
|
||||
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
|
||||
* @param toClass
|
||||
|
|
|
|||
|
|
@ -137,20 +137,6 @@ class ContributionsListFragmentUnitTests {
|
|||
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
|
||||
@Throws(Exception::class)
|
||||
fun testAddImageToWikipedia() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue