From: tobiasKaminsky Date: Wed, 2 Dec 2015 19:28:56 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/avoidDuplicateFiles' into beta X-Git-Tag: beta-20151202~2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/deb1e48fc01a9750cc55429ff290e6f6ac025bf4?hp=2eecb46250300a470fa20caee27b2b04a1e0ea49 Merge remote-tracking branch 'remotes/upstream/avoidDuplicateFiles' into beta --- diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 7d809835..d51b3c08 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -12,16 +12,12 @@ - @string/pref_behaviour_entries_do_nothing - @string/pref_behaviour_entries_copy + @string/pref_behaviour_entries_keep_file @string/pref_behaviour_entries_move - @string/pref_behaviour_entries_delete NOTHING - COPY MOVE - DELETE \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 68597bfb..1df3a152 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -394,6 +394,8 @@ Cache size Upload file to server and ... Behaviour + Original file will be... + Original file will be... Copy file Move file Storage path @@ -413,6 +415,8 @@ Do you want to stream this file with an external app?\n\nCAUTION: This may expose your password! Set picture as Set As + kept in original folder + moved to ownCloud folder Sharing Share with users and groups diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 3972e9e3..e1876e94 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -31,15 +31,6 @@ - - @@ -76,6 +67,14 @@ android:disableDependentsState="true" android:title="@string/instant_video_upload_on_charging" android:key="instant_video_upload_on_charging"/> + diff --git a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java index dc32ecc0..d1ffd8f6 100644 --- a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java +++ b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java @@ -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; } diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index b6f21a5c..513a639f 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -174,10 +174,11 @@ public class FileDownloader extends Service Pair 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()); diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 9bc2742e..7937f409 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -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 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) { diff --git a/src/com/owncloud/android/files/services/IndexedForest.java b/src/com/owncloud/android/files/services/IndexedForest.java index 4c1ac7bd..8f4ccb67 100644 --- a/src/com/owncloud/android/files/services/IndexedForest.java +++ b/src/com/owncloud/android/files/services/IndexedForest.java @@ -101,38 +101,45 @@ public class IndexedForest { public /* synchronized */ Pair putIfAbsent(Account account, String remotePath, V value) { String targetKey = buildKey(account, remotePath); Node valuedNode = new Node(targetKey, value); - mMap.putIfAbsent( - targetKey, - valuedNode + Node previousValue = mMap.putIfAbsent( + targetKey, + valuedNode ); + if (previousValue != null) { + // remotePath already known; not replaced + return null; - String currentPath = remotePath, parentPath = null, parentKey = null; - Node 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 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(targetKey, linkedTo); } - return new Pair(targetKey, linkedTo); }; diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index 512056ba..182ec0b3 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -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; diff --git a/src/com/owncloud/android/services/SyncFolderHandler.java b/src/com/owncloud/android/services/SyncFolderHandler.java index 33318f57..daa16128 100644 --- a/src/com/owncloud/android/services/SyncFolderHandler.java +++ b/src/com/owncloud/android/services/SyncFolderHandler.java @@ -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 putResult = + mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation); + if (putResult != null) { + sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade! + } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index e69eb047..c51484ae 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -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(); } diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index 61b4702e..d7288c91 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -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) { diff --git a/tests/project.properties b/tests/project.properties index 00cf62ba..916037e3 100644 --- a/tests/project.properties +++ b/tests/project.properties @@ -11,4 +11,4 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-22 +target=android-23