Forráskód Böngészése

Review behaviour of failed uploads: list in uploads view

masensio 9 éve
szülő
commit
66ec45f633

+ 2 - 0
src/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -3,6 +3,7 @@
  *
  *   @author LukeOwncloud
  *   @author David A. Velasco
+ *   @author masensio
  *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
@@ -152,6 +153,7 @@ public class UploadsStorageManager extends Observable {
         ContentValues cv = new ContentValues();
         cv.put(ProviderTableMeta.UPLOADS_PATH, ocUpload.getLocalPath());
         cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value);
+        cv.put(ProviderTableMeta.UPLOADS_LAST_RESULT, ocUpload.getLastResult().getValue());
 
         int result = getDB().update(ProviderTableMeta.CONTENT_URI_UPLOADS,
                 cv,

+ 2 - 2
src/com/owncloud/android/db/OCUpload.java

@@ -108,7 +108,7 @@ public class OCUpload {
         mUploadTimestamp = -1;
         mAccountName = "";
         mUploadStatus = UploadStatus.UPLOAD_LATER;
-        mLastResult = UploadResult.UPLOADED;
+        mLastResult = UploadResult.UNKNOWN;
     }
 
     // Getters & Setters
@@ -140,7 +140,7 @@ public class OCUpload {
      */
     public void setUploadStatus(UploadStatus uploadStatus) {
         this.mUploadStatus = uploadStatus;
-        setLastResult(null);
+        setLastResult(UploadResult.UNKNOWN);
     }
 
     /**

+ 55 - 8
src/com/owncloud/android/db/UploadResult.java

@@ -1,8 +1,27 @@
-package com.owncloud.android.db;
-
 /**
- * Created by masensio on 14/12/2015.
+ *   ownCloud Android client application
+ *
+ *   @author masensio
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
  */
+
+package com.owncloud.android.db;
+
+import com.owncloud.android.lib.common.operations.RemoteOperationResult;
+
 public enum UploadResult {
     UPLOADED(0),
     NETWORK_CONNECTION(1),
@@ -11,7 +30,8 @@ public enum UploadResult {
     CONFLICT_ERROR(4),
     FILE_ERROR(5),
     PRIVILEDGES_ERROR(6),
-    CANCELLED(7);
+    CANCELLED(7),
+    UNKNOWN(8);
 
     private final int value;
 
@@ -22,10 +42,8 @@ public enum UploadResult {
     public int getValue() {
         return value;
     }
-    public static UploadResult fromValue(int value)
-    {
-        switch (value)
-        {
+    public static UploadResult fromValue(int value) {
+        switch (value) {
             case 0:
                 return UPLOADED;
             case 1:
@@ -42,6 +60,35 @@ public enum UploadResult {
                 return PRIVILEDGES_ERROR;
             case 7:
                 return CANCELLED;
+            case 8:
+                return UNKNOWN;
+        }
+        return null;
+    }
+
+    public static UploadResult fromOperationResult(RemoteOperationResult result){
+        switch (result.getCode()){
+            case UNKNOWN_ERROR:
+                return UNKNOWN;
+            case OK:
+                return UPLOADED;
+            case NO_NETWORK_CONNECTION:
+            case HOST_NOT_AVAILABLE:
+            case TIMEOUT:
+            case WRONG_CONNECTION:
+                return NETWORK_CONNECTION;
+            case ACCOUNT_EXCEPTION:
+                return CREDENTIAL_ERROR;
+//            case
+//                return FOLDER_ERROR;
+            case CONFLICT:
+                return CONFLICT_ERROR;
+            case FILE_NOT_FOUND:
+                return FILE_ERROR;
+            case UNAUTHORIZED:
+                return PRIVILEDGES_ERROR;
+            case CANCELLED:
+                return CANCELLED;
         }
         return null;
     }

+ 34 - 30
src/com/owncloud/android/files/services/FileUploadService.java

@@ -1307,6 +1307,8 @@ public class FileUploadService extends Service implements OnDatatransferProgress
 //                }
             }
 
+            updateDatabaseUploadResult(uploadResult, mCurrentUpload);
+
             if(!uploadResult.isSuccess()){
                 //in case of failure, do not show details file view (because there is no file!)
                 Intent showUploadListIntent = new Intent(this, UploadListActivity.class);
@@ -1326,7 +1328,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
 //                db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath());
 //                db.close();
                 mPendingUploads.remove(upload.getAccount(), upload.getFile().getRemotePath());
-                updateDatabaseUploadResult(uploadResult, mCurrentUpload);
+                //updateDatabaseUploadResult(uploadResult, mCurrentUpload);
                 // remove success notification, with a delay of 2 seconds
                 NotificationDelayer.cancelWithDelay(mNotificationManager, R.string.uploader_upload_succeeded_ticker,
                         2000);
@@ -1356,39 +1358,40 @@ public class FileUploadService extends Service implements OnDatatransferProgress
                 );
             } else {
                 // TODO: Disable for testing of menu actions in uploads view
-//                if (shouldRetryFailedUpload(uploadResult)) {
-//                    mUploadsStorageManager.updateUploadStatus(
-//                        upload.getOriginalStoragePath(), UploadStatus.UPLOAD_FAILED_RETRY, uploadResult
-//                    );
-//                } else {
-//                    mUploadsStorageManager.updateUploadStatus(upload.getOriginalStoragePath(),
-//                            UploadsStorageManager.UploadStatus.UPLOAD_FAILED_GIVE_UP, uploadResult);
-//                }
+                if (shouldRetryFailedUpload(uploadResult)) {
+                    mUploadsStorageManager.updateUploadStatus(
+                            upload.getOriginalStoragePath(), UploadStatus.UPLOAD_FAILED_RETRY,
+                            UploadResult.fromOperationResult(uploadResult));
+                } else {
+                    mUploadsStorageManager.updateUploadStatus(upload.getOriginalStoragePath(),
+                            UploadsStorageManager.UploadStatus.UPLOAD_FAILED_GIVE_UP,
+                            UploadResult.fromOperationResult(uploadResult));
+                }
             }
         }
     }
 
     // TODO: Disable for testing of menu actions in uploads view
-//
-//    /**
-//     * Determines whether with given uploadResult the upload should be retried later.
-//     * @param uploadResult
-//     * @return true if upload should be retried later, false if is should be abandoned.
-//     */
-//    private boolean shouldRetryFailedUpload(RemoteOperationResult uploadResult) {
-//        if (uploadResult.isSuccess()) {
-//            return false;
-//        }
-//        switch (uploadResult.getCode()) {
-//        case HOST_NOT_AVAILABLE:
-//        case NO_NETWORK_CONNECTION:
-//        case TIMEOUT:
-//        case WRONG_CONNECTION: // SocketException
-//            return true;
-//        default:
-//            return false;
-//        }
-//    }
+
+    /**
+     * Determines whether with given uploadResult the upload should be retried later.
+     * @param uploadResult
+     * @return true if upload should be retried later, false if is should be abandoned.
+     */
+    private boolean shouldRetryFailedUpload(RemoteOperationResult uploadResult) {
+        if (uploadResult.isSuccess()) {
+            return false;
+        }
+        switch (uploadResult.getCode()) {
+            case HOST_NOT_AVAILABLE:
+            case NO_NETWORK_CONNECTION:
+            case TIMEOUT:
+            case WRONG_CONNECTION: // SocketException
+                return true;
+            default:
+                return false;
+        }
+    }
 
     /**
      * Updates the persistent upload database that upload is in progress.
@@ -1396,7 +1399,8 @@ public class FileUploadService extends Service implements OnDatatransferProgress
     private void updateDatabaseUploadStart(UploadFileOperation upload) {
         mUploadsStorageManager.updateUploadStatus(
                 upload.getOriginalStoragePath(),
-                UploadStatus.UPLOAD_IN_PROGRESS, null
+                UploadStatus.UPLOAD_IN_PROGRESS,
+                UploadResult.UNKNOWN
         );
     }
 

+ 7 - 13
src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -2,6 +2,7 @@
  *   ownCloud Android client application
  *
  *   @author LukeOwncloud
+ *   @author masensio
  *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
@@ -40,12 +41,12 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
 import com.owncloud.android.db.OCUpload;
+import com.owncloud.android.db.UploadResult;
 import com.owncloud.android.files.services.FileUploadService;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.utils.BitmapUtils;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimetypeIconUtil;
 
@@ -198,13 +199,6 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                     if(mParentActivity.getFileUploaderBinder() != null) {
                         mParentActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener,
                                 mParentActivity.getAccount(), uploadOCFile);
-//                        mCurrentUpload = mParentActivity.getFileUploaderBinder().getCurrentUploadOperation();
-//                        if(mCurrentUpload != null) {
-//                            mCurrentUpload.addDatatransferProgressListener(mProgressListener);
-//                            Log_OC.d(TAG, "added progress listener for current upload: " + mCurrentUpload);
-//                        } else {
-//                            Log_OC.w(TAG, "getFileUploaderBinder().getCurrentUploadOperation() return null. That is odd.");
-//                        }
                     } else {
                         Log_OC.e(TAG, "UploadBinder == null. It should have been created on creating mParentActivity"
                                 + " which inherits from FileActivity. Fix that!");
@@ -219,12 +213,12 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                     }
                     break;
                 case UPLOAD_FAILED_RETRY:
-                    if(upload.getLastResult() != null){
-                        status = "Last failure: "
-                                + upload.getLastResult().toString();
-                    } else {
+//                    if(upload.getLastResult() != UploadResult.UNKNOWN){
+//                        status = "Last failure: "
+//                                + upload.getLastResult().toString();
+//                    } else {
                         status = "Upload will be retried shortly.";
-                    }
+//                    }
                     String laterReason = FileUploadService.getUploadLaterReason(mParentActivity, upload);
                     if(laterReason != null) {
                         //Upload failed once but is delayed now, show reason.