Browse Source

Checking Network Connection failed uploads

masensio 9 năm trước cách đây
mục cha
commit
b6f8e93504

+ 2 - 0
res/values/strings.xml

@@ -118,6 +118,8 @@
     <string name="uploader_upload_failed_ticker">Upload failed</string>
     <string name="uploader_upload_failed_content_single">Upload of %1$s could not be completed</string>
     <string name="uploader_upload_failed_credentials_error">Upload failed, you need to relogin</string>
+    <string name="uploads_view_upload_status_failed_connection_error">Connection error</string>
+    <string name="uploads_view_upload_status_failed_retry">Upload will be retried shortly</string>
     <string name="downloader_download_in_progress_ticker">Downloading &#8230;</string>
     <string name="downloader_download_in_progress_content">%1$d%% Downloading %2$s</string>
     <string name="downloader_download_succeeded_ticker">Download succeeded</string>

+ 0 - 1
src/com/owncloud/android/datamodel/OCFile.java

@@ -56,7 +56,6 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     private static final String TAG = OCFile.class.getSimpleName();
 
-
     private long mId;
     private long mParentId;
     private long mLength;

+ 73 - 1
src/com/owncloud/android/db/OCUpload.java

@@ -22,6 +22,8 @@ package com.owncloud.android.db;
 
 import android.accounts.Account;
 import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
 
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.OCFile;
@@ -38,7 +40,7 @@ import java.util.GregorianCalendar;
  * be stored persistently by {@link UploadsStorageManager}.
  * 
  */
-public class OCUpload {
+public class OCUpload implements Parcelable{
 
     /** Generated - should be refreshed every time the class changes!! */
 //    private static final long serialVersionUID = 2647551318657321611L;
@@ -336,4 +338,74 @@ public class OCUpload {
                 return false;
         }
     }
+
+
+    /****
+     * PARCELABLE METHODS
+     */
+    public static final Parcelable.Creator<OCUpload> CREATOR = new Parcelable.Creator<OCUpload>() {
+
+        @Override
+        public OCUpload createFromParcel(Parcel source) {
+            return new OCUpload(source);
+        }
+
+        @Override
+        public OCUpload[] newArray(int size) {
+            return new OCUpload[size];
+        }
+    };
+
+    /**
+     * Reconstruct from parcel
+     *
+     * @param source The source parcel
+     */
+    protected OCUpload(Parcel source) {
+        readFromParcel(source);
+    }
+
+    public void readFromParcel(Parcel source) {
+        mId = source.readLong();
+        mFile = source.readParcelable(OCFile.class.getClassLoader());
+        mLocalAction = source.readInt();
+        mForceOverwrite = source.readInt() == 0;
+        mIsCreateRemoteFolder = source.readInt() == 0;
+        mIsUseWifiOnly = source.readInt() == 0;
+        mIsWhileChargingOnly = source.readInt() == 0;
+        mUploadTimestamp = source.readLong();
+        mAccountName = source.readString();
+        try {
+            mUploadStatus = UploadStatus.valueOf(source.readString());
+        } catch (IllegalArgumentException x) {
+            mUploadStatus = UploadStatus.UPLOAD_LATER;
+        }
+        try {
+            mLastResult = UploadResult.valueOf(source.readString());
+        } catch (IllegalArgumentException x) {
+            mLastResult = UploadResult.UNKNOWN;
+        }
+    }
+
+
+    @Override
+    public int describeContents() {
+        return this.hashCode();
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeLong(mId);
+        dest.writeParcelable(mFile, flags);
+        dest.writeInt(mLocalAction);
+        //dest.writeLong(mUploadTime);
+        dest.writeInt(mForceOverwrite ? 1 : 0);
+        dest.writeInt(mIsCreateRemoteFolder ? 1 : 0);
+        dest.writeInt(mIsUseWifiOnly ? 1 : 0);
+        dest.writeInt(mIsWhileChargingOnly ? 1 : 0);
+        dest.writeLong(mUploadTimestamp);
+        dest.writeString(mAccountName);
+        dest.writeString(mUploadStatus.name());
+        dest.writeString(((mLastResult == null) ? "" : mLastResult.name()));
+    }
 }

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

@@ -504,19 +504,19 @@ public class FileOperationsHelper {
                 getString(R.string.wait_a_moment));
     }
 
