Browse Source

Calls to the FileUploader service refactored and fixed

Juan Carlos González Cabrero 9 years ago
parent
commit
6e63e65f2d

+ 68 - 114
src/com/owncloud/android/files/services/FileUploader.java

@@ -37,6 +37,7 @@ import android.os.HandlerThread;
 import android.os.IBinder;
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Looper;
 import android.os.Message;
 import android.os.Message;
+import android.os.Parcelable;
 import android.os.Process;
 import android.os.Process;
 import android.support.v4.app.NotificationCompat;
 import android.support.v4.app.NotificationCompat;
 import android.util.Pair;
 import android.util.Pair;
@@ -81,16 +82,15 @@ import java.util.Vector;
 
 
 /**
 /**
  * Service for uploading files. Invoke using context.startService(...).
  * Service for uploading files. Invoke using context.startService(...).
- *
+ * <p/>
  * Files to be uploaded are stored persistently using {@link UploadsStorageManager}.
  * Files to be uploaded are stored persistently using {@link UploadsStorageManager}.
- *
+ * <p/>
  * On next invocation of {@link FileUploader} uploaded files which
  * On next invocation of {@link FileUploader} uploaded files which
  * previously failed will be uploaded again until either upload succeeded or a
  * previously failed will be uploaded again until either upload succeeded or a
  * fatal error occured.
  * fatal error occured.
- *
+ * <p/>
  * Every file passed to this service is uploaded. No filtering is performed.
  * Every file passed to this service is uploaded. No filtering is performed.
  * However, Intent keys (e.g., KEY_WIFI_ONLY) are obeyed.
  * However, Intent keys (e.g., KEY_WIFI_ONLY) are obeyed.
- *
  */
  */
 public class FileUploader extends Service
 public class FileUploader extends Service
         implements OnDatatransferProgressListener, OnAccountsUpdateListener {
         implements OnDatatransferProgressListener, OnAccountsUpdateListener {
@@ -264,7 +264,7 @@ public class FileUploader extends Service
     }
     }
 
 
     /**
     /**
-     * Call to upload a new file. Main method.
+     * Call to upload several new files
      */
      */
     public static void uploadNewFile(Context context, Account account, String[] localPaths, String[] remotePaths,
     public static void uploadNewFile(Context context, Account account, String[] localPaths, String[] remotePaths,
                                      Integer behaviour, String mimeType, Boolean createRemoteFolder, Boolean wifiOnly) {
                                      Integer behaviour, String mimeType, Boolean createRemoteFolder, Boolean wifiOnly) {
@@ -274,56 +274,16 @@ public class FileUploader extends Service
         intent.putExtra(FileUploader.KEY_ACCOUNT, account);
         intent.putExtra(FileUploader.KEY_ACCOUNT, account);
         intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths);
         intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths);
         intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
         intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
-
-        if (behaviour != null)
-            intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
-        if (mimeType != null)
-            intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeType);
-        if (createRemoteFolder != null)
-            intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder);
-        if (wifiOnly != null)
-            intent.putExtra(FileUploader.KEY_WIFI_ONLY, wifiOnly);
+        intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
+        intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeType);
+        intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder);
+        intent.putExtra(FileUploader.KEY_WIFI_ONLY, wifiOnly);
 
 
         context.startService(intent);
         context.startService(intent);
     }
     }
 
 
     /**
     /**
-     * Call to upload multiple new files from the FileDisplayActivity
-     */
-    public static void uploadNewFile(Context context, Account account, String[] localPaths, String[] remotePaths, int
-            behaviour) {
-
-        uploadNewFile(context, account, localPaths, remotePaths, behaviour, null, null, null);
-    }
-
-    /**
-     * Call to upload a new single file from the FileDisplayActivity
-     */
-    public static void uploadNewFile(Context context, String localPath, String remotePath, int resultCode, String
-            mimeType) {
-
-        uploadNewFile(context, null, new String[]{localPath}, new String[]{remotePath}, resultCode, mimeType, null,
-                null);
-    }
-
-    /**
-     * Call to upload multiple new files from external applications
-     */
-    public static void uploadNewFile(Context context, Account account, String[] localPaths, String[] remotePaths) {
-
-        uploadNewFile(context, account, localPaths, remotePaths, null, null, null, null);
-    }
-
-    /**
-     * Call to upload a new single file from external applications
-     */
-    public static void uploadNewFile(Context context, Account account, String localPath, String remotePath) {
-
-        uploadNewFile(context, account, new String[]{localPath}, new String[]{remotePath}, null, null, null, null);
-    }
-
-    /**
-     * Call to upload a new single file from the Instant Upload Broadcast Receiver
+     * Call to upload a new single file
      */
      */
     public static void uploadNewFile(Context context, Account account, String localPath, String remotePath, int
     public static void uploadNewFile(Context context, Account account, String localPath, String remotePath, int
             behaviour, String mimeType, boolean createRemoteFile, boolean wifiOnly) {
             behaviour, String mimeType, boolean createRemoteFile, boolean wifiOnly) {
@@ -333,7 +293,7 @@ public class FileUploader extends Service
     }
     }
 
 
     /**
     /**
-     * Call to update a file already uploaded from the ConflictsResolveActivity
+     * Call to update multiple files already uploaded
      */
      */
     public static void uploadUpdate(Context context, Account account, OCFile[] existingFiles, Integer behaviour,
     public static void uploadUpdate(Context context, Account account, OCFile[] existingFiles, Integer behaviour,
                                     Boolean forceOverwrite) {
                                     Boolean forceOverwrite) {
@@ -349,7 +309,7 @@ public class FileUploader extends Service
     }
     }
 
 
     /**
     /**
-     * Call to update a file already uploaded from the ConflictsResolveActivity
+     * Call to update a dingle file already uploaded
      */
      */
     public static void uploadUpdate(Context context, Account account, OCFile existingFile, Integer behaviour, Boolean
     public static void uploadUpdate(Context context, Account account, OCFile existingFile, Integer behaviour, Boolean
             forceOverwrite) {
             forceOverwrite) {
@@ -357,22 +317,14 @@ public class FileUploader extends Service
         uploadUpdate(context, account, new OCFile[]{existingFile}, behaviour, forceOverwrite);
         uploadUpdate(context, account, new OCFile[]{existingFile}, behaviour, forceOverwrite);
     }
     }
 
 
