Преглед изворни кода

added laterReason for once failed uploads

Luke Owncloud пре 10 година
родитељ
комит
5879e1b194

+ 5 - 5
src/com/owncloud/android/db/UploadDbHandler.java

@@ -213,8 +213,8 @@ public class UploadDbHandler extends Observable {
      * 
      * @return 1 if file status was updated, else 0.
      */
-    public int updateUpload(UploadDbObject uploadDbObject) {
-        return updateUpload(uploadDbObject.getLocalPath(), uploadDbObject.getUploadStatus(),
+    public int updateUploadStatus(UploadDbObject uploadDbObject) {
+        return updateUploadStatus(uploadDbObject.getLocalPath(), uploadDbObject.getUploadStatus(),
                 uploadDbObject.getLastResult());
     }
 
@@ -262,7 +262,7 @@ public class UploadDbHandler extends Observable {
      * @param result new result of upload operation
      * @return 1 if file status was updated, else 0.
      */
-    public int updateUpload(String filepath, UploadStatus status, RemoteOperationResult result) {
+    public int updateUploadStatus(String filepath, UploadStatus status, RemoteOperationResult result) {
         
 //        Log_OC.e(TAG, "Updating "+filepath+" with uploadStatus="+status +" and result="+result);
         
@@ -384,7 +384,7 @@ public class UploadDbHandler extends Observable {
     }
 
     public long clearFailedUploads() {
-        String[] where = new String[3];
+        String[] where = new String[2];
         where[0] = String.valueOf(UploadStatus.UPLOAD_CANCELLED.value);
         where[1] = String.valueOf(UploadStatus.UPLOAD_FAILED_GIVE_UP.value);
         long result = getDB().delete(TABLE_UPLOAD, "uploadStatus = ? OR uploadStatus = ?", where);
@@ -396,7 +396,7 @@ public class UploadDbHandler extends Observable {
     }
 
     public long clearFinishedUploads() {
-        String[] where = new String[3];
+        String[] where = new String[1];
         where[0] = String.valueOf(UploadStatus.UPLOAD_SUCCEEDED.value);
         long result = getDB().delete(TABLE_UPLOAD, "uploadStatus = ?", where);
         Log_OC.d(TABLE_UPLOAD, "delete all finished uploads");

+ 2 - 2
src/com/owncloud/android/files/FileOperationsHelper.java

@@ -248,13 +248,13 @@ public class FileOperationsHelper {
     }
 
     /**
-     * Retry uploading a failed or cancelled upload with force. That is, all restrictions (wifi-only, etc.) are removed from upload.
+     * Retry uploading a failed or cancelled upload with force.
      */
     public void retryUpload(UploadDbObject upload) {
         Account account = mFileActivity.getAccount();
         FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
         if (uploaderBinder != null) {
-            upload.removeAllUploadRestrictions();
+            upload.removeAllUploadRestrictions(); //only this object, upload DB stays untouched.
             uploaderBinder.retry(account, upload);            
         }  else {
             Log_OC.w(TAG, "uploaderBinder not set. Cannot remove " + upload.getOCFile());            

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

@@ -461,7 +461,7 @@ public class FileUploadService extends IntentService implements OnDatatransferPr
             UploadDbObject uploadDbObject = mPendingUploads.get(remotePath);
             uploadDbObject.setUploadStatus(UploadStatus.UPLOAD_LATER);
             uploadDbObject.setLastResult(null);
-            mDb.updateUpload(uploadDbObject);
+            mDb.updateUploadStatus(uploadDbObject);
 
             Log_OC.d(TAG, "Start uploading " + remotePath);
         } else {
@@ -500,7 +500,7 @@ public class FileUploadService extends IntentService implements OnDatatransferPr
                 // KEY_UPLOAD_TIMESTAMP - TODO use AlarmManager to wake up this service
                 break;
             case FILE_GONE:
-                mDb.updateUpload(uploadDbObject.getLocalPath(), UploadStatus.UPLOAD_FAILED_GIVE_UP,
+                mDb.updateUploadStatus(uploadDbObject.getLocalPath(), UploadStatus.UPLOAD_FAILED_GIVE_UP,
                         new RemoteOperationResult(ResultCode.FILE_NOT_FOUND));
                 it.remove();
                 break;
@@ -607,7 +607,7 @@ public class FileUploadService extends IntentService implements OnDatatransferPr
                 // storagePath inside upload is the temporary path. file
                 // contains the correct path used as db reference.
                 upload.getOCFile().setStoragePath(file.getStoragePath());
-                mDb.updateUpload(upload);
+                mDb.updateUploadStatus(upload);
             }
         }
         
@@ -1058,7 +1058,7 @@ public class FileUploadService extends IntentService implements OnDatatransferPr
      * Updates the persistent upload database that upload is in progress.
      */
     private void updateDatabaseUploadStart(UploadFileOperation upload) {
-        mDb.updateUpload(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_IN_PROGRESS, null);    
+        mDb.updateUploadStatus(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_IN_PROGRESS, null);    
     }
 
     /**
@@ -1152,16 +1152,16 @@ public class FileUploadService extends IntentService implements OnDatatransferPr
         // result: success or fail notification
         Log_OC.d(TAG, "updateDataseUploadResult uploadResult: " + uploadResult + " upload: " + upload);
         if (uploadResult.isCancelled()) {
-            mDb.updateUpload(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_CANCELLED, uploadResult);
+            mDb.updateUploadStatus(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_CANCELLED, uploadResult);
         } else {
 
             if (uploadResult.isSuccess()) {
-                mDb.updateUpload(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_SUCCEEDED, uploadResult);
+                mDb.updateUploadStatus(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_SUCCEEDED, uploadResult);
             } else {
                 if (shouldRetryFailedUpload(uploadResult)) {
-                    mDb.updateUpload(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_FAILED_RETRY, uploadResult);
+                    mDb.updateUploadStatus(upload.getOriginalStoragePath(), UploadStatus.UPLOAD_FAILED_RETRY, uploadResult);
                 } else {
-                    mDb.updateUpload(upload.getOriginalStoragePath(),
+                    mDb.updateUploadStatus(upload.getOriginalStoragePath(),
                             UploadDbHandler.UploadStatus.UPLOAD_FAILED_GIVE_UP, uploadResult);
                 }
             }

+ 6 - 0
src/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java

@@ -9,6 +9,7 @@ import android.app.Activity;
 import android.content.Context;
 import android.database.DataSetObserver;
 import android.graphics.Bitmap;
+import android.os.Environment;
 import android.text.format.DateUtils;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -173,6 +174,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                 if(uploadObject.getLastResult() != null){
                     status = "Last failure: "
                         + uploadObject.getLastResult().getLogMessage();
+                    String laterReason =FileUploadService.getUploadLaterReason(mActivity, uploadObject);
+                    if(laterReason != null) {
+                        //Upload is delayed, show reason.
+                        status += "\n" + laterReason;
+                    }
                 } else {
                     status = "Upload will be retried shortly.";
                 }