Przeglądaj źródła

Hopefully fix retries

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 lat temu
rodzic
commit
98480ee4dc

+ 28 - 19
src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -32,7 +32,6 @@ import android.util.Log;
 import com.evernote.android.job.JobManager;
 import com.evernote.android.job.JobRequest;
 import com.evernote.android.job.util.Device;
-import com.evernote.android.job.util.support.PersistableBundleCompat;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
@@ -230,6 +229,7 @@ public class FilesSyncHelper {
         for (OCUpload failedUpload: failedUploads) {
             accountExists = false;
             fileExists = new File(failedUpload.getLocalPath()).exists();
+            restartedInCurrentIteration = false;
 
             // check if accounts still exists
             for (Account account : AccountUtils.getAccounts(context)) {
@@ -241,25 +241,34 @@ public class FilesSyncHelper {
 
             if (!failedUpload.getLastResult().equals(UploadResult.UPLOADED)) {
                 if (failedUpload.getCreadtedBy() == UploadFileOperation.CREATED_AS_INSTANT_PICTURE) {
-                    uploadsStorageManager.removeUpload(failedUpload);
-
                     if (accountExists && fileExists) {
-                        PersistableBundleCompat bundle = new PersistableBundleCompat();
-                        bundle.putString(AutoUploadJob.LOCAL_PATH, failedUpload.getLocalPath());
-                        bundle.putString(AutoUploadJob.REMOTE_PATH, failedUpload.getRemotePath());
-                        bundle.putString(AutoUploadJob.ACCOUNT, failedUpload.getAccountName());
-                        bundle.putInt(AutoUploadJob.UPLOAD_BEHAVIOUR, failedUpload.getLocalAction());
-
-                        new JobRequest.Builder(AutoUploadJob.TAG)
-                                .setExecutionWindow(10_000L, 10_000L)
-                                .setRequiresCharging(failedUpload.isWhileChargingOnly())
-                                .setRequiredNetworkType(failedUpload.isUseWifiOnly() ? JobRequest.NetworkType.UNMETERED :
-                                        JobRequest.NetworkType.CONNECTED)
-                                .setExtras(bundle)
-                                .setRequirementsEnforced(true)
-                                .setUpdateCurrent(false)
-                                .build()
-                                .schedule();
+                        // Handle case of charging
+
+                        if (failedUpload.isWhileChargingOnly() && Device.isCharging(context)) {
+                            if (failedUpload.isUseWifiOnly() &&
+                                    Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED)) {
+                                uploadRequester.retry(context, failedUpload);
+                                restartedInCurrentIteration = true;
+                            } else if (!failedUpload.isUseWifiOnly() &&
+                                    !Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY)) {
+                                uploadRequester.retry(context, failedUpload);
+                                restartedInCurrentIteration = true;
+                            }
+                        }
+
+                        // Handle case of wifi
+
+                        if (!restartedInCurrentIteration) {
+                            if (failedUpload.isUseWifiOnly() &&
+                                    Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED)) {
+                                uploadRequester.retry(context, failedUpload);
+                            } else if (!failedUpload.isUseWifiOnly() &&
+                                    !Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY)) {
+                                uploadRequester.retry(context, failedUpload);
+                            }
+                        }
+                    } else {
+                        uploadsStorageManager.removeUpload(failedUpload);
                     }
                 } else {
                     if (accountExists && fileExists) {

+ 1 - 1
src/main/res/values-en-rGB/strings.xml

@@ -169,7 +169,7 @@
     <string name="uploader_upload_failed_credentials_error">Upload failed, you need to log in again</string>
     <string name="uploads_view_title">Uploads</string>
     <string name="uploads_view_group_current_uploads">Current</string>
-    <string name="uploads_view_group_failed_uploads">Failed (tap to retry)</string>
+    <string name="uploads_view_group_failed_uploads">Failed / Pending restart</string>
     <string name="uploads_view_group_finished_uploads">Uploaded</string>
     <string name="uploads_view_upload_status_succeeded">Completed</string>
     <string name="uploads_view_upload_status_cancelled">Cancelled</string>