-    /**
-     * Call to update a file already uploaded from the Synchronize File Operation
-     */
-    public static void uploadUpdate(Context context, Account account, OCFile existingFile, Boolean forceOverwrite) {
-
-        uploadUpdate(context, account, new OCFile[]{existingFile}, null, forceOverwrite);
-    }
-
     /**
     /**
      * Checks if an ownCloud server version should support chunked uploads.
      * Checks if an ownCloud server version should support chunked uploads.
      *
      *
      * @param version OwnCloud version instance corresponding to an ownCloud
      * @param version OwnCloud version instance corresponding to an ownCloud
-     *            server.
+     *                server.
      * @return 'True' if the ownCloud server with version supports chunked
      * @return 'True' if the ownCloud server with version supports chunked
-     *         uploads.
-     *
+     * uploads.
+     * <p/>
      * TODO - move to OwnCloudVersion
      * TODO - move to OwnCloudVersion
      */
      */
     private static boolean chunkedUploadIsSupported(OwnCloudVersion version) {
     private static boolean chunkedUploadIsSupported(OwnCloudVersion version) {
@@ -433,7 +385,7 @@ public class FileUploader extends Service
 
 
     /**
     /**
      * Entry point to add one or several files to the queue of uploads.
      * 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
      * New uploads are added calling to startService(), resulting in a call to
      * this method. This ensures the service will keep on working although the
      * this method. This ensures the service will keep on working although the
      * caller activity goes away.
      * caller activity goes away.
@@ -468,7 +420,9 @@ public class FileUploader extends Service
             OCFile[] files = null;
             OCFile[] files = null;
 
 
             if (intent.hasExtra(KEY_FILE)) {
             if (intent.hasExtra(KEY_FILE)) {
-                files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE);
+                Parcelable[] files_temp = intent.getParcelableArrayExtra(KEY_FILE);
+                files = new OCFile[files_temp.length];
+                System.arraycopy(files_temp, 0, files, 0, files_temp.length);
                 // TODO : test multiple upload, working find
                 // TODO : test multiple upload, working find
 
 
             } else {
             } else {
@@ -618,7 +572,7 @@ public class FileUploader extends Service
                     upload.getRemotePath(),
                     upload.getRemotePath(),
                     newUpload,
                     newUpload,
                     String.valueOf(upload.getUploadId()
                     String.valueOf(upload.getUploadId()
-            ));
+                    ));
             if (putResult != null) {
             if (putResult != null) {
                 String uploadKey = putResult.first;
                 String uploadKey = putResult.first;
                 requestedUploads.add(uploadKey);
                 requestedUploads.add(uploadKey);
@@ -642,7 +596,7 @@ public class FileUploader extends Service
     /**
     /**
      * Provides a binder object that clients can use to perform operations on
      * Provides a binder object that clients can use to perform operations on
      * the queue of uploads, excepting the addition of new files.
      * the queue of uploads, excepting the addition of new files.
-     *
+     * <p/>
      * Implemented to perform cancellation, pause and resume of existing
      * Implemented to perform cancellation, pause and resume of existing
      * uploads.
      * uploads.
      */
      */
@@ -673,7 +627,7 @@ public class FileUploader extends Service
     /**
     /**
      * Binder to let client components to perform operations on the queue of
      * Binder to let client components to perform operations on the queue of
      * uploads.
      * uploads.
-     *
+     * <p/>
      * It provides by itself the available operations.
      * It provides by itself the available operations.
      */
      */
     public class FileUploaderBinder extends Binder implements OnDatatransferProgressListener {
     public class FileUploaderBinder extends Binder implements OnDatatransferProgressListener {
@@ -689,8 +643,8 @@ public class FileUploader extends Service
         /**
         /**
          * Cancels a pending or current upload of a remote file.
          * Cancels a pending or current upload of a remote file.
          *
          *
-         * @param account   ownCloud account where the remote file will be stored.
-         * @param file      A file in the queue of pending uploads
+         * @param account ownCloud account where the remote file will be stored.
+         * @param file    A file in the queue of pending uploads
          */
          */
         public void cancel(Account account, OCFile file) {
         public void cancel(Account account, OCFile file) {
             cancel(account.name, file.getRemotePath(), file.getStoragePath());
             cancel(account.name, file.getRemotePath(), file.getStoragePath());
@@ -699,7 +653,7 @@ public class FileUploader extends Service
         /**
         /**
          * Cancels a pending or current upload that was persisted.
          * Cancels a pending or current upload that was persisted.
          *
          *
-         * @param storedUpload    Upload operation persisted
+         * @param storedUpload Upload operation persisted
          */
          */
         public void cancel(OCUpload storedUpload) {
         public void cancel(OCUpload storedUpload) {
             cancel(storedUpload.getAccountName(), storedUpload.getRemotePath(), storedUpload.getLocalPath());
             cancel(storedUpload.getAccountName(), storedUpload.getRemotePath(), storedUpload.getLocalPath());
@@ -708,9 +662,9 @@ public class FileUploader extends Service
         /**
         /**
          * Cancels a pending or current upload of a remote file.
          * Cancels a pending or current upload of a remote file.
          *
          *
-         * @param accountName   Local name of an ownCloud account where the remote file will be stored.
-         * @param remotePath    Remote target of the upload
-         * @param localPath     Absolute local path to the source file
+         * @param accountName Local name of an ownCloud account where the remote file will be stored.
+         * @param remotePath  Remote target of the upload
+         * @param localPath   Absolute local path to the source file
          */
          */
         private void cancel(String accountName, String remotePath, String localPath) {
         private void cancel(String accountName, String remotePath, String localPath) {
             Pair<UploadFileOperation, String> removeResult =
             Pair<UploadFileOperation, String> removeResult =
@@ -719,7 +673,7 @@ public class FileUploader extends Service
             if (upload == null &&
             if (upload == null &&
                     mCurrentUpload != null && mCurrentAccount != null &&
                     mCurrentUpload != null && mCurrentAccount != null &&
                     mCurrentUpload.getRemotePath().startsWith(remotePath) &&
                     mCurrentUpload.getRemotePath().startsWith(remotePath) &&
-                    accountName.equals(mCurrentAccount.name) ) {
+                    accountName.equals(mCurrentAccount.name)) {
 
 
                 upload = mCurrentUpload;
                 upload = mCurrentUpload;
             }
             }
@@ -731,7 +685,7 @@ public class FileUploader extends Service
                     // to be run by FileUploader#uploadFile
                     // to be run by FileUploader#uploadFile
                     OCUpload ocUpload =
                     OCUpload ocUpload =
                             mUploadsStorageManager.getUploadByLocalPath(localPath)[0];
                             mUploadsStorageManager.getUploadByLocalPath(localPath)[0];
-                                // TODO bad idea, should search for account + remoteName, or uploadId
+                    // TODO bad idea, should search for account + remoteName, or uploadId
                     ocUpload.setUploadStatus(UploadStatus.UPLOAD_CANCELLED);
                     ocUpload.setUploadStatus(UploadStatus.UPLOAD_CANCELLED);
                     ocUpload.setLastResult(UploadResult.CANCELLED);
                     ocUpload.setLastResult(UploadResult.CANCELLED);
                     mUploadsStorageManager.updateUploadStatus(ocUpload);
                     mUploadsStorageManager.updateUploadStatus(ocUpload);
@@ -742,7 +696,7 @@ public class FileUploader extends Service
         /**
         /**
          * Cancels all the uploads for an account
          * Cancels all the uploads for an account
          *
          *
-         * @param account   ownCloud account.
+         * @param account ownCloud account.
          */
          */
         public void cancel(Account account) {
         public void cancel(Account account) {
             Log_OC.d(TAG, "Account= " + account.name);
             Log_OC.d(TAG, "Account= " + account.name);
@@ -798,16 +752,16 @@ public class FileUploader extends Service
         /**
         /**
          * Returns True when the file described by 'file' is being uploaded to
          * Returns True when the file described by 'file' is being uploaded to
          * the ownCloud account 'account' or waiting for it
          * the ownCloud account 'account' or waiting for it
-         *
+         * <p/>
          * If 'file' is a directory, returns 'true' if some of its descendant files
          * If 'file' is a directory, returns 'true' if some of its descendant files
          * is uploading or waiting to upload.
          * is uploading or waiting to upload.
-         *
+         * <p/>
          * Warning: If remote file exists and !forceOverwrite the original file
          * Warning: If remote file exists and !forceOverwrite the original file
          * is being returned here. That is, it seems as if the original file is
          * is being returned here. That is, it seems as if the original file is
          * being updated when actually a new file is being uploaded.
          * being updated when actually a new file is being uploaded.
          *
          *
          * @param account Owncloud account where the remote file will be stored.
          * @param account Owncloud account where the remote file will be stored.
-         * @param file A file that could be in the queue of pending uploads
+         * @param file    A file that could be in the queue of pending uploads
          */
          */
         public boolean isUploading(Account account, OCFile file) {
         public boolean isUploading(Account account, OCFile file) {
             if (account == null || file == null)
             if (account == null || file == null)
@@ -819,11 +773,11 @@ public class FileUploader extends Service
         /**
         /**
          * Adds a listener interested in the progress of the upload for a concrete file.
          * Adds a listener interested in the progress of the upload for a concrete file.
          *
          *
-         * @param listener      Object to notify about progress of transfer.    
-         * @param account       ownCloud account holding the file of interest.
-         * @param file          {@link OCFile} of interest for listener.
+         * @param listener Object to notify about progress of transfer.
+         * @param account  ownCloud account holding the file of interest.
+         * @param file     {@link OCFile} of interest for listener.
          */
          */
-        public void addDatatransferProgressListener (
+        public void addDatatransferProgressListener(
                 OnDatatransferProgressListener listener,
                 OnDatatransferProgressListener listener,
                 Account account,
                 Account account,
                 OCFile file
                 OCFile file
@@ -837,11 +791,11 @@ public class FileUploader extends Service
         /**
         /**
          * Adds a listener interested in the progress of the upload for a concrete file.
          * Adds a listener interested in the progress of the upload for a concrete file.
          *
          *
-         * @param listener      Object to notify about progress of transfer.
-         * @param account       ownCloud account holding the file of interest.
-         * @param ocUpload      {@link OCUpload} of interest for listener.
+         * @param listener Object to notify about progress of transfer.
+         * @param account  ownCloud account holding the file of interest.
+         * @param ocUpload {@link OCUpload} of interest for listener.
          */
          */
-        public void addDatatransferProgressListener (
+        public void addDatatransferProgressListener(
                 OnDatatransferProgressListener listener,
                 OnDatatransferProgressListener listener,
                 Account account,
                 Account account,
                 OCUpload ocUpload
                 OCUpload ocUpload
@@ -855,11 +809,11 @@ public class FileUploader extends Service
         /**
         /**
          * Removes a listener interested in the progress of the upload for a concrete file.
          * Removes a listener interested in the progress of the upload for a concrete file.
          *
          *
-         * @param listener      Object to notify about progress of transfer.    
-         * @param account       ownCloud account holding the file of interest.
-         * @param file          {@link OCFile} of interest for listener.
+         * @param listener Object to notify about progress of transfer.
+         * @param account  ownCloud account holding the file of interest.
+         * @param file     {@link OCFile} of interest for listener.
          */
          */
-        public void removeDatatransferProgressListener (
+        public void removeDatatransferProgressListener(
                 OnDatatransferProgressListener listener,
                 OnDatatransferProgressListener listener,
                 Account account,
                 Account account,
                 OCFile file
                 OCFile file
@@ -875,11 +829,11 @@ public class FileUploader extends Service
         /**
         /**
          * Removes a listener interested in the progress of the upload for a concrete file.
          * Removes a listener interested in the progress of the upload for a concrete file.
          *
          *
-         * @param listener      Object to notify about progress of transfer.
-         * @param account       ownCloud account holding the file of interest.
-         * @param ocUpload      Stored upload of interest
+         * @param listener Object to notify about progress of transfer.
+         * @param account  ownCloud account holding the file of interest.
+         * @param ocUpload Stored upload of interest
          */
          */
-        public void removeDatatransferProgressListener (
+        public void removeDatatransferProgressListener(
                 OnDatatransferProgressListener listener,
                 OnDatatransferProgressListener listener,
                 Account account,
                 Account account,
                 OCUpload ocUpload
                 OCUpload ocUpload
@@ -906,13 +860,13 @@ public class FileUploader extends Service
 
 
         /**
         /**
          * Builds a key for the map of listeners.
          * Builds a key for the map of listeners.
-         *
+         * <p/>
          * TODO use method in IndexedForest, or refactor both to a common place
          * TODO use method in IndexedForest, or refactor both to a common place
          * add to local database) to better policy (add to local database, then upload)
          * add to local database) to better policy (add to local database, then upload)
          *
          *
-         * @param accountName   Local name of the ownCloud account where the file to upload belongs.
-         * @param remotePath    Remote path to upload the file to.
-         * @return              Key
+         * @param accountName Local name of the ownCloud account where the file to upload belongs.
+         * @param remotePath  Remote path to upload the file to.
+         * @return Key
          */
          */
         private String buildRemoteName(String accountName, String remotePath) {
         private String buildRemoteName(String accountName, String remotePath) {
             return accountName + remotePath;
             return accountName + remotePath;
@@ -931,7 +885,7 @@ public class FileUploader extends Service
     /**
     /**
      * Upload worker. Performs the pending uploads in the order they were
      * Upload worker. Performs the pending uploads in the order they were
      * requested.
      * requested.
-     *
+     * <p/>
      * Created with the Looper of a new thread, started in
      * Created with the Looper of a new thread, started in
      * {@link FileUploader#onCreate()}.
      * {@link FileUploader#onCreate()}.
      */
      */
@@ -1062,13 +1016,13 @@ public class FileUploader extends Service
     /**
     /**
      * Checks the existence of the folder where the current file will be uploaded both
      * Checks the existence of the folder where the current file will be uploaded both
      * in the remote server and in the local database.
      * in the remote server and in the local database.
-     *
+     * <p/>
      * If the upload is set to enforce the creation of the folder, the method tries to
      * If the upload is set to enforce the creation of the folder, the method tries to
      * create it both remote and locally.
      * create it both remote and locally.
      *
      *
-     *  @param  pathToGrant     Full remote path whose existence will be granted.
-     *  @return An {@link OCFile} instance corresponding to the folder where the file
-     *  will be uploaded.
+     * @param pathToGrant Full remote path whose existence will be granted.
+     * @return An {@link OCFile} instance corresponding to the folder where the file
+     * will be uploaded.
      */
      */
     private RemoteOperationResult grantFolderExistence(String pathToGrant) {
     private RemoteOperationResult grantFolderExistence(String pathToGrant) {
         RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, this, false);
         RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, this, false);
@@ -1114,11 +1068,11 @@ public class FileUploader extends Service
 
 
     /**
     /**
      * Saves a OC File after a successful upload.
      * Saves a OC File after a successful upload.
-     *
+     * <p/>
      * A PROPFIND is necessary to keep the props in the local database
      * A PROPFIND is necessary to keep the props in the local database
      * synchronized with the server, specially the modification time and Etag
      * synchronized with the server, specially the modification time and Etag
      * (where available)
      * (where available)
-     *
+     * <p/>
      * TODO move into UploadFileOperation
      * TODO move into UploadFileOperation
      */
      */
     private void saveUploadedFile() {
     private void saveUploadedFile() {
@@ -1236,8 +1190,8 @@ public class FileUploader extends Service
     /**
     /**
      * Updates the status notification with the result of an upload operation.
      * Updates the status notification with the result of an upload operation.
      *
      *
-     * @param uploadResult  Result of the upload operation.
-     * @param upload        Finished upload operation
+     * @param uploadResult Result of the upload operation.
+     * @param upload       Finished upload operation
      */
      */
     private void notifyUploadResult(UploadFileOperation upload,
     private void notifyUploadResult(UploadFileOperation upload,
                                     RemoteOperationResult uploadResult) {
                                     RemoteOperationResult uploadResult) {
@@ -1357,7 +1311,7 @@ public class FileUploader extends Service
      * Sends a broadcast in order to the interested activities can update their
      * Sends a broadcast in order to the interested activities can update their
      * view
      * view
      *
      *
-     * @param upload                    Finished upload operation
+     * @param upload Finished upload operation
      */
      */
     private void sendBroadcastUploadStarted(
     private void sendBroadcastUploadStarted(
             UploadFileOperation upload) {
             UploadFileOperation upload) {
@@ -1374,9 +1328,9 @@ public class FileUploader extends Service
      * Sends a broadcast in order to the interested activities can update their
      * Sends a broadcast in order to the interested activities can update their
      * view
      * view
      *
      *
-     * @param upload                    Finished upload operation
-     * @param uploadResult              Result of the upload operation
-     * @param unlinkedFromRemotePath    Path in the uploads tree where the upload was unlinked from
+     * @param upload                 Finished upload operation
+     * @param uploadResult           Result of the upload operation
+     * @param unlinkedFromRemotePath Path in the uploads tree where the upload was unlinked from
      */
      */
     private void sendBroadcastUploadFinished(
     private void sendBroadcastUploadFinished(
             UploadFileOperation upload,
             UploadFileOperation upload,
@@ -1405,7 +1359,7 @@ public class FileUploader extends Service
     /**
     /**
      * Remove uploads of an account
      * Remove uploads of an account
      *
      *
-     * @param account       Downloads account to remove
+     * @param account Downloads account to remove
      */
      */
     private void cancelUploadsForAccount(Account account) {
     private void cancelUploadsForAccount(Account account) {
         // Cancel pending uploads
         // Cancel pending uploads

+ 34 - 34
src/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -56,8 +56,8 @@ public class SynchronizeFileOperation extends SyncOperation {
     private boolean mTransferWasRequested = false;
     private boolean mTransferWasRequested = false;
 
 
     /**
     /**
-     * When 'false', uploads to the server are not done; only downloads or conflict detection.  
-     * This is a temporal field. 
+     * When 'false', uploads to the server are not done; only downloads or conflict detection.
+     * This is a temporal field.
      * TODO Remove when 'folder synchronization' replaces 'folder download'.
      * TODO Remove when 'folder synchronization' replaces 'folder download'.
      */
      */
     private boolean mAllowUploads;
     private boolean mAllowUploads;
@@ -65,17 +65,17 @@ public class SynchronizeFileOperation extends SyncOperation {
 
 
     /**
     /**
      * Constructor for "full synchronization mode".
      * Constructor for "full synchronization mode".
-     *
+     * <p/>
      * Uses remotePath to retrieve all the data both in local cache and in the remote OC server
      * Uses remotePath to retrieve all the data both in local cache and in the remote OC server
      * when the operation is executed, instead of reusing {@link OCFile} instances.
      * when the operation is executed, instead of reusing {@link OCFile} instances.
-     *
+     * <p/>
      * Useful for direct synchronization of a single file.
      * Useful for direct synchronization of a single file.
      *
      *
      * @param
      * @param
-     * @param account               ownCloud account holding the file.
-     * @param syncFileContents      When 'true', transference of data will be started by the 
-     *                              operation if needed and no conflict is detected.
-     * @param context               Android context; needed to start transfers.
+     * @param account          ownCloud account holding the file.
+     * @param syncFileContents When 'true', transference of data will be started by the
+     *                         operation if needed and no conflict is detected.
+     * @param context          Android context; needed to start transfers.
      */
      */
     public SynchronizeFileOperation(
     public SynchronizeFileOperation(
             String remotePath,
             String remotePath,
@@ -96,21 +96,21 @@ public class SynchronizeFileOperation extends SyncOperation {
     /**
     /**
      * Constructor allowing to reuse {@link OCFile} instances just queried from local cache or
      * Constructor allowing to reuse {@link OCFile} instances just queried from local cache or
      * from remote OC server.
      * from remote OC server.
-     *
+     * <p/>
      * Useful to include this operation as part of the synchronization of a folder
      * Useful to include this operation as part of the synchronization of a folder
      * (or a full account), avoiding the repetition of fetch operations (both in local database
      * (or a full account), avoiding the repetition of fetch operations (both in local database
      * or remote server).
      * or remote server).
-     *
+     * <p/>
      * At least one of localFile or serverFile MUST NOT BE NULL. If you don't have none of them,
      * At least one of localFile or serverFile MUST NOT BE NULL. If you don't have none of them,
      * use the other constructor.
      * use the other constructor.
      *
      *
-     * @param localFile             Data of file (just) retrieved from local cache/database.
-     * @param serverFile            Data of file (just) retrieved from a remote server. If null,
-     *                              will be retrieved from network by the operation when executed.
-     * @param account               ownCloud account holding the file.
-     * @param syncFileContents      When 'true', transference of data will be started by the 
-     *                              operation if needed and no conflict is detected.
-     * @param context               Android context; needed to start transfers.
+     * @param localFile        Data of file (just) retrieved from local cache/database.
+     * @param serverFile       Data of file (just) retrieved from a remote server. If null,
+     *                         will be retrieved from network by the operation when executed.
+     * @param account          ownCloud account holding the file.
+     * @param syncFileContents When 'true', transference of data will be started by the
+     *                         operation if needed and no conflict is detected.
+     * @param context          Android context; needed to start transfers.
      */
      */
     public SynchronizeFileOperation(
     public SynchronizeFileOperation(
             OCFile localFile,
             OCFile localFile,
@@ -141,26 +141,26 @@ public class SynchronizeFileOperation extends SyncOperation {
 
 
     /**
     /**
      * Temporal constructor.
      * Temporal constructor.
-     *
+     * <p/>
      * Extends the previous one to allow constrained synchronizations where uploads are never
      * Extends the previous one to allow constrained synchronizations where uploads are never
      * performed - only downloads or conflict detection.
      * performed - only downloads or conflict detection.
-     *
+     * <p/>
      * Do not use unless you are involved in 'folder synchronization' or 'folder download' work
      * Do not use unless you are involved in 'folder synchronization' or 'folder download' work
      * in progress.
      * in progress.
-     *
+     * <p/>
      * TODO Remove when 'folder synchronization' replaces 'folder download'.
      * TODO Remove when 'folder synchronization' replaces 'folder download'.
      *
      *
-     * @param localFile             Data of file (just) retrieved from local cache/database.
-     *                              MUSTN't be null.
-     * @param serverFile            Data of file (just) retrieved from a remote server.
-     *                              If null, will be retrieved from network by the operation
-     *                              when executed.
-     * @param account               ownCloud account holding the file.
-     * @param syncFileContents      When 'true', transference of data will be started by the 
-     *                              operation if needed and no conflict is detected.
-     * @param allowUploads          When 'false', uploads to the server are not done;
-     *                              only downloads or conflict detection.
-     * @param context               Android context; needed to start transfers.
+     * @param localFile        Data of file (just) retrieved from local cache/database.
+     *                         MUSTN't be null.
+     * @param serverFile       Data of file (just) retrieved from a remote server.
+     *                         If null, will be retrieved from network by the operation
+     *                         when executed.
+     * @param account          ownCloud account holding the file.
+     * @param syncFileContents When 'true', transference of data will be started by the
+     *                         operation if needed and no conflict is detected.
+     * @param allowUploads     When 'false', uploads to the server are not done;
+     *                         only downloads or conflict detection.
+     * @param context          Android context; needed to start transfers.
      */
      */
     public SynchronizeFileOperation(
     public SynchronizeFileOperation(
             OCFile localFile,
             OCFile localFile,
@@ -281,11 +281,11 @@ public class SynchronizeFileOperation extends SyncOperation {
     /**
     /**
      * Requests for an upload to the FileUploader service
      * Requests for an upload to the FileUploader service
      *
      *
-     * @param file     OCFile object representing the file to upload
+     * @param file OCFile object representing the file to upload
      */
      */
     private void requestForUpload(OCFile file) {
     private void requestForUpload(OCFile file) {
 
 
-        FileUploader.uploadUpdate(mContext, mAccount, file, true);
+        FileUploader.uploadUpdate(mContext, mAccount, file, FileUploader.LOCAL_BEHAVIOUR_MOVE, true);
 
 
         mTransferWasRequested = true;
         mTransferWasRequested = true;
     }
     }
@@ -294,7 +294,7 @@ public class SynchronizeFileOperation extends SyncOperation {
     /**
     /**
      * Requests for a download to the FileDownloader service
      * Requests for a download to the FileDownloader service
      *
      *
-     * @param file     OCFile object representing the file to download
+     * @param file OCFile object representing the file to download
      */
      */
     private void requestForDownload(OCFile file) {
     private void requestForDownload(OCFile file) {
         Intent i = new Intent(mContext, FileDownloader.class);
         Intent i = new Intent(mContext, FileDownloader.class);

+ 36 - 33
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -232,7 +232,7 @@ public class FileDisplayActivity extends HookActivity implements
     }
     }
 
 
     /**
     /**
-     *  Called when the ownCloud {@link Account} associated to the Activity was just updated.
+     * Called when the ownCloud {@link Account} associated to the Activity was just updated.
      */
      */
     @Override
     @Override
     protected void onAccountSet(boolean stateWasRecovered) {
     protected void onAccountSet(boolean stateWasRecovered) {
@@ -350,10 +350,10 @@ public class FileDisplayActivity extends HookActivity implements
     /**
     /**
      * Replaces the second fragment managed by the activity with the received as
      * Replaces the second fragment managed by the activity with the received as
      * a parameter.
      * a parameter.
-     *
+     * <p/>
      * Assumes never will be more than two fragments managed at the same time.
      * Assumes never will be more than two fragments managed at the same time.
      *
      *
-     * @param fragment      New second Fragment to set.
+     * @param fragment New second Fragment to set.
      */
      */
     private void setSecondFragment(Fragment fragment) {
     private void setSecondFragment(Fragment fragment) {
         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
@@ -611,7 +611,6 @@ public class FileDisplayActivity extends HookActivity implements
 
 
     /**
     /**
      * Called, when the user selected something for uploading
      * Called, when the user selected something for uploading
-     *
      */
      */
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
     @Override
     @Override
@@ -680,7 +679,9 @@ public class FileDisplayActivity extends HookActivity implements
                 remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
                 remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
             }
             }
 
 
-            FileUploader.uploadNewFile(this, getAccount(), filePaths, remotePaths, resultCode);
+            int behaviour = (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE) ? FileUploader
+                    .LOCAL_BEHAVIOUR_MOVE : FileUploader.LOCAL_BEHAVIOUR_COPY;
+            FileUploader.uploadNewFile(this, getAccount(), filePaths, remotePaths, behaviour, null, false, false);
 
 
         } else {
         } else {
             Log_OC.d(TAG, "User clicked on 'Update' with no selection");
             Log_OC.d(TAG, "User clicked on 'Update' with no selection");
@@ -753,15 +754,17 @@ public class FileDisplayActivity extends HookActivity implements
             remotePath += new File(filePath).getName();
             remotePath += new File(filePath).getName();
         }
         }
 
 
-        FileUploader.uploadNewFile(this, filePath, remotePath, resultCode, mimeType);
+        int behaviour = (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE) ? FileUploader.LOCAL_BEHAVIOUR_MOVE :
+                FileUploader.LOCAL_BEHAVIOUR_COPY;
+        FileUploader.uploadNewFile(this, getAccount(), filePath, remotePath, behaviour, mimeType, false, false);
 
 
     }
     }
 
 
     /**
     /**
      * Request the operation for moving the file/folder from one path to another
      * Request the operation for moving the file/folder from one path to another
      *
      *
-     * @param data              Intent received
-     * @param resultCode        Result code received
+     * @param data       Intent received
+     * @param resultCode Result code received
      */
      */
     private void requestMoveOperation(Intent data, int resultCode) {
     private void requestMoveOperation(Intent data, int resultCode) {
         OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
         OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
@@ -1102,7 +1105,7 @@ public class FileDisplayActivity extends HookActivity implements
 
 
     /**
     /**
      * Class waiting for broadcast events from the {@link FileDownloader} service.
      * Class waiting for broadcast events from the {@link FileDownloader} service.
-     *
+     * <p/>
      * Updates the UI when a download is started or finished, provided that it is relevant for the
      * Updates the UI when a download is started or finished, provided that it is relevant for the
      * current folder.
      * current folder.
      */
      */
@@ -1199,7 +1202,7 @@ public class FileDisplayActivity extends HookActivity implements
      * Shows the information of the {@link OCFile} received as a
      * Shows the information of the {@link OCFile} received as a
      * parameter in the second fragment.
      * parameter in the second fragment.
      *
      *
-     * @param file          {@link OCFile} whose details will be shown
+     * @param file {@link OCFile} whose details will be shown
      */
      */
     @Override
     @Override
     public void showDetails(OCFile file) {
     public void showDetails(OCFile file) {
@@ -1308,8 +1311,8 @@ public class FileDisplayActivity extends HookActivity implements
      * Updates the view associated to the activity after the finish of some operation over files
      * Updates the view associated to the activity after the finish of some operation over files
      * in the current account.
      * in the current account.
      *
      *
-     * @param operation     Removal operation performed.
-     * @param result        Result of the removal.
+     * @param operation Removal operation performed.
+     * @param result    Result of the removal.
      */
      */
     @Override
     @Override
     public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
     public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
@@ -1360,8 +1363,8 @@ public class FileDisplayActivity extends HookActivity implements
      * Updates the view associated to the activity after the finish of an operation trying to
      * Updates the view associated to the activity after the finish of an operation trying to
      * remove a file.
      * remove a file.
      *
      *
-     * @param operation     Removal operation performed.
-     * @param result        Result of the removal.
+     * @param operation Removal operation performed.
+     * @param result    Result of the removal.
      */
      */
     private void onRemoveFileOperationFinish(RemoveFileOperation operation,
     private void onRemoveFileOperationFinish(RemoveFileOperation operation,
                                              RemoteOperationResult result) {
                                              RemoteOperationResult result) {
@@ -1397,8 +1400,8 @@ public class FileDisplayActivity extends HookActivity implements
      * Updates the view associated to the activity after the finish of an operation trying to move a
      * Updates the view associated to the activity after the finish of an operation trying to move a
      * file.
      * file.
      *
      *
-     * @param operation     Move operation performed.
-     * @param result        Result of the move operation.
+     * @param operation Move operation performed.
+     * @param result    Result of the move operation.
      */
      */
     private void onMoveFileOperationFinish(MoveFileOperation operation,
     private void onMoveFileOperationFinish(MoveFileOperation operation,
                                            RemoteOperationResult result) {
                                            RemoteOperationResult result) {
@@ -1444,8 +1447,8 @@ public class FileDisplayActivity extends HookActivity implements
      * Updates the view associated to the activity after the finish of an operation trying to rename
      * Updates the view associated to the activity after the finish of an operation trying to rename
      * a file.
      * a file.
      *
      *
-     * @param operation     Renaming operation performed.
-     * @param result        Result of the renaming.
+     * @param operation Renaming operation performed.
+     * @param result    Result of the renaming.
      */
      */
     private void onRenameFileOperationFinish(RenameFileOperation operation,
     private void onRenameFileOperationFinish(RenameFileOperation operation,
                                              RemoteOperationResult result) {
                                              RemoteOperationResult result) {
@@ -1512,8 +1515,8 @@ public class FileDisplayActivity extends HookActivity implements
      * Updates the view associated to the activity after the finish of an operation trying create a
      * Updates the view associated to the activity after the finish of an operation trying create a
      * new folder
      * new folder
      *
      *
-     * @param operation     Creation operation performed.
-     * @param result        Result of the creation.
+     * @param operation Creation operation performed.
+     * @param result    Result of the creation.
      */
      */
     private void onCreateFolderOperationFinish(CreateFolderOperation operation,
     private void onCreateFolderOperationFinish(CreateFolderOperation operation,
                                                RemoteOperationResult result) {
                                                RemoteOperationResult result) {
@@ -1584,16 +1587,16 @@ public class FileDisplayActivity extends HookActivity implements
 
 
     /**
     /**
      * Starts an operation to refresh the requested folder.
      * Starts an operation to refresh the requested folder.
-     *
+     * <p/>
      * The operation is run in a new background thread created on the fly.
      * The operation is run in a new background thread created on the fly.
-     *
+     * <p/>
      * The refresh updates is a "light sync": properties of regular files in folder are updated (including
      * The refresh updates is a "light sync": properties of regular files in folder are updated (including
      * associated shares), but not their contents. Only the contents of files marked to be kept-in-sync are
      * associated shares), but not their contents. Only the contents of files marked to be kept-in-sync are
      * synchronized too.
      * synchronized too.
      *
      *
-     * @param folder        Folder to refresh.
-     * @param ignoreETag    If 'true', the data from the server will be fetched and sync'ed even if the eTag
-     *                      didn't change.
+     * @param folder     Folder to refresh.
+     * @param ignoreETag If 'true', the data from the server will be fetched and sync'ed even if the eTag
+     *                   didn't change.
      */
      */
     public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag) {
     public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag) {
 
 
@@ -1671,7 +1674,7 @@ public class FileDisplayActivity extends HookActivity implements
      * to monitor the download progress and prepares the activity to send the file
      * to monitor the download progress and prepares the activity to send the file
      * when the download finishes.
      * when the download finishes.
      *
      *
-     * @param file          {@link OCFile} to download and preview.
+     * @param file {@link OCFile} to download and preview.
      */
      */
     public void startDownloadForSending(OCFile file) {
     public void startDownloadForSending(OCFile file) {
         mWaitingToSend = file;
         mWaitingToSend = file;
@@ -1683,7 +1686,7 @@ public class FileDisplayActivity extends HookActivity implements
     /**
     /**
      * Opens the image gallery showing the image {@link OCFile} received as parameter.
      * Opens the image gallery showing the image {@link OCFile} received as parameter.
      *
      *
-     * @param file                      Image {@link OCFile} to show.
+     * @param file Image {@link OCFile} to show.
      */
      */
     public void startImagePreview(OCFile file) {
     public void startImagePreview(OCFile file) {
         Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
         Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
@@ -1696,11 +1699,11 @@ public class FileDisplayActivity extends HookActivity implements
     /**
     /**
      * Stars the preview of an already down media {@link OCFile}.
      * Stars the preview of an already down media {@link OCFile}.
      *
      *
-     * @param file                      Media {@link OCFile} to preview.
-     * @param startPlaybackPosition     Media position where the playback will be started,
-     *                                  in milliseconds.
-     * @param autoplay                  When 'true', the playback will start without user
-     *                                  interactions.
+     * @param file                  Media {@link OCFile} to preview.
+     * @param startPlaybackPosition Media position where the playback will be started,
+     *                              in milliseconds.
+     * @param autoplay              When 'true', the playback will start without user
+     *                              interactions.
      */
      */
     public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
     public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
         Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition,
         Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition,
@@ -1733,7 +1736,7 @@ public class FileDisplayActivity extends HookActivity implements
      * to monitor the download progress and prepares the activity to preview
      * to monitor the download progress and prepares the activity to preview
      * or open the file when the download finishes.
      * or open the file when the download finishes.
      *
      *
-     * @param file          {@link OCFile} to download and preview.
+     * @param file {@link OCFile} to download and preview.
      */
      */
     public void startDownloadForPreview(OCFile file) {
     public void startDownloadForPreview(OCFile file) {
         Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());
         Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());

+ 9 - 7
src/com/owncloud/android/ui/activity/Uploader.java

@@ -564,7 +564,7 @@ public class Uploader extends FileActivity
                 }
                 }
 
 
                 FileUploader.uploadNewFile(this, getAccount(), local.toArray(new String[local.size()]), remote
                 FileUploader.uploadNewFile(this, getAccount(), local.toArray(new String[local.size()]), remote
-                        .toArray(new String[remote.size()]));
+                        .toArray(new String[remote.size()]), FileUploader.LOCAL_BEHAVIOUR_FORGET, null, false, false);
 
 
                 //Save the path to shared preferences
                 //Save the path to shared preferences
                 SharedPreferences.Editor appPrefs = PreferenceManager
                 SharedPreferences.Editor appPrefs = PreferenceManager
@@ -597,8 +597,8 @@ public class Uploader extends FileActivity
      * Updates the view associated to the activity after the finish of an operation
      * Updates the view associated to the activity after the finish of an operation
      * trying create a new folder
      * trying create a new folder
      *
      *
-     * @param operation     Creation operation performed.
-     * @param result        Result of the creation.
+     * @param operation Creation operation performed.
+     * @param result    Result of the creation.
      */
      */
     private void onCreateFolderOperationFinish(CreateFolderOperation operation,
     private void onCreateFolderOperationFinish(CreateFolderOperation operation,
                                                RemoteOperationResult result) {
                                                RemoteOperationResult result) {
@@ -619,9 +619,9 @@ public class Uploader extends FileActivity
 
 
 
 
     /**
     /**
-     *  Loads the target folder initialize shown to the user.
-     *
-     *  The target account has to be chosen before this method is called. 
+     * Loads the target folder initialize shown to the user.
+     * <p/>
+     * The target account has to be chosen before this method is called.
      */
      */
     private void initTargetFolder() {
     private void initTargetFolder() {
         if (getStorageManager() == null) {
         if (getStorageManager() == null) {
@@ -683,6 +683,7 @@ public class Uploader extends FileActivity
 
 
     /**
     /**
      * Process the result of CopyTmpFileAsyncTask
      * Process the result of CopyTmpFileAsyncTask
+     *
      * @param result
      * @param result
      * @param index
      * @param index
      */
      */
@@ -692,7 +693,8 @@ public class Uploader extends FileActivity
             dismissWaitingCopyDialog();
             dismissWaitingCopyDialog();
         }
         }
         if (result != null) {
         if (result != null) {
-            FileUploader.uploadNewFile(this, getAccount(), result, mRemoteCacheData.get(index));
+            FileUploader.uploadNewFile(this, getAccount(), result, mRemoteCacheData.get(index), FileUploader
+                    .LOCAL_BEHAVIOUR_FORGET, null, false, false);
 
 
         } else {
         } else {
             String message = String.format(getString(R.string.uploader_error_forbidden_content),
             String message = String.format(getString(R.string.uploader_error_forbidden_content),

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

@@ -1,22 +1,21 @@
 /**
 /**
- *   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
- *   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/>.
+ * ownCloud Android client application
  *
  *
+ * @author LukeOwncloud
+ * @author masensio
+ * Copyright (C) 2015 ownCloud Inc.
+ * <p/>
+ * 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.
+ * <p/>
+ * 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.
+ * <p/>
+ * 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.ui.adapter;
 package com.owncloud.android.ui.adapter;
 
 
@@ -75,32 +74,40 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     interface Refresh {
     interface Refresh {
         public void refresh();
         public void refresh();
     }
     }
+
     abstract class UploadGroup implements Refresh {
     abstract class UploadGroup implements Refresh {
         OCUpload[] items;
         OCUpload[] items;
         String name;
         String name;
+
         public UploadGroup(String groupName) {
         public UploadGroup(String groupName) {
             this.name = groupName;
             this.name = groupName;
             items = new OCUpload[0];
             items = new OCUpload[0];
         }
         }
+
         public String getGroupName() {
         public String getGroupName() {
             return name;
             return name;
         }
         }
+
         public Comparator<OCUpload> comparator = new Comparator<OCUpload>() {
         public Comparator<OCUpload> comparator = new Comparator<OCUpload>() {
             @Override
             @Override
             public int compare(OCUpload lhs, OCUpload rhs) {
             public int compare(OCUpload lhs, OCUpload rhs) {
                 return compareUploadId(lhs, rhs);
                 return compareUploadId(lhs, rhs);
             }
             }
+
             private int compareUploadId(OCUpload lsh, OCUpload rsh) {
             private int compareUploadId(OCUpload lsh, OCUpload rsh) {
                 return Long.valueOf(lsh.getUploadId()).compareTo(rsh.getUploadId());
                 return Long.valueOf(lsh.getUploadId()).compareTo(rsh.getUploadId());
             }
             }
+
             private int compareUpdateTime(OCUpload lhs, OCUpload rhs) {
             private int compareUpdateTime(OCUpload lhs, OCUpload rhs) {
                 long lLastModified = new File(lhs.getLocalPath()).lastModified();
                 long lLastModified = new File(lhs.getLocalPath()).lastModified();
                 long rLastModified = new File(rhs.getLocalPath()).lastModified();
                 long rLastModified = new File(rhs.getLocalPath()).lastModified();
                 return Long.valueOf(rLastModified).compareTo(lLastModified);
                 return Long.valueOf(rLastModified).compareTo(lLastModified);
             }
             }
         };
         };
+
         abstract public int getGroupIcon();
         abstract public int getGroupIcon();
     }
     }
+
     private UploadGroup[] mUploadGroups = null;
     private UploadGroup[] mUploadGroups = null;
     private final int MAX_NUM_UPLOADS_SHOWN = 30;
     private final int MAX_NUM_UPLOADS_SHOWN = 30;
 
 
@@ -116,31 +123,34 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                 Arrays.sort(items, comparator);
                 Arrays.sort(items, comparator);
                 items = trimToMaxLength(items);
                 items = trimToMaxLength(items);
             }
             }
+
             @Override
             @Override
             public int getGroupIcon() {
             public int getGroupIcon() {
                 return R.drawable.upload_in_progress;
                 return R.drawable.upload_in_progress;
             }
             }
         };
         };
-        mUploadGroups[1] = new UploadGroup(mParentActivity.getString(R.string.uploads_view_group_failed_uploads)){
+        mUploadGroups[1] = new UploadGroup(mParentActivity.getString(R.string.uploads_view_group_failed_uploads)) {
             @Override
             @Override
             public void refresh() {
             public void refresh() {
                 items = mUploadsStorageManager.getFailedUploads();
                 items = mUploadsStorageManager.getFailedUploads();
                 Arrays.sort(items, comparator);
                 Arrays.sort(items, comparator);
                 items = trimToMaxLength(items);
                 items = trimToMaxLength(items);
             }
             }
+
             @Override
             @Override
             public int getGroupIcon() {
             public int getGroupIcon() {
                 return R.drawable.upload_failed;
                 return R.drawable.upload_failed;
             }
             }
 
 
         };
         };
-        mUploadGroups[2] = new UploadGroup(mParentActivity.getString(R.string.uploads_view_group_finished_uploads)){
+        mUploadGroups[2] = new UploadGroup(mParentActivity.getString(R.string.uploads_view_group_finished_uploads)) {
             @Override
             @Override
             public void refresh() {
             public void refresh() {
                 items = mUploadsStorageManager.getFinishedUploads();
                 items = mUploadsStorageManager.getFinishedUploads();
                 Arrays.sort(items, comparator);
                 Arrays.sort(items, comparator);
                 items = trimToMaxLength(items);
                 items = trimToMaxLength(items);
             }
             }
+
             @Override
             @Override
             public int getGroupIcon() {
             public int getGroupIcon() {
                 return R.drawable.upload_finished;
                 return R.drawable.upload_finished;
@@ -151,11 +161,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     }
     }
 
 
 
 
-    private OCUpload[] trimToMaxLength(OCUpload[] items){
+    private OCUpload[] trimToMaxLength(OCUpload[] items) {
         if (items.length > 30) {
         if (items.length > 30) {
-            OCUpload[] arrayTrim= new OCUpload[30];
+            OCUpload[] arrayTrim = new OCUpload[30];
 
 
-            for(int i = 0; i < MAX_NUM_UPLOADS_SHOWN; i++){
+            for (int i = 0; i < MAX_NUM_UPLOADS_SHOWN; i++) {
                 arrayTrim[i] = items[i];
                 arrayTrim[i] = items[i];
             }
             }
             return arrayTrim;
             return arrayTrim;
@@ -249,7 +259,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                     progressBar.setProgress(0);
                     progressBar.setProgress(0);
                     progressBar.setVisibility(View.VISIBLE);
                     progressBar.setVisibility(View.VISIBLE);
                     mProgressListener = new ProgressListener(progressBar);
                     mProgressListener = new ProgressListener(progressBar);
-                    if(mParentActivity.getFileUploaderBinder() != null) {
+                    if (mParentActivity.getFileUploaderBinder() != null) {
                         mParentActivity.getFileUploaderBinder().addDatatransferProgressListener(
                         mParentActivity.getFileUploaderBinder().addDatatransferProgressListener(
                                 mProgressListener,
                                 mProgressListener,
                                 mParentActivity.getAccount(),
                                 mParentActivity.getAccount(),
@@ -280,7 +290,8 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                                         Intent updateAccountCredentials = new Intent(mParentActivity,
                                         Intent updateAccountCredentials = new Intent(mParentActivity,
                                                 AuthenticatorActivity.class);
                                                 AuthenticatorActivity.class);
                                         updateAccountCredentials.putExtra(
                                         updateAccountCredentials.putExtra(
-                                                AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount(mParentActivity));
+                                                AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount
+                                                        (mParentActivity));
                                         updateAccountCredentials.putExtra(
                                         updateAccountCredentials.putExtra(
                                                 AuthenticatorActivity.EXTRA_ACTION,
                                                 AuthenticatorActivity.EXTRA_ACTION,
                                                 AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
                                                 AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
@@ -310,7 +321,8 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                         }
                         }
                     } else {
                     } else {
                         status = mParentActivity.getString(
                         status = mParentActivity.getString(
-                                R.string.uploads_view_upload_status_failed);;
+                                R.string.uploads_view_upload_status_failed);
+                        ;
                     }
                     }
                     break;
                     break;
                 case UPLOAD_FAILED_RETRY:
                 case UPLOAD_FAILED_RETRY:
@@ -320,7 +332,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                         status = mParentActivity.getString(R.string.uploads_view_upload_status_failed_retry);
                         status = mParentActivity.getString(R.string.uploads_view_upload_status_failed_retry);
                     }
                     }
                     String laterReason = upload.getUploadLaterReason(mParentActivity);
                     String laterReason = upload.getUploadLaterReason(mParentActivity);
-                    if(laterReason != null) {
+                    if (laterReason != null) {
                         //Upload failed once but is delayed now, show reason.
                         //Upload failed once but is delayed now, show reason.
                         status = laterReason;
                         status = laterReason;
                     }
                     }
@@ -337,23 +349,23 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                     status = upload.getUploadLaterReason(mParentActivity);
                     status = upload.getUploadLaterReason(mParentActivity);
                     break;
                     break;
                 case UPLOAD_SUCCEEDED:
                 case UPLOAD_SUCCEEDED:
-                    status =  mParentActivity.getString(R.string.uploads_view_upload_status_succeeded);
+                    status = mParentActivity.getString(R.string.uploads_view_upload_status_succeeded);
                     statusTextView.setVisibility(View.GONE);
                     statusTextView.setVisibility(View.GONE);
                     break;
                     break;
                 case UPLOAD_CANCELLED:
                 case UPLOAD_CANCELLED:
-                    status =  mParentActivity.getString(R.string.uploads_view_upload_status_cancelled);
+                    status = mParentActivity.getString(R.string.uploads_view_upload_status_cancelled);
                     break;
                     break;
                 case UPLOAD_PAUSED:
                 case UPLOAD_PAUSED:
-                    status =  mParentActivity.getString(R.string.uploads_view_upload_status_paused);
+                    status = mParentActivity.getString(R.string.uploads_view_upload_status_paused);
                     break;
                     break;
                 default:
                 default:
                     status = upload.getUploadStatus().toString();
                     status = upload.getUploadStatus().toString();
-                    if(upload.getLastResult() != null){
+                    if (upload.getLastResult() != null) {
                         upload.getLastResult().toString();
                         upload.getLastResult().toString();
                     }
                     }
                     break;
                     break;
             }
             }
-            if(upload.getUploadStatus() != UploadStatus.UPLOAD_IN_PROGRESS) {
+            if (upload.getUploadStatus() != UploadStatus.UPLOAD_IN_PROGRESS) {
                 ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.upload_progress_bar);
                 ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.upload_progress_bar);
                 progressBar.setVisibility(View.GONE);
                 progressBar.setVisibility(View.GONE);
                 if (mParentActivity.getFileUploaderBinder() != null && mProgressListener != null) {
                 if (mParentActivity.getFileUploaderBinder() != null && mProgressListener != null) {
@@ -393,12 +405,12 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             }
             }
 
 
             if (upload.userCanRetryUpload()) {
             if (upload.userCanRetryUpload()) {
-                    view.setOnClickListener(new OnClickListener() {
-                        @Override
-                        public void onClick(View v) {
-                            mParentActivity.getFileOperationsHelper().retryUpload(upload);
-                        }
-                    });
+                view.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        mParentActivity.getFileOperationsHelper().retryUpload(upload);
+                    }
+                });
             }
             }
 
 
 
 
@@ -420,12 +432,12 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             // TODO this code is duplicated; refactor to a common place
             // TODO this code is duplicated; refactor to a common place
             if ((fakeFileToCheatThumbnailsCacheManagerInterface.isImage()
             if ((fakeFileToCheatThumbnailsCacheManagerInterface.isImage()
                     && fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
                     && fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
-                    upload.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED)){
+                    upload.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED)) {
                 // Thumbnail in Cache?
                 // Thumbnail in Cache?
                 Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
                 Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
                         String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId())
                         String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId())
                 );
                 );
-                if (thumbnail != null && !fakeFileToCheatThumbnailsCacheManagerInterface.needsUpdateThumbnail()){
+                if (thumbnail != null && !fakeFileToCheatThumbnailsCacheManagerInterface.needsUpdateThumbnail()) {
                     fileIcon.setImageBitmap(thumbnail);
                     fileIcon.setImageBitmap(thumbnail);
                 } else {
                 } else {
                     // generate new Thumbnail
                     // generate new Thumbnail
@@ -498,7 +510,6 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     }
     }
 
 
 
 
-
     @Override
     @Override
     public boolean hasStableIds() {
     public boolean hasStableIds() {
         return false;
         return false;
@@ -560,7 +571,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
     public int getGroupCount() {
     public int getGroupCount() {
         int size = 0;
         int size = 0;
         for (UploadGroup uploadGroup : mUploadGroups) {
         for (UploadGroup uploadGroup : mUploadGroups) {
-            if(uploadGroup.items.length > 0) {
+            if (uploadGroup.items.length > 0) {
                 size++;
                 size++;
             }
             }
         }
         }
@@ -576,7 +587,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
         int id = -1;
         int id = -1;
         for (int i = 0; i <= groupPosition; ) {
         for (int i = 0; i <= groupPosition; ) {
             id++;
             id++;
-            if(mUploadGroups[id].items.length > 0){
+            if (mUploadGroups[id].items.length > 0) {
                 i++;
                 i++;
             }
             }
         }
         }
@@ -617,8 +628,9 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
         }
         }
 
 
         @Override
         @Override
-        public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String filename) {
-            int percent = (int)(100.0*((double)totalTransferredSoFar)/((double)totalToTransfer));
+        public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String
+                filename) {
+            int percent = (int) (100.0 * ((double) totalTransferredSoFar) / ((double) totalToTransfer));
             if (percent != mLastPercent) {
             if (percent != mLastPercent) {
                 ProgressBar pb = mProgressBar.get();
                 ProgressBar pb = mProgressBar.get();
                 if (pb != null) {
                 if (pb != null) {
@@ -629,9 +641,11 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             mLastPercent = percent;
             mLastPercent = percent;
         }
         }
 
 
-    };
+    }
+
+    ;
 
 
-    public void addBinder(){
+    public void addBinder() {
         notifyDataSetChanged();
         notifyDataSetChanged();
     }
     }
 }
 }