Merge remote-tracking branch 'remotes/upstream/avoidDuplicateFiles' into beta
authortobiasKaminsky <tobias@kaminsky.me>
Wed, 2 Dec 2015 19:28:56 +0000 (20:28 +0100)
committertobiasKaminsky <tobias@kaminsky.me>
Wed, 2 Dec 2015 19:28:56 +0000 (20:28 +0100)
12 files changed:
res/values/attrs.xml
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java
src/com/owncloud/android/files/services/FileDownloader.java
src/com/owncloud/android/files/services/FileUploader.java
src/com/owncloud/android/files/services/IndexedForest.java
src/com/owncloud/android/operations/UploadFileOperation.java
src/com/owncloud/android/services/SyncFolderHandler.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/activity/Preferences.java
tests/project.properties

index 7d80983..d51b3c0 100644 (file)
        </declare-styleable>
 
        <string-array name="pref_behaviour_entries">
-               <item>@string/pref_behaviour_entries_do_nothing</item>
-               <item>@string/pref_behaviour_entries_copy</item>
+               <item>@string/pref_behaviour_entries_keep_file</item>
                <item>@string/pref_behaviour_entries_move</item>
-               <item>@string/pref_behaviour_entries_delete</item>
        </string-array>
 
        <string-array name="pref_behaviour_entryValues">
                <item>NOTHING</item>
-               <item>COPY</item>
                <item>MOVE</item>
-               <item>DELETE</item>
        </string-array>
 </resources>
\ No newline at end of file
index 68597bf..1df3a15 100644 (file)
     <string name="pref_cache_size">Cache size</string>
     <string name="prefs_instant_behaviour_dialogTitle">Upload file to server and ...</string>
     <string name="prefs_instant_behaviour_title">Behaviour</string>
+    <string name="prefs_instant_behaviour_dialogTitle">Original file will be...</string>
+    <string name="prefs_instant_behaviour_title">Original file will be...</string>
     <string name="upload_copy_files">Copy file</string>
     <string name="upload_move_files">Move file</string>
     <string name="prefs_storage_path">Storage path</string>
     <string name="stream_expose_password">Do you want to stream this file with an external app?\n\nCAUTION: This may expose your password!</string>
     <string name="set_picture_as">Set picture as</string>
     <string name="set_as">Set As</string>
+    <string name="pref_behaviour_entries_keep_file">kept in original folder</string>
+    <string name="pref_behaviour_entries_move">moved to ownCloud folder</string>
 
     <string name="share_dialog_title">Sharing</string>
     <string name="share_with_user_section_title">Share with users and groups</string>
index 3972e9e..e1876e9 100644 (file)
        </PreferenceCategory>
 
     <PreferenceCategory android:title="@string/prefs_category_instant_uploading" android:key="instant_uploading_category">
-         <com.owncloud.android.ui.dialog.OwnCloudListPreference android:key="prefs_instant_behaviour"
-                        android:dialogTitle="@string/prefs_instant_behaviour_dialogTitle"
-                        android:title="@string/prefs_instant_behaviour_title"
-                        android:entries="@array/pref_behaviour_entries"
-                        android:entryValues="@array/pref_behaviour_entryValues"
-                        android:defaultValue="NOTHING"
-                        android:summary="%s"
-                        />
-
                <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
                                android:title="@string/prefs_instant_upload"
                                android:summary="@string/prefs_instant_upload_summary"/>
                        android:disableDependentsState="true"
                        android:title="@string/instant_video_upload_on_charging"
                        android:key="instant_video_upload_on_charging"/>
+               <com.owncloud.android.ui.dialog.OwnCloudListPreference android:key="prefs_instant_behaviour"
+                       android:dialogTitle="@string/prefs_instant_behaviour_dialogTitle"
+                       android:title="@string/prefs_instant_behaviour_title"
+                       android:entries="@array/pref_behaviour_entries"
+                       android:entryValues="@array/pref_behaviour_entryValues"
+                       android:defaultValue="NOTHING"
+                       android:summary="%s"
+                       />
        </PreferenceCategory>
 
        <PreferenceCategory android:title="@string/common_category" android:key="common_category">
index dc32ecc..d1ffd8f 100644 (file)
@@ -140,17 +140,10 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
         if (behaviour.equalsIgnoreCase("NOTHING")) {
             Log_OC.d(TAG, "upload file and do nothing");
             i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_FORGET);
-        } else if (behaviour.equalsIgnoreCase("COPY")) {
-            i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_COPY);
-            Log_OC.d(TAG, "upload file and copy file to oc folder");
         } else if (behaviour.equalsIgnoreCase("MOVE")) {
             i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_MOVE);
             Log_OC.d(TAG, "upload file and move file to oc folder");
