Skip to content

Commit

Permalink
automate retries for failed uploads once the user returns to the app
Browse files Browse the repository at this point in the history
  • Loading branch information
RitikaPahwa4444 committed Jul 7, 2023
1 parent 4aa4ea0 commit 96058ff
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.free.nrw.commons.contributions;

import android.Manifest.permission;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -47,6 +48,8 @@
import fr.free.nrw.commons.upload.worker.UploadWorker;
import fr.free.nrw.commons.utils.PermissionUtils;
import fr.free.nrw.commons.utils.ViewUtilWrapper;
import io.reactivex.schedulers.Schedulers;
import java.util.Collections;
import javax.inject.Inject;
import javax.inject.Named;
import timber.log.Timber;
Expand All @@ -58,6 +61,8 @@ public class MainActivity extends BaseActivity
SessionManager sessionManager;
@Inject
ContributionController controller;
@Inject
ContributionDao contributionDao;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.pager)
Expand Down Expand Up @@ -360,6 +365,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

/**
* Retry all failed uploads as soon as the user returns to the app
*/
@SuppressLint("CheckResult")
private void retryAllFailedUploads() {
contributionDao.
getContribution(Collections.singletonList(Contribution.STATE_FAILED))
.subscribeOn(Schedulers.io())
.subscribe(failedUploads -> {
for (Contribution contribution: failedUploads) {
contributionsFragment.retryUpload(contribution);
}
});
}

public void toggleLimitedConnectionMode() {
defaultKvStore.putBoolean(CommonsApplication.IS_LIMITED_CONNECTION_MODE_ENABLED,
!defaultKvStore
Expand Down Expand Up @@ -405,6 +425,8 @@ protected void onResume() {
(!applicationKvStore.getBoolean("login_skipped"))) {
WelcomeActivity.startYourself(this);
}

retryAllFailedUploads();
}

@Override
Expand Down

0 comments on commit 96058ff

Please sign in to comment.