-//    /**
-//     * Retry uploading a failed or cancelled upload with force.
-//     */
-//    public void retryUpload(OCUpload upload) {
-//        Account account = mFileActivity.getAccount();
-//        FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
-//        if (uploaderBinder != null) {
-//            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());
-//        }
-//    }
+    /**
+     * Retry uploading a failed or cancelled upload with force.
+     */
+    public void retryUpload(OCUpload upload) {
+        Account account = mFileActivity.getAccount();
+        FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
+        if (uploaderBinder != null) {
+            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());
+        }
+    }
     
     /**
      * Remove upload from upload list.

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

@@ -111,16 +111,21 @@ public class FileUploadService extends Service implements OnDatatransferProgress
     public static final String KEY_LOCAL_FILE = "LOCAL_FILE";
     public static final String KEY_REMOTE_FILE = "REMOTE_FILE";
     public static final String KEY_MIME_TYPE = "MIME_TYPE";
-    
+
+    /**
+     * Call this Service with only this Intent key if all pending uploads are to be retried.
+     */
+    private static final String KEY_RETRY = "KEY_RETRY";
 //    /**
-//     * Call this Service with only this Intent key if all pending uploads are to be retried.
+//     * Call this Service with KEY_RETRY and KEY_RETRY_REMOTE_PATH to retry
+//     * upload of file identified by KEY_RETRY_REMOTE_PATH.
 //     */
-//    private static final String KEY_RETRY = "KEY_RETRY";
+//    private static final String KEY_RETRY_REMOTE_PATH = "KEY_RETRY_REMOTE_PATH";
     /**
-     * Call this Service with KEY_RETRY and KEY_RETRY_REMOTE_PATH to retry
-     * download of file identified by KEY_RETRY_REMOTE_PATH.
+     * Call this Service with KEY_RETRY and KEY_RETRY_UPLOAD to retry
+     * upload of file identified by KEY_RETRY_UPLOAD.
      */
-    private static final String KEY_RETRY_REMOTE_PATH = "KEY_RETRY_REMOTE_PATH";    
+    private static final String KEY_RETRY_UPLOAD = "KEY_RETRY_UPLOAD";
     /**
      * {@link Account} to which file is to be uploaded.
      */
@@ -130,7 +135,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
      */
     public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE";
     /**
-     * Set to true if remote file is to be overwritten. Default action is to upload with different name. 
+     * Set to true if remote file is to be overwritten. Default action is to upload with different name.
      */
     public static final String KEY_FORCE_OVERWRITE = "KEY_FORCE_OVERWRITE";
     /**
@@ -149,7 +154,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
 //     * Set to future UNIX timestamp. Upload will not be performed before this timestamp.
 //     */
 //    public static final String KEY_UPLOAD_TIMESTAMP= "KEY_UPLOAD_TIMESTAMP";
-    
+
     public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR";
 
     //public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD";
@@ -204,7 +209,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
 //            return null;
 //        }
 //    }
-    
+
 //    public enum UploadQuantity {
 //        UPLOAD_SINGLE_FILE(0), UPLOAD_MULTIPLE_FILES(1);
 //        private final int value;
@@ -228,7 +233,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
     private FileDataStorageManager mStorageManager;
     //since there can be only one instance of an Android service, there also just one db connection.
     private UploadsStorageManager mUploadsStorageManager = null;
-    
+
     private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
     //private final AtomicBoolean mCancellationPossible = new AtomicBoolean(false);
 
@@ -244,7 +249,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
      * {@link UploadFileOperation} object of ongoing upload. Can be null. Note: There can only be one concurrent upload!
      */
     private UploadFileOperation mCurrentUpload = null;
-    
+
     private NotificationManager mNotificationManager;
     private NotificationCompat.Builder mNotificationBuilder;
     private int mLastPercent;