-        } else if (behaviour.equalsIgnoreCase("DELETE")){
-            i.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, FileUploader.LOCAL_BEHAVIOUR_REMOVE);
-            Log_OC.d(TAG, "upload file and delete file in original place");
         }
-
         return i;
     }
 
index b6f21a5..513a639 100644 (file)
@@ -174,10 +174,11 @@ public class FileDownloader extends Service
                 Pair<String, String> putResult = mPendingDownloads.putIfAbsent(
                         account, file.getRemotePath(), newDownload
                 );
-                String downloadKey = putResult.first;
-                requestedDownloads.add(downloadKey);
-
-                sendBroadcastNewDownload(newDownload, putResult.second);
+                if (putResult != null) {
+                    String downloadKey = putResult.first;
+                    requestedDownloads.add(downloadKey);
+                    sendBroadcastNewDownload(newDownload, putResult.second);
+                }   // else, file already in the queue of downloads; don't repeat the request
 
             } catch (IllegalArgumentException e) {
                 Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
index 9bc2742..7937f40 100644 (file)
@@ -103,7 +103,6 @@ public class FileUploader extends Service
     public static final int LOCAL_BEHAVIOUR_COPY = 0;
     public static final int LOCAL_BEHAVIOUR_MOVE = 1;
     public static final int LOCAL_BEHAVIOUR_FORGET = 2;
-    public static final int LOCAL_BEHAVIOUR_REMOVE = 3;
 
     public static final int UPLOAD_SINGLE_FILE = 0;
     public static final int UPLOAD_MULTIPLE_FILES = 1;
@@ -262,7 +261,7 @@ public class FileUploader extends Service
 
         boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
         boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
-        int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_COPY);
+        int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);
 
         if (intent.hasExtra(KEY_FILE) && files == null) {
             Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
@@ -317,8 +316,10 @@ public class FileUploader extends Service
                 Pair<String, String> putResult = mPendingUploads.putIfAbsent(
                         account, files[i].getRemotePath(), newUpload
                 );
-                uploadKey = putResult.first;
-                requestedUploads.add(uploadKey);
+                if (putResult != null) {
+                    uploadKey = putResult.first;
+                    requestedUploads.add(uploadKey);
+                }   // else, file already in the queue of uploads; don't repeat the request
             }
 
         } catch (IllegalArgumentException e) {
index 4c1ac7b..8f4ccb6 100644 (file)
@@ -101,38 +101,45 @@ public class IndexedForest<V> {
     public /* synchronized */ Pair<String, String> putIfAbsent(Account account, String remotePath, V value) {
         String targetKey = buildKey(account, remotePath);
         Node<V> valuedNode = new Node(targetKey, value);
-        mMap.putIfAbsent(
-                targetKey,
-                valuedNode
+        Node<V> previousValue = mMap.putIfAbsent(
+            targetKey,
+            valuedNode
         );
+        if (previousValue != null) {
+            // remotePath already known; not replaced
+            return null;
 
-        String currentPath = remotePath, parentPath = null, parentKey = null;
-        Node<V> currentNode = valuedNode, parentNode = null;
-        boolean linked = false;
-        while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) {
-            parentPath = new File(currentPath).getParent();
-            if (!parentPath.endsWith(OCFile.PATH_SEPARATOR)) {
-                parentPath += OCFile.PATH_SEPARATOR;
+        } else {
+            // value really added
+            String currentPath = remotePath, parentPath = null, parentKey = null;
+            Node<V> currentNode = valuedNode, parentNode = null;
+            boolean linked = false;
+            while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) {
+                parentPath = new File(currentPath).getParent();
+                if (!parentPath.endsWith(OCFile.PATH_SEPARATOR)) {
+                    parentPath += OCFile.PATH_SEPARATOR;
+                }
+                parentKey = buildKey(account, parentPath);
+                parentNode = mMap.get(parentKey);
+                if (parentNode == null) {
+                    parentNode = new Node(parentKey, null);
+                    parentNode.addChild(currentNode);
+                    mMap.put(parentKey, parentNode);
+                } else {
+                    parentNode.addChild(currentNode);
+                    linked = true;
+                }
+                currentPath = parentPath;
+                currentNode = parentNode;
             }
-            parentKey = buildKey(account, parentPath);
-            parentNode = mMap.get(parentKey);
-            if (parentNode == null) {
-                parentNode = new Node(parentKey, null);
-                parentNode.addChild(currentNode);
-                mMap.put(parentKey, parentNode);
-            } else {
-                parentNode.addChild(currentNode);
-                linked = true;
+
+            String linkedTo = OCFile.ROOT_PATH;
+            if (linked) {
+                linkedTo = parentNode.getKey().substring(account.name.length());
             }
-            currentPath = parentPath;
-            currentNode = parentNode;
-        }
 
-        String linkedTo = OCFile.ROOT_PATH;
-        if (linked) {
-            linkedTo = parentNode.getKey().substring(account.name.length());
+            return new Pair<String, String>(targetKey, linkedTo);
         }
-        return new Pair<String, String>(targetKey, linkedTo);
     };
 
 
index 512056b..182ec0b 100644 (file)
@@ -332,10 +332,7 @@ public class UploadFileOperation extends RemoteOperation {
             // location in the ownCloud local folder
             if (result.isSuccess()) {
                 if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) {
-                    mFile.setStoragePath(null);
-                } else if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_REMOVE){
-                    mFile.setStoragePath(null);
-                    originalFile.delete();
+                    mFile.setStoragePath("");
                 } else {
                     mFile.setStoragePath(expectedPath);
                     File fileToMove = null;
index 33318f5..daa1612 100644 (file)
@@ -138,8 +138,11 @@ class SyncFolderHandler extends Handler {
 
     public void add(Account account, String remotePath,
                     SynchronizeFolderOperation syncFolderOperation){
-        mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
-        sendBroadcastNewSyncFolder(account, remotePath);    // TODO upgrade!
+        Pair<String, String> putResult =
+                mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
+        if (putResult != null) {
+            sendBroadcastNewSyncFolder(account, remotePath);    // TODO upgrade!
+        }
     }
 
 
index e69eb04..c51484a 100644 (file)
@@ -1132,7 +1132,7 @@ public class FileDisplayActivity extends HookActivity
         @Override
         public void onReceive(Context context, Intent intent) {
             try {
-                String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
+                String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
                 String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
                 boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
                 OCFile currentDir = getCurrentDir();
@@ -1141,7 +1141,7 @@ public class FileDisplayActivity extends HookActivity
 
                 if (sameAccount && isDescendant) {
                     String linkedToRemotePath =
-                            intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
+                            intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH);
                     if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
                         refreshListOfFilesFragment();
                     }
index 61b4702..d7288c9 100644 (file)
@@ -123,6 +123,7 @@ public class Preferences extends PreferenceActivity
     private String mUploadPath;
     private PreferenceCategory mPrefInstantUploadCategory;
     private Preference mPrefInstantUpload;
+    private Preference mPrefInstantUploadBehaviour;
     private Preference mPrefInstantUploadPath;
     private Preference mPrefInstantUploadPathWiFi;
     private Preference mPrefInstantVideoUpload;
@@ -461,6 +462,9 @@ public class Preferences extends PreferenceActivity
             @Override
             public boolean onPreferenceChange(Preference preference, Object newValue) {
                 toggleInstantPictureOptions((Boolean) newValue);
+                toggleInstantUploadBehaviour(
+                        ((CheckBoxPreference)mPrefInstantVideoUpload).isChecked(),
+                        (Boolean) newValue);
                 return true;
             }
         });
@@ -488,14 +492,22 @@ public class Preferences extends PreferenceActivity
         toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
         
         mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
-            
+
             @Override
             public boolean onPreferenceChange(Preference preference, Object newValue) {
                 toggleInstantVideoOptions((Boolean) newValue);
+                toggleInstantUploadBehaviour(
+                        (Boolean) newValue,
+                        ((CheckBoxPreference) mPrefInstantUpload).isChecked());
                 return true;
             }
         });
-            
+
+        mPrefInstantUploadBehaviour = findPreference("prefs_instant_behaviour");
+        toggleInstantUploadBehaviour(
+                ((CheckBoxPreference)mPrefInstantVideoUpload).isChecked(),
+                ((CheckBoxPreference)mPrefInstantUpload).isChecked());
+
         /* About App */
        pAboutApp = findPreference("about_app");
        if (pAboutApp != null) { 
@@ -607,6 +619,14 @@ public class Preferences extends PreferenceActivity
         }
     }
 
+    private void toggleInstantUploadBehaviour(Boolean video, Boolean picture){
+        if (picture || video){
+            mPrefInstantUploadCategory.addPreference(mPrefInstantUploadBehaviour);
+        } else {
+            mPrefInstantUploadCategory.removePreference(mPrefInstantUploadBehaviour);
+        }
+    }
+
     @Override
     public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
 
index 00cf62b..916037e 100644 (file)
@@ -11,4 +11,4 @@
 #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
 
 # Project target.
-target=android-22
+target=android-23