Browse Source

Changes from comments in reliable_uploads code review

masensio 9 years ago
parent
commit
1a74d5ba59

+ 12 - 61
src/com/owncloud/android/db/UploadDbHandler.java

@@ -1,6 +1,8 @@
-/* ownCloud Android client application
- *   Copyright (C) 2011-2012  Bartek Przybylski
- *   Copyright (C) 2012-2013 ownCloud Inc.
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   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,
@@ -32,10 +34,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 /**
  * Database helper for storing list of files to be uploaded, including status
  * information for each file.
- * 
- * @author Bartek Przybylski
- * @author LukeOwncloud
- * 
  */
 public class UploadDbHandler extends Observable {
     private SQLiteDatabase mDB;
@@ -43,20 +41,9 @@ public class UploadDbHandler extends Observable {
     private final String mDatabaseName;
     private final int mDatabaseVersion = 4;
 
-    static private final String TAG = "UploadDbHandler";
+    static private final String TAG = UploadDbHandler.class.getSimpleName();
     static private final String TABLE_UPLOAD = "list_of_uploads";
 
-    // for testing only
-    public void recreateDb() {
-//        getDB().beginTransaction();
-//        try {
-//            mHelper.onUpgrade(getDB(), 0, mDatabaseVersion);
-//            getDB().setTransactionSuccessful();
-//        } finally {
-//            getDB().endTransaction();
-//        }
-    }
-
     public enum UploadStatus {
         /**
          * Upload scheduled.
@@ -88,7 +75,7 @@ public class UploadDbHandler extends Observable {
         UPLOAD_CANCELLED(6);
         private final int value;
 
-        private UploadStatus(int value) {
+        UploadStatus(int value) {
             this.value = value;
         }
 
@@ -117,41 +104,6 @@ public class UploadDbHandler extends Observable {
         me = null;
     }
 
-    /**
-     * Store a file persistently (to be uploaded later).
-     * 
-     * @param filepath local file path to file
-     * @param account account for uploading
-     * @param message optional message. can be null.
-     * @return false if an error occurred, else true.
-     */
-    public boolean storeFile(String filepath, String account, String message) {
-        // /OBSOLETE
-        Log_OC.i(TAG, "obsolete method called");
-        return false;
-        // ContentValues cv = new ContentValues();
-        // cv.put("path", filepath);
-        // cv.put("account", account);
-        // cv.put("attempt",
-        // UploadStatus.UPLOAD_STATUS_UPLOAD_LATER.getValue());
-        // cv.put("message", message);
-        // long result = mDB.insert(TABLE_UPLOAD, null, cv);
-        // Log_OC.d(TABLE_UPLOAD, "putFileForLater returns with: " + result +
-        // " for file: " + filepath);
-        // return result != -1;
-    }
-
-    // ununsed until now. uncomment if needed.
-    // public Cursor getFailedFiles() {
-    // return mDB.query(TABLE_INSTANT_UPLOAD, null, "attempt>" +
-    // UploadStatus.UPLOAD_STATUS_UPLOAD_LATER, null, null, null, null);
-    // }
-
-    // ununsed until now. uncomment if needed.
-    // public void clearFiles() {
-    // mDB.delete(TABLE_INSTANT_UPLOAD, null, null);
-    // }
-
     private class OpenerHelper extends SQLiteOpenHelper {
         public OpenerHelper(Context context) {
             super(context, mDatabaseName, null, mDatabaseVersion);
@@ -197,7 +149,7 @@ public class UploadDbHandler extends Observable {
 
         long result = getDB().insert(TABLE_UPLOAD, null, cv);
         
-        Log_OC.d(TAG, "putFileForLater returns with: " + result + " for file: " + uploadObject.getLocalPath());
+        Log_OC.d(TAG, "storeUpload returns with: " + result + " for file: " + uploadObject.getLocalPath());
         if (result == -1) {
             Log_OC.e(TAG, "Failed to insert item " + uploadObject.getLocalPath() + " into upload db.");
             return false;
@@ -217,12 +169,10 @@ public class UploadDbHandler extends Observable {
                 uploadDbObject.getLastResult());
     }
 
-    public int updateUploadInternal(Cursor c, UploadStatus status, RemoteOperationResult result) {
+    private int updateUploadInternal(Cursor c, UploadStatus status, RemoteOperationResult result) {
         
         while(c.moveToNext()) {
             // read upload object and update
-            
-            
             String uploadObjectString = c.getString(c.getColumnIndex("uploadObject"));
             UploadDbObject uploadObject = UploadDbObject.fromString(uploadObjectString);
             
@@ -280,7 +230,7 @@ public class UploadDbHandler extends Observable {
      * are informed.
      */
     public void notifyObserversNow() {
-        Log_OC.d("UploadListAdapter", "notifyObserversNow");
+        Log_OC.d(TAG, "notifyObserversNow");
         setChanged();
         notifyObservers();
     }
@@ -407,7 +357,8 @@ public class UploadDbHandler extends Observable {
     
     public void setAllCurrentToUploadLater() {
         
-        Cursor c = getDB().query(TABLE_UPLOAD, null, "uploadStatus==" + UploadStatus.UPLOAD_IN_PROGRESS.value, null, null, null, null);
+        Cursor c = getDB().query(TABLE_UPLOAD, null, "uploadStatus==" + UploadStatus.UPLOAD_IN_PROGRESS.value,
+                null, null, null, null);
         
         updateUploadInternal(c, UploadStatus.UPLOAD_LATER, null);
     }

+ 94 - 52
src/com/owncloud/android/db/UploadDbObject.java

@@ -1,3 +1,23 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 package com.owncloud.android.db;
 
 import java.io.ByteArrayInputStream;
@@ -23,58 +43,45 @@ import com.owncloud.android.lib.common.utils.Log_OC;
  * Stores all information in order to start upload operations. PersistentUploadObject can
  * be stored persistently by {@link UploadDbHandler}.
  * 
- * @author LukeOwncloud
- * 
  */
 public class UploadDbObject implements Serializable {
 
     /** Generated - should be refreshed every time the class changes!! */
     private static final long serialVersionUID = -2306246191385279928L;
 
-    private static final String TAG = "UploadDbObject";
+    private static final String TAG = UploadDbObject.class.getSimpleName();
     
     public UploadDbObject(OCFile ocFile) {
-        this.ocFile = ocFile;
+        this.mFile = ocFile;
     }
-//    /**
-//     * Local path to file which is to be uploaded.
-//     */
-//    String localPath;
-//    /**
-//     * Remote path where file is to be uploaded to.
-//     */
-//    String remotePath;
-//
-//    /**
-//     * Mime type of upload file.
-//     */
-//    String mimeType;
-    OCFile ocFile;
+
+
+    OCFile mFile;
     
     public OCFile getOCFile() {
-        return ocFile;
+        return mFile;
     }
     
     
     /**
      * Local action for upload.
      */
-    LocalBehaviour localAction;
+    LocalBehaviour mLocalAction;
 
     /**
      * Date and time when this upload was first requested.
      */
-    Calendar uploadTime = new GregorianCalendar();
+    Calendar mUploadTime = new GregorianCalendar();
 
     public Calendar getUploadTime() {
-        return uploadTime;
+        return mUploadTime;
     }
 
     /**
      * @return the uploadStatus
      */
     public UploadStatus getUploadStatus() {
-        return uploadStatus;
+        return mUploadStatus;
     }
 
     /**
@@ -82,7 +89,7 @@ public class UploadDbObject implements Serializable {
      * @param uploadStatus the uploadStatus to set
      */
     public void setUploadStatus(UploadStatus uploadStatus) {
-        this.uploadStatus = uploadStatus;
+        this.mUploadStatus = uploadStatus;
         setLastResult(null);
     }
 
@@ -90,71 +97,71 @@ public class UploadDbObject implements Serializable {
      * @return the lastResult
      */
     public RemoteOperationResult getLastResult() {
-        return lastResult;
+        return mLastResult;
     }
 
     /**
      * @param lastResult the lastResult to set
      */
     public void setLastResult(RemoteOperationResult lastResult) {
-        this.lastResult = lastResult;
+        this.mLastResult = lastResult;
     }
 
     /**
      * Overwrite destination file?
      */
-    boolean forceOverwrite;
+    boolean mForceOverwrite;
     /**
      * Create destination folder?
      */
-    boolean isCreateRemoteFolder;
+    boolean mIsCreateRemoteFolder;
     /**
      * Upload only via wifi?
      */
-    boolean isUseWifiOnly;
+    boolean mIsUseWifiOnly;
     /**
      * Upload only if phone being charged?
      */
-    boolean isWhileChargingOnly;
+    boolean mIsWhileChargingOnly;
     /**
      * Earliest time when upload may be started. Negative if not set.
      */
-    long uploadTimestamp;
+    long mUploadTimestamp;
 
     /**
      * Name of Owncloud account to upload file to.
      */
-    String accountName;
+    String mAccountName;
 
     /**
      * Status of upload (later, in_progress, ...).
      */
-    UploadStatus uploadStatus;
+    UploadStatus mUploadStatus;
 
     /**
      * Result from last upload operation. Can be null.
      */
-    RemoteOperationResult lastResult;
+    RemoteOperationResult mLastResult;
 
     /**
      * @return the localPath
      */
     public String getLocalPath() {
-        return ocFile.getStoragePath();
+        return mFile.getStoragePath();
     }
 
     /**
      * @return the remotePath
      */
     public String getRemotePath() {
-        return ocFile.getRemotePath();
+        return mFile.getRemotePath();
     }
 
     /**
      * @return the mimeType
      */
     public String getMimeType() {
-        return ocFile.getMimetype();
+        return mFile.getMimetype();
     }
 
 
@@ -163,70 +170,70 @@ public class UploadDbObject implements Serializable {
      */
     public LocalBehaviour getLocalAction() {
         // return null;
-        return localAction;
+        return mLocalAction;
     }
 
     /**
      * @param localAction the localAction to set
      */
     public void setLocalAction(LocalBehaviour localAction) {
-        this.localAction = localAction;
+        this.mLocalAction = localAction;
     }
 
     /**
      * @return the forceOverwrite
      */
     public boolean isForceOverwrite() {
-        return forceOverwrite;
+        return mForceOverwrite;
     }
 
     /**
      * @param forceOverwrite the forceOverwrite to set
      */
     public void setForceOverwrite(boolean forceOverwrite) {
-        this.forceOverwrite = forceOverwrite;
+        this.mForceOverwrite = forceOverwrite;
     }
 
     /**
      * @return the isCreateRemoteFolder
      */
     public boolean isCreateRemoteFolder() {
-        return isCreateRemoteFolder;
+        return mIsCreateRemoteFolder;
     }
 
     /**
      * @param isCreateRemoteFolder the isCreateRemoteFolder to set
      */
     public void setCreateRemoteFolder(boolean isCreateRemoteFolder) {
-        this.isCreateRemoteFolder = isCreateRemoteFolder;
+        this.mIsCreateRemoteFolder = isCreateRemoteFolder;
     }
 
     /**
      * @return the isUseWifiOnly
      */
     public boolean isUseWifiOnly() {
-        return isUseWifiOnly;
+        return mIsUseWifiOnly;
     }
 
     /**
      * @param isUseWifiOnly the isUseWifiOnly to set
      */
     public void setUseWifiOnly(boolean isUseWifiOnly) {
-        this.isUseWifiOnly = isUseWifiOnly;
+        this.mIsUseWifiOnly = isUseWifiOnly;
     }
 
     /**
      * @return the accountName
      */
     public String getAccountName() {
-        return accountName;
+        return mAccountName;
     }
 
     /**
      * @param accountName the accountName to set
      */
     public void setAccountName(String accountName) {
-        this.accountName = accountName;
+        this.mAccountName = accountName;
     }
 
     /**
@@ -279,11 +286,11 @@ public class UploadDbObject implements Serializable {
     }
 
     public void setWhileChargingOnly(boolean isWhileChargingOnly) {
-        this.isWhileChargingOnly = isWhileChargingOnly;        
+        this.mIsWhileChargingOnly = isWhileChargingOnly;
     }
     
     public boolean isWhileChargingOnly() {
-        return isWhileChargingOnly;
+        return mIsWhileChargingOnly;
     }
 
     /**
@@ -291,7 +298,7 @@ public class UploadDbObject implements Serializable {
      * @return the uploadTimestamp
      */
     public long getUploadTimestamp() {
-        return uploadTimestamp;
+        return mUploadTimestamp;
     }
 
     /**
@@ -299,14 +306,15 @@ public class UploadDbObject implements Serializable {
      * @param uploadTimestamp the uploadTimestamp to set
      */
     public void setUploadTimestamp(long uploadTimestamp) {
-        this.uploadTimestamp = uploadTimestamp;
+        this.mUploadTimestamp = uploadTimestamp;
     }
     
     /**
      * For debugging purposes only.
      */
     public String toFormattedString() {
-        return getLocalPath() + " status:"+getUploadStatus() + " result:" + (getLastResult()==null?"null":getLastResult().getCode());
+        return getLocalPath() + " status:" + getUploadStatus() + " result:" +
+                (getLastResult() == null?"null" : getLastResult().getCode());
     }
 
     /**
@@ -317,4 +325,38 @@ public class UploadDbObject implements Serializable {
         setWhileChargingOnly(false);
         setUploadTimestamp(0);
     }
+
+    /**
+     * Returns true when user is able to cancel this upload. That is, when
+     * upload is currently in progress or scheduled for upload.
+     */
+    public  boolean userCanCancelUpload() {
+        switch (this.getUploadStatus()) {
+            case UPLOAD_IN_PROGRESS:
+            case UPLOAD_LATER:
+            case UPLOAD_FAILED_RETRY:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    /**
+     * Returns true when user can choose to retry this upload. That is, when
+     * user cancelled upload before or when upload has failed.
+     */
+    public boolean userCanRetryUpload() {
+        switch (this.getUploadStatus()) {
+            case UPLOAD_CANCELLED:
+            case UPLOAD_FAILED_RETRY://automatically retried. no need for user option.
+            case UPLOAD_FAILED_GIVE_UP: //TODO this case needs to be handled as described by
+                // https://github.com/owncloud/android/issues/765#issuecomment-66490312
+            case UPLOAD_LATER: //upload is already schedule but allow user to increase priority
+            case UPLOAD_SUCCEEDED: // if user wants let him to re-upload (maybe
+                // remote file was deleted...)
+                return true;
+            default:
+                return false;
+        }
+    }
 }

+ 10 - 6
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

@@ -43,10 +43,12 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
     // Image action
     // Unofficial action, works for most devices but not HTC. See: https://github.com/owncloud/android/issues/6
     private static String NEW_PHOTO_ACTION_UNOFFICIAL = "com.android.camera.NEW_PICTURE";
-    // Officially supported action since SDK 14: http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_PICTURE
+    // Officially supported action since SDK 14:
+    // http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_PICTURE
     private static String NEW_PHOTO_ACTION = "android.hardware.action.NEW_PICTURE";
     // Video action
-    // Officially supported action since SDK 14: http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_VIDEO
+    // Officially supported action since SDK 14:
+    // http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_VIDEO
     private static String NEW_VIDEO_ACTION = "android.hardware.action.NEW_VIDEO";
 
     @Override
@@ -91,7 +93,8 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             return;
         }
 
-        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE };
+        String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE,
+                Images.Media.SIZE };
         c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
         if (!c.moveToFirst()) {
             Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
@@ -114,7 +117,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         i.putExtra(FileUploadService.KEY_ACCOUNT, account);
         i.putExtra(FileUploadService.KEY_LOCAL_FILE, file_path);
         i.putExtra(FileUploadService.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, file_name));
-        i.putExtra(FileUploadService.KEY_UPLOAD_TYPE, FileUploadService.UploadSingleMulti.UPLOAD_SINGLE_FILE);
+        i.putExtra(FileUploadService.KEY_UPLOAD_TYPE, FileUploadService.UploadQuantity.UPLOAD_SINGLE_FILE);
         i.putExtra(FileUploadService.KEY_MIME_TYPE, mime_type);
         i.putExtra(FileUploadService.KEY_CREATE_REMOTE_FOLDER, true);
         i.putExtra(FileUploadService.KEY_WIFI_ONLY, instantPictureUploadViaWiFiOnly(context));
@@ -167,7 +170,8 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             return;
         }
 
-        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE, Video.Media.SIZE };
+        String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE,
+                Video.Media.SIZE };
         c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
         if (!c.moveToFirst()) {
             Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
@@ -183,7 +187,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         i.putExtra(FileUploadService.KEY_ACCOUNT, account);
         i.putExtra(FileUploadService.KEY_LOCAL_FILE, file_path);
         i.putExtra(FileUploadService.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, file_name));
-        i.putExtra(FileUploadService.KEY_UPLOAD_TYPE, FileUploadService.UploadSingleMulti.UPLOAD_SINGLE_FILE);
+        i.putExtra(FileUploadService.KEY_UPLOAD_TYPE, FileUploadService.UploadQuantity.UPLOAD_SINGLE_FILE);
         i.putExtra(FileUploadService.KEY_MIME_TYPE, mime_type);
         i.putExtra(FileUploadService.KEY_CREATE_REMOTE_FOLDER, true);
         i.putExtra(FileUploadService.KEY_WIFI_ONLY, instantVideoUploadViaWiFiOnly(context));

+ 29 - 13
src/com/owncloud/android/files/services/ConnectivityActionReceiver.java

@@ -1,3 +1,23 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 package com.owncloud.android.files.services;
 
 import android.content.BroadcastReceiver;
@@ -7,12 +27,9 @@ import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
-import android.net.NetworkInfo.State;
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
-import android.util.Log;
 
-import com.owncloud.android.files.InstantUploadBroadcastReceiver;
 import com.owncloud.android.lib.common.utils.Log_OC;
 
 /**
@@ -24,37 +41,36 @@ import com.owncloud.android.lib.common.utils.Log_OC;
  * service, ... - Handle offline mode (cf.
  * https://github.com/owncloud/android/issues/162)
  * 
- * @author LukeOwncloud
- * 
  */
 public class ConnectivityActionReceiver extends BroadcastReceiver {
-    private static final String TAG = "ConnectivityActionReceiver";
+    private static final String TAG = ConnectivityActionReceiver.class.getSimpleName();
 
     @Override
     public void onReceive(final Context context, Intent intent) {
         // LOG ALL EVENTS:
-        Log.v(TAG, "action: " + intent.getAction());
-        Log.v(TAG, "component: " + intent.getComponent());
+        Log_OC.v(TAG, "action: " + intent.getAction());
+        Log_OC.v(TAG, "component: " + intent.getComponent());
         Bundle extras = intent.getExtras();
         if (extras != null) {
             for (String key : extras.keySet()) {
-                Log.v(TAG, "key [" + key + "]: " + extras.get(key));
+                Log_OC.v(TAG, "key [" + key + "]: " + extras.get(key));
             }
         } else {
-            Log.v(TAG, "no extras");
+            Log_OC.v(TAG, "no extras");
         }
 
         
         /**
          * Just checking for State.CONNECTED will is not good enough, as it ends here multiple times.
          * Work around from:
-         * http://stackoverflow.com/questions/17287178/connectivitymanager-getactivenetworkinfo-returning-true-when-internet-is-off
+         * http://stackoverflow.com/
+         * questions/17287178/connectivitymanager-getactivenetworkinfo-returning-true-when-internet-is-off
          */            
         if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
             NetworkInfo networkInfo =
                 intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
             if(networkInfo.isConnected()) {
-                Log.d(TAG, "Wifi is connected: " + String.valueOf(networkInfo));
+                Log_OC.d(TAG, "Wifi is connected: " + String.valueOf(networkInfo));
                 wifiConnected(context);
             }
         } else if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
@@ -63,7 +79,7 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
             NetworkInfo networkInfo = cm.getActiveNetworkInfo();
             if(networkInfo == null || networkInfo.getType() == ConnectivityManager.TYPE_WIFI &&
                 ! networkInfo.isConnected()) {
-                Log.d(TAG, "Wifi is disconnected: " + String.valueOf(networkInfo));
+                Log_OC.d(TAG, "Wifi is disconnected: " + String.valueOf(networkInfo));
                 wifiDisconnected(context);
             }
         }

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

@@ -1,6 +1,8 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012 Bartek Przybylski
- *   Copyright (C) 2012-2013 ownCloud Inc.
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   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,
@@ -80,7 +82,6 @@ import com.owncloud.android.operations.CreateFolderOperation;
 import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.activity.UploadListActivity;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.ErrorMessageAdapter;
@@ -98,10 +99,7 @@ import com.owncloud.android.utils.UriUtils;
  * Every file passed to this service is uploaded. No filtering is performed.
  * However, Intent keys (e.g., KEY_WIFI_ONLY) are obeyed.
  * 
- * @author LukeOwncloud
- * 
  */
-@SuppressWarnings("unused")
 public class FileUploadService extends Service implements OnDatatransferProgressListener {
 
     private volatile Looper mServiceLooper;
@@ -138,7 +136,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
      */
     public static final String KEY_ACCOUNT = "ACCOUNT";
     /**
-     * Set whether single file or multiple files are to be uploaded. Value must be of type {@link UploadSingleMulti}.
+     * Set whether single file or multiple files are to be uploaded. Value must be of type {@link UploadQuantity}.
      */
     public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE";
     /**
@@ -186,7 +184,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
         LOCAL_BEHAVIOUR_FORGET(2);
         private final int value;
 
-        private LocalBehaviour(int value) {
+        LocalBehaviour(int value) {
             this.value = value;
         }
 
@@ -195,11 +193,11 @@ public class FileUploadService extends Service implements OnDatatransferProgress
         }
     }
     
-    public enum UploadSingleMulti {
+    public enum UploadQuantity {
         UPLOAD_SINGLE_FILE(0), UPLOAD_MULTIPLE_FILES(1);
         private final int value;
 
-        private UploadSingleMulti(int value) {
+        UploadQuantity(int value) {
             this.value = value;
         }
 
@@ -282,8 +280,8 @@ public class FileUploadService extends Service implements OnDatatransferProgress
         Log_OC.d(TAG, "mPendingUploads size:" + mPendingUploads.size() + " - onCreate");
         mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
         mBinder = new FileUploaderBinder();
-        mDb = UploadDbHandler.getInstance(this.getBaseContext());
-        mDb.recreateDb(); //for testing only
+        mDb = UploadDbHandler.getInstance(this);
+//        mDb.recreateDb(); //for testing only
         
         //when this service starts there is no upload in progress. if db says so, app probably crashed before.
         mDb.setAllCurrentToUploadLater();
@@ -388,7 +386,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
             mDb.notifyObserversNow();
         } else {
             Log_OC.d(TAG, "Receive upload intent.");
-            UploadSingleMulti uploadType = (UploadSingleMulti) intent.getSerializableExtra(KEY_UPLOAD_TYPE);
+            UploadQuantity uploadType = (UploadQuantity) intent.getSerializableExtra(KEY_UPLOAD_TYPE);
             if (uploadType == null) {
                 Log_OC.e(TAG, "Incorrect or no upload type provided");
                 return;
@@ -403,7 +401,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
             OCFile[] files = null;
             // if KEY_FILE given, use it
             if (intent.hasExtra(KEY_FILE)) {
-                if (uploadType == UploadSingleMulti.UPLOAD_SINGLE_FILE) {
+                if (uploadType == UploadQuantity.UPLOAD_SINGLE_FILE) {
                     files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };
                 } else {
                     files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE);
@@ -419,7 +417,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
                 String[] localPaths;
                 String[] remotePaths;
                 String[] mimeTypes;
-                if (uploadType == UploadSingleMulti.UPLOAD_SINGLE_FILE) {
+                if (uploadType == UploadQuantity.UPLOAD_SINGLE_FILE) {
                     localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
                     remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
                     mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
@@ -800,7 +798,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
          * 
          * @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 file {@link OCFile} of interest for listener.
          */
         public void addDatatransferProgressListener(OnDatatransferProgressListener listener, Account account,
                 OCFile file) {
@@ -816,7 +814,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
          * 
          * @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 file {@link OCFile} of interest for listener.
          */
         public void removeDatatransferProgressListener(OnDatatransferProgressListener listener, Account account,
                 OCFile file) {

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

@@ -293,7 +293,7 @@ public class SynchronizeFileOperation extends SyncOperation {
         in the database when the FileUploader service gets it!
         i.putExtra(FileUploader.KEY_LOCAL_FILE, localFile.getStoragePath());*/
         i.putExtra(FileUploadService.KEY_UPLOAD_TYPE,
-                FileUploadService.UploadSingleMulti.UPLOAD_SINGLE_FILE);
+                FileUploadService.UploadQuantity.UPLOAD_SINGLE_FILE);
         i.putExtra(FileUploadService.KEY_FORCE_OVERWRITE, true);
         mContext.startService(i);
         mTransferWasRequested = true;

+ 1 - 1
src/com/owncloud/android/ui/activity/ConflictsResolveActivity.java

@@ -77,7 +77,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
         }
         i.putExtra(FileUploadService.KEY_ACCOUNT, getAccount());
         i.putExtra(FileUploadService.KEY_FILE, (Parcelable)getFile());
-        i.putExtra(FileUploadService.KEY_UPLOAD_TYPE, FileUploadService.UploadSingleMulti.UPLOAD_SINGLE_FILE);
+        i.putExtra(FileUploadService.KEY_UPLOAD_TYPE, FileUploadService.UploadQuantity.UPLOAD_SINGLE_FILE);
         
         startService(i);
         finish();

+ 2 - 8
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -64,7 +64,6 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.db.UploadDbObject;
 import com.owncloud.android.files.services.FileDownloader;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploadService;
@@ -692,7 +691,7 @@ public class FileDisplayActivity extends HookActivity implements
             i.putExtra(FileUploadService.KEY_LOCAL_FILE, filePaths);
             i.putExtra(FileUploadService.KEY_REMOTE_FILE, remotePaths);
             i.putExtra(FileUploadService.KEY_UPLOAD_TYPE,
-                    FileUploadService.UploadSingleMulti.UPLOAD_MULTIPLE_FILES);
+                    FileUploadService.UploadQuantity.UPLOAD_MULTIPLE_FILES);
             if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)
                 i.putExtra(FileUploadService.KEY_LOCAL_BEHAVIOUR, FileUploadService.LocalBehaviour.LOCAL_BEHAVIOUR_MOVE);
             startService(i);
@@ -772,7 +771,7 @@ public class FileDisplayActivity extends HookActivity implements
         i.putExtra(FileUploadService.KEY_REMOTE_FILE, remotePath);
         i.putExtra(FileUploadService.KEY_MIME_TYPE, mimeType);
         i.putExtra(FileUploadService.KEY_UPLOAD_TYPE,
-                FileUploadService.UploadSingleMulti.UPLOAD_SINGLE_FILE);
+                FileUploadService.UploadQuantity.UPLOAD_SINGLE_FILE);
         if (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE) {
             i.putExtra(FileUploadService.KEY_LOCAL_BEHAVIOUR,
                     FileUploadService.LocalBehaviour.LOCAL_BEHAVIOUR_MOVE);
@@ -786,13 +785,8 @@ public class FileDisplayActivity extends HookActivity implements
     /**
      * Request the operation for moving the file/folder from one path to another
      *
-<<<<<<< HEAD
      * @param data              Intent received
      * @param resultCode        Result code received
-=======
-     * @param data       Intent received
-     * @param resultCode Result code received
->>>>>>> master
      */
     private void requestMoveOperation(Intent data, int resultCode) {
         OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);

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

@@ -569,7 +569,7 @@ public class Uploader extends FileActivity
 
                 Intent intent = new Intent(getApplicationContext(), FileUploadService.class);
                 intent.putExtra(FileUploadService.KEY_UPLOAD_TYPE,
-                        FileUploadService.UploadSingleMulti.UPLOAD_MULTIPLE_FILES);
+                        FileUploadService.UploadQuantity.UPLOAD_MULTIPLE_FILES);
                 intent.putExtra(FileUploadService.KEY_LOCAL_FILE,
                         local.toArray(new String[local.size()]));
                 intent.putExtra(FileUploadService.KEY_REMOTE_FILE,
@@ -705,7 +705,7 @@ public class Uploader extends FileActivity
         if (result != null) {
             Intent intent = new Intent(getApplicationContext(), FileUploadService.class);
             intent.putExtra(FileUploadService.KEY_UPLOAD_TYPE,
-                    FileUploadService.UploadSingleMulti.UPLOAD_SINGLE_FILE);
+                    FileUploadService.UploadQuantity.UPLOAD_SINGLE_FILE);
             intent.putExtra(FileUploadService.KEY_LOCAL_FILE, result);
             intent.putExtra(FileUploadService.KEY_REMOTE_FILE, mRemoteCacheData.get(index));
             intent.putExtra(FileUploadService.KEY_ACCOUNT, getAccount());

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

@@ -1,3 +1,22 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
 package com.owncloud.android.ui.adapter;
 
 import java.lang.ref.WeakReference;
@@ -16,7 +35,6 @@ import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.BaseExpandableListAdapter;
-import android.widget.Button;
 import android.widget.ExpandableListView;
 import android.widget.ImageButton;
 import android.widget.ImageView;
@@ -35,7 +53,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.UploadUtils;
 
 /**
  * This Adapter populates a ListView with following types of uploads: pending,
@@ -241,7 +258,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             statusView.setText(status);
 
             ImageButton rightButton = (ImageButton) view.findViewById(R.id.upload_right_button);
-            if (UploadUtils.userCanRetryUpload(uploadObject)
+            if (uploadObject.userCanRetryUpload()
                     && uploadObject.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED) {
                 //Refresh
                 rightButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_action_refresh_grey));
@@ -251,7 +268,7 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
                         parentFileActivity.getFileOperationsHelper().retryUpload(uploadObject);                                        
                     }
                 });
-            } else if (UploadUtils.userCanCancelUpload(uploadObject)) {
+            } else if (uploadObject.userCanCancelUpload()) {
                 //Cancel
                 rightButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_cancel));
                 rightButton.setOnClickListener(new OnClickListener() {                
@@ -275,7 +292,6 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
             ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
             fileIcon.setImageResource(R.drawable.file);
             try {
-                //TODO Wait for https://github.com/owncloud/android/pull/746 and add thumbnail.
                 Bitmap b = ThumbnailsCacheManager.getBitmapFromDiskCache(uploadObject.getOCFile().getRemoteId());
                 if (b != null) {
                     fileIcon.setImageBitmap(b);

+ 23 - 4
src/com/owncloud/android/ui/errorhandling/ErrorShowActivity.java

@@ -1,3 +1,22 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
 package com.owncloud.android.ui.errorhandling;
 
 import android.app.Activity;
@@ -9,9 +28,9 @@ import com.owncloud.android.R;
 
 public class ErrorShowActivity extends Activity {
 
-	private static final String TAG = ErrorShowActivity.class.getName();
+	private static final String TAG = ErrorShowActivity.class.getSimpleName();
 
-	TextView error;
+	TextView mError;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
@@ -19,8 +38,8 @@ public class ErrorShowActivity extends Activity {
 		Log.e(TAG, "ErrorShowActivity was called. See above for StackTrace.");
 		Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
 		setContentView(R.layout.errorhandling_showerror);
-		error = (TextView) findViewById(R.id.errorTextView);
-		error.setText(getIntent().getStringExtra("error"));
+		mError = (TextView) findViewById(R.id.errorTextView);
+		mError.setText(getIntent().getStringExtra("error"));
 
 	}
 }

+ 24 - 5
src/com/owncloud/android/ui/errorhandling/ExceptionHandler.java

@@ -1,3 +1,22 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
 package com.owncloud.android.ui.errorhandling;
 
 import java.io.PrintWriter;
@@ -9,13 +28,13 @@ import android.os.Build;
 import android.util.Log;
 
 public class ExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler {
-	private final Activity myContext;
+	private final Activity mContext;
 	private final String LINE_SEPARATOR = "\n";
 
-	private static final String TAG = ExceptionHandler.class.getName();
+	private static final String TAG = ExceptionHandler.class.getSimpleName();
 
 	public ExceptionHandler(Activity context) {
-		myContext = context;
+		mContext = context;
 	}
 
 	public void uncaughtException(Thread thread, Throwable exception) {
@@ -55,9 +74,9 @@ public class ExceptionHandler implements java.lang.Thread.UncaughtExceptionHandl
 
 		Log.e(TAG, "An exception was thrown and handled by ExceptionHandler:", exception);
 
-		Intent intent = new Intent(myContext, ErrorShowActivity.class);
+		Intent intent = new Intent(mContext, ErrorShowActivity.class);
 		intent.putExtra("error", errorReport.toString());
-		myContext.startActivity(intent);
+		mContext.startActivity(intent);
 
 		android.os.Process.killProcess(android.os.Process.myPid());
 		System.exit(1000);

+ 2 - 2
src/com/owncloud/android/ui/fragment/UploadListFragment.java

@@ -120,7 +120,7 @@ public class UploadListFragment extends ExpandableListFragment {
         int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
         int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
         UploadDbObject uploadFile = (UploadDbObject) mAdapter.getChild(groupPosition, childPosition);
-        if (UploadUtils.userCanCancelUpload(uploadFile)) {
+        if (uploadFile.userCanCancelUpload()) {
             MenuItem item = menu.findItem(R.id.action_remove_upload);
             if (item != null) {
                 item.setVisible(false);
@@ -133,7 +133,7 @@ public class UploadListFragment extends ExpandableListFragment {
                 item.setEnabled(false);
             }
         }
-        if (!UploadUtils.userCanRetryUpload(uploadFile)) {
+        if (!uploadFile.userCanRetryUpload()) {
             MenuItem item = menu.findItem(R.id.action_retry_upload);
             if (item != null) {
                 item.setVisible(false);

+ 20 - 33
src/com/owncloud/android/utils/UploadUtils.java

@@ -1,3 +1,23 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   @author LukeOwncloud
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
 package com.owncloud.android.utils;
 
 import android.content.Context;
@@ -31,38 +51,5 @@ public class UploadUtils {
                 && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
                 && cm.getActiveNetworkInfo().getState() == State.CONNECTED;
     }
-    
-    /**
-     * Returns true when user is able to cancel this upload. That is, when
-     * upload is currently in progress or scheduled for upload.
-     */
-    static public  boolean userCanCancelUpload(UploadDbObject uploadFile) {
-        switch (uploadFile.getUploadStatus()) {
-        case UPLOAD_IN_PROGRESS:
-        case UPLOAD_LATER:
-        case UPLOAD_FAILED_RETRY:
-            return true;
-        default:
-            return false;
-        }
-    }
 
-    /**
-     * Returns true when user can choose to retry this upload. That is, when
-     * user cancelled upload before or when upload has failed.
-     */
-    static public boolean userCanRetryUpload(UploadDbObject uploadFile) {
-        switch (uploadFile.getUploadStatus()) {
-        case UPLOAD_CANCELLED:
-        case UPLOAD_FAILED_RETRY://automatically retried. no need for user option.
-        case UPLOAD_FAILED_GIVE_UP: //TODO this case needs to be handled as described by
-            // https://github.com/owncloud/android/issues/765#issuecomment-66490312
-        case UPLOAD_LATER: //upload is already schedule but allow user to increase priority
-        case UPLOAD_SUCCEEDED: // if user wants let him to re-upload (maybe
-                               // remote file was deleted...)
-            return true;
-        default:
-            return false;
-        }
-    }
 }