@@ -262,12 +267,12 @@ public class FileUploadService extends Service implements OnDatatransferProgress
 
     /**
      * Checks if an ownCloud server version should support chunked uploads.
-     * 
+     *
      * @param version OwnCloud version instance corresponding to an ownCloud
-     *            server.
+     *                server.
      * @return 'True' if the ownCloud server with version supports chunked
-     *         uploads.
-     *
+     * uploads.
+     * <p/>
      * TODO - move to OCClient
      */
     private static boolean chunkedUploadIsSupported(OwnCloudVersion version) {
@@ -299,7 +304,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
         //when this service starts there is no upload in progress. if db says so, app probably crashed before.
         mUploadsStorageManager.setAllCurrentToUploadLater();
 
-       // mUploadExecutor = Executors.newFixedThreadPool(1);
+        // mUploadExecutor = Executors.newFixedThreadPool(1);
 
 //        Log_OC.d(TAG, "FileUploadService.retry() called by onCreate()");
 //        FileUploadService.retry(getApplicationContext());
@@ -313,7 +318,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
      */
     @Override
     public void onDestroy() {
-        Log_OC.v(TAG, "Destroying service" );
+        Log_OC.v(TAG, "Destroying service");
         mBinder = null;
         mServiceHandler = null;
         mServiceLooper.quit();
@@ -344,7 +349,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
 
     /**
      * Entry point to add one or several files to the queue of uploads.
-     *
+     * <p/>
      * New uploads are added calling to startService(), resulting in a call to
      * this method. This ensures the service will keep on working although the
      * caller activity goes away.
@@ -353,166 +358,209 @@ public class FileUploadService extends Service implements OnDatatransferProgress
     public int onStartCommand(Intent intent, int flags, int startId) {
         Log_OC.d(TAG, "Starting command with id " + startId);
 
-        if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
-                || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
+        boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
+        AbstractList<String> requestedUploads = new Vector<String>();
+
+        if (!intent.hasExtra(KEY_ACCOUNT)) {
             Log_OC.e(TAG, "Not enough information provided in intent");
             return Service.START_NOT_STICKY;
-        }
-        int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
-        if (uploadType == -1) {
-            Log_OC.e(TAG, "Incorrect upload type provided");
-            return Service.START_NOT_STICKY;
-        }
-        Account account = intent.getParcelableExtra(KEY_ACCOUNT);
-        if (!AccountUtils.exists(account, getApplicationContext())) {
-            return Service.START_NOT_STICKY;
-        }
 
-        String[] localPaths = null, remotePaths = null, mimeTypes = null;
-        OCFile[] files = null;
-        if (uploadType == UPLOAD_SINGLE_FILE) {
+        } else {
+            Account account = intent.getParcelableExtra(KEY_ACCOUNT);
+            if (!AccountUtils.exists(account, getApplicationContext())) {
+                return Service.START_NOT_STICKY;
+            }
+            OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
+            boolean chunked = FileUploadService.chunkedUploadIsSupported(ocv);
 
-            if (intent.hasExtra(KEY_FILE)) {
-                files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };
+            if (!retry) {
+                if (!intent.hasExtra(KEY_UPLOAD_TYPE) || !(intent.hasExtra(KEY_LOCAL_FILE) ||
+                        intent.hasExtra(KEY_FILE))) {
+                    Log_OC.e(TAG, "Not enough information provided in intent");
+                    return Service.START_NOT_STICKY;
+                }
+                int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
+                if (uploadType == -1) {
+                    Log_OC.e(TAG, "Incorrect upload type provided");
+                    return Service.START_NOT_STICKY;
+                }
 
-            } else {
-                localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
-                remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
-                mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
-            }
+                String[] localPaths = null, remotePaths = null, mimeTypes = null;
+                OCFile[] files = null;
+                if (uploadType == UPLOAD_SINGLE_FILE) {
 
-        } else { // mUploadType == UPLOAD_MULTIPLE_FILES
+                    if (intent.hasExtra(KEY_FILE)) {
+                        files = new OCFile[]{intent.getParcelableExtra(KEY_FILE)};
 
-            if (intent.hasExtra(KEY_FILE)) {
-                files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO
-                // will
-                // this
-                // casting
-                // work
-                // fine?
+                    } else {
+                        localPaths = new String[]{intent.getStringExtra(KEY_LOCAL_FILE)};
+                        remotePaths = new String[]{intent.getStringExtra(KEY_REMOTE_FILE)};
+                        mimeTypes = new String[]{intent.getStringExtra(KEY_MIME_TYPE)};
+                    }
 
-            } else {
-                localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
-                remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
-                mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
-            }
-        }
+                } else { // mUploadType == UPLOAD_MULTIPLE_FILES
 
-        mStorageManager = new FileDataStorageManager(account, getContentResolver());
+                    if (intent.hasExtra(KEY_FILE)) {
+                        files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO
+                        // will
+                        // this
+                        // casting
+                        // work
+                        // fine?
 
-        boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
-     //   boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
-        int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
+                    } else {
+                        localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
+                        remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
+                        mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
+                    }
+                }
 
-        boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
-        boolean isUseWifiOnly = intent.getBooleanExtra(KEY_WIFI_ONLY, true);
-        boolean isWhileChargingOnly = intent.getBooleanExtra(KEY_WHILE_CHARGING_ONLY, false);
-        //long uploadTimestamp = intent.getLongExtra(KEY_UPLOAD_TIMESTAMP, -1);
+                mStorageManager = new FileDataStorageManager(account, getContentResolver());
 
+                boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
+                //   boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
+                int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
 
-        if (intent.hasExtra(KEY_FILE) && files == null) {
-            Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
-            return Service.START_NOT_STICKY;
+                boolean isCreateRemoteFolder = intent.getBooleanExtra(KEY_CREATE_REMOTE_FOLDER, false);
+                boolean isUseWifiOnly = intent.getBooleanExtra(KEY_WIFI_ONLY, true);
+                boolean isWhileChargingOnly = intent.getBooleanExtra(KEY_WHILE_CHARGING_ONLY, false);
+                //long uploadTimestamp = intent.getLongExtra(KEY_UPLOAD_TIMESTAMP, -1);
 
-        } else if (!intent.hasExtra(KEY_FILE)) {
-            if (localPaths == null) {
-                Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
-                return Service.START_NOT_STICKY;
-            }
-            if (remotePaths == null) {
-                Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
-                return Service.START_NOT_STICKY;
-            }
-            if (localPaths.length != remotePaths.length) {
-                Log_OC.e(TAG, "Different number of remote paths and local paths!");
-                return Service.START_NOT_STICKY;
-            }
 
-            files = new OCFile[localPaths.length];
-            for (int i = 0; i < localPaths.length; i++) {
-                files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i],
-                        ((mimeTypes != null) ? mimeTypes[i] : null));
-                if (files[i] == null) {
-                    Log_OC.e(TAG, "obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i]
-                            + " and localPaths[i]:" + localPaths[i]);
+                if (intent.hasExtra(KEY_FILE) && files == null) {
+                    Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
                     return Service.START_NOT_STICKY;
+
+                } else if (!intent.hasExtra(KEY_FILE)) {
+                    if (localPaths == null) {
+                        Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
+                        return Service.START_NOT_STICKY;
+                    }
+                    if (remotePaths == null) {
+                        Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
+                        return Service.START_NOT_STICKY;
+                    }
+                    if (localPaths.length != remotePaths.length) {
+                        Log_OC.e(TAG, "Different number of remote paths and local paths!");
+                        return Service.START_NOT_STICKY;
+                    }
+
+                    files = new OCFile[localPaths.length];
+                    for (int i = 0; i < localPaths.length; i++) {
+                        files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i],
+                                ((mimeTypes != null) ? mimeTypes[i] : null));
+                        if (files[i] == null) {
+                            Log_OC.e(TAG, "obtainNewOCFileToUpload() returned null for remotePaths[i]:" + remotePaths[i]
+                                    + " and localPaths[i]:" + localPaths[i]);
+                            return Service.START_NOT_STICKY;
+                        }
+
+                        mStorageManager.saveFile(files[i]);
+                        files[i] = mStorageManager.getFileByLocalPath(files[i].getStoragePath());
+                    }
                 }
+                // at this point variable "OCFile[] files" is loaded correctly.
 
-                mStorageManager.saveFile(files[i]);
-                files[i] = mStorageManager.getFileByLocalPath(files[i].getStoragePath());
-            }
-        }
-        // at this point variable "OCFile[] files" is loaded correctly.
+                String uploadKey = null;
+                UploadFileOperation newUpload = null;
+                try {
+                    for (int i = 0; i < files.length; i++) {
+                        newUpload = new UploadFileOperation(
+                                account,
+                                files[i],
+                                chunked,
+                                //isInstant,
+                                forceOverwrite,
+                                localAction, // Change for compilation
+                                getApplicationContext()
+                        );
+                        if (isCreateRemoteFolder) {
+                            newUpload.setRemoteFolderToBeCreated();
+                        }
+                        newUpload.addDatatransferProgressListener(this);
+                        newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
+                        Pair<String, String> putResult = mPendingUploads.putIfAbsent(
+                                account, files[i].getRemotePath(), newUpload
+                        );
+                        if (putResult != null) {
+                            uploadKey = putResult.first;
+                            requestedUploads.add(uploadKey);
+                            // Save upload in database
+                            OCUpload ocUpload = new OCUpload(files[i]);
+                            ocUpload.setAccountName(account.name);
+                            ocUpload.setForceOverwrite(forceOverwrite);
+                            ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
+                            ocUpload.setLocalAction(localAction);
+                            ocUpload.setUseWifiOnly(isUseWifiOnly);
+                            ocUpload.setWhileChargingOnly(isWhileChargingOnly);
+//                    ocUpload.setUploadTimestamp(uploadTimestamp);
+                            ocUpload.setUploadStatus(UploadStatus.UPLOAD_LATER);
 
-        OwnCloudVersion ocv = AccountUtils.getServerVersion(account);
+                            // storagePath inside upload is the temporary path. file
+                            // contains the correct path used as db reference.
+                            ocUpload.getOCFile().setStoragePath(localPaths[i]);
+                            mUploadsStorageManager.storeUpload(ocUpload);
+                        }   // else, file already in the queue of uploads; don't repeat the request
+                    }
 
-        boolean chunked = FileUploadService.chunkedUploadIsSupported(ocv);
-        AbstractList<String> requestedUploads = new Vector<String>();
-        String uploadKey = null;
-        UploadFileOperation newUpload = null;
-        try {
-            for (int i = 0; i < files.length; i++) {
-                newUpload = new UploadFileOperation(
+                } catch (IllegalArgumentException e) {
+                    Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
+                    return START_NOT_STICKY;
+
+                } catch (IllegalStateException e) {
+                    Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
+                    return START_NOT_STICKY;
+
+                } catch (Exception e) {
+                    Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
+                    return START_NOT_STICKY;
+
+                }
+            } else {
+                if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_RETRY_UPLOAD) ) {
+                    Log_OC.e(TAG, "Not enough information provided in intent: no KEY_RETRY_UPLOAD_KEY");
+                    return START_NOT_STICKY;
+                }
+                OCUpload upload = intent.getParcelableExtra(KEY_RETRY_UPLOAD);
+
+                UploadFileOperation newUpload = new UploadFileOperation(
                         account,
-                        files[i],
+                        upload.getOCFile(),
                         chunked,
-                        //isInstant,
-                        forceOverwrite,
-                        localAction, // Change for compilation
+                        upload.isForceOverwrite(),
+                        upload.getLocalAction(),
                         getApplicationContext()
                 );
-                if (isCreateRemoteFolder) {
+                if (upload.isCreateRemoteFolder()) {
                     newUpload.setRemoteFolderToBeCreated();
                 }
                 newUpload.addDatatransferProgressListener(this);
                 newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
+
                 Pair<String, String> putResult = mPendingUploads.putIfAbsent(
-                        account, files[i].getRemotePath(), newUpload
+                        account, upload.getOCFile().getRemotePath(), newUpload
                 );
                 if (putResult != null) {
-                    uploadKey = putResult.first;
+                    String uploadKey = putResult.first;
                     requestedUploads.add(uploadKey);
-                    // Save upload in database
-                    OCUpload ocUpload = new OCUpload(files[i]);
-                    ocUpload.setAccountName(account.name);
-                    ocUpload.setForceOverwrite(forceOverwrite);
-                    ocUpload.setCreateRemoteFolder(isCreateRemoteFolder);
-                    ocUpload.setLocalAction(localAction);
-                    ocUpload.setUseWifiOnly(isUseWifiOnly);
-                    ocUpload.setWhileChargingOnly(isWhileChargingOnly);
-//                    ocUpload.setUploadTimestamp(uploadTimestamp);
-                    ocUpload.setUploadStatus(UploadStatus.UPLOAD_LATER);
 
-                    // storagePath inside upload is the temporary path. file
-                    // contains the correct path used as db reference.
-                    ocUpload.getOCFile().setStoragePath(localPaths[i]);
-                    mUploadsStorageManager.storeUpload(ocUpload);
-                }   // else, file already in the queue of uploads; don't repeat the request
+                    // Update upload in database
+                    upload.setUploadStatus(UploadStatus.UPLOAD_LATER);
+                    mUploadsStorageManager.updateUpload(upload);
+                }
             }
 
-        } catch (IllegalArgumentException e) {
-            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
-            return START_NOT_STICKY;
-
-        } catch (IllegalStateException e) {
-            Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
-            return START_NOT_STICKY;
-
-        } catch (Exception e) {
-            Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
-            return START_NOT_STICKY;
-
-        }
-
-        if (requestedUploads.size() > 0) {
-            Message msg = mServiceHandler.obtainMessage();
-            msg.arg1 = startId;
-            msg.obj = requestedUploads;
-            mServiceHandler.sendMessage(msg);
+            if (requestedUploads.size() > 0) {
+                Message msg = mServiceHandler.obtainMessage();
+                msg.arg1 = startId;
+                msg.obj = requestedUploads;
+                mServiceHandler.sendMessage(msg);
+            }
+            return Service.START_NOT_STICKY;
         }
-        return Service.START_NOT_STICKY;
     }
 
+
     @Override
     public void onAccountsUpdated(Account[] accounts) {
         // Review current upload, and cancel it if its account doen't exist
@@ -640,16 +688,16 @@ public class FileUploadService extends Service implements OnDatatransferProgress
             }
         }
 
-//        // TODO: Review: Method from FileUploadService with some changes because the merge with FileUploader
-//        // TODO Complete operation to retry the upload
-//        /**
-//         * Puts upload in upload list and tell FileUploadService to upload items in list.
-//         */
-//        public void retry(Account account, OCUpload upload) {
-//            String uploadKey = buildRemoteName(upload);
-//            //mPendingUploads.put(uploadKey, upload);
-//            FileUploadService.retry(getApplicationContext(), uploadKey);
-//        }
+        // TODO: Review: Method from FileUploadService with some changes because the merge with FileUploader
+        // TODO Complete operation to retry the upload
+        /**
+         * Puts upload in upload list and tell FileUploadService to upload items in list.
+         */
+        public void retry(Account account, OCUpload upload) {
+            String uploadKey = buildRemoteName(account, upload.getOCFile());
+//            mPendingUploads.put(uploadKey, upload);
+            FileUploadService.retry(getApplicationContext(), account, upload);
+        }
 
         public void clearListeners() {
             mBoundListeners.clear();
@@ -823,8 +871,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
                 notifyUploadStart(mCurrentUpload);
 
                 RemoteOperationResult uploadResult = null, grantResult;
-
-
+                
                 try {
                     /// prepare client object to send the request to the ownCloud server
                     if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentUpload.getAccount())) {
@@ -1905,24 +1952,25 @@ public class FileUploadService extends Service implements OnDatatransferProgress
         return CanUploadFileNowStatus.NOW;        
     }
 
-//    /**
-//     * Call if all pending uploads are to be retried.
-//     */
+    /**
+     * Call if all pending uploads are to be retried.
+     */
 //    public static void retry(Context context) {
 //        retry(context, null);
 //    }
 
-//    /**
-//     * Call to retry upload identified by remotePath
-//     */
-//    private static void retry(Context context, String remotePath) {
-//        Log_OC.d(TAG, "FileUploadService.retry()");
-//        Intent i = new Intent(context, FileUploadService.class);
-//        i.putExtra(FileUploadService.KEY_RETRY, true);
-//        if(remotePath != null) {
-//            i.putExtra(FileUploadService.KEY_RETRY_REMOTE_PATH, remotePath);
-//        }
-//        context.startService(i);
-//    }
+    /**
+     * Call to retry upload identified by remotePath
+     */
+    private static void retry(Context context, Account account, OCUpload upload) {
+        Log_OC.d(TAG, "FileUploadService.retry()");
+        Intent i = new Intent(context, FileUploadService.class);
+        i.putExtra(FileUploadService.KEY_RETRY, true);
+        if(upload!= null) {
+            i.putExtra(FileUploadService.KEY_ACCOUNT, account);
+            i.putExtra(FileUploadService.KEY_RETRY_UPLOAD, upload);
+        }
+        context.startService(i);
+    }
 
 }

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

@@ -213,12 +213,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                     }
                     break;
                 case UPLOAD_FAILED_RETRY:
-//                    if(upload.getLastResult() != UploadResult.UNKNOWN){
-//                        status = "Last failure: "
-//                                + upload.getLastResult().toString();
-//                    } else {
-                        status = "Upload will be retried shortly.";
-//                    }
+                    if (upload.getLastResult() == UploadResult.NETWORK_CONNECTION) {
+                        status = mParentActivity.getString(R.string.uploads_view_upload_status_failed_connection_error);
+                    } else {
+                        status =  mParentActivity.getString(R.string.uploads_view_upload_status_failed_retry);;
+                    }
                     String laterReason = FileUploadService.getUploadLaterReason(mParentActivity, upload);
                     if(laterReason != null) {
                         //Upload failed once but is delayed now, show reason.
@@ -266,7 +265,8 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                 rightButton.setOnClickListener(new OnClickListener() {
                     @Override
                     public void onClick(View v) {
-                   //     mParentActivity.getFileOperationsHelper().retryUpload(upload);
+                        Log_OC.d(TAG, "Retry unpload CLICK");
+                        mParentActivity.getFileOperationsHelper().retryUpload(upload);
                     }
                 });
             } else if (upload.userCanCancelUpload()) {