diff --git a/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt b/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt
index 705e8d4ef1..65ab584a0b 100644
--- a/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt
+++ b/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt
@@ -32,6 +32,7 @@ import com.owncloud.android.AbstractOnServerIT
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.OCUpload
+import com.owncloud.android.lib.common.operations.OperationCancelledException
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
import com.owncloud.android.lib.resources.files.model.RemoteFile
import com.owncloud.android.operations.UploadFileOperation
@@ -397,4 +398,109 @@ class FileUploaderIT : AbstractOnServerIT() {
assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
}
+
+ /**
+ * uploads a file with "skip if exists" option set, so do nothing if file exists
+ */
+ @Test
+ fun testCancelServer() {
+ val file = getDummyFile("/chunkedFile.txt")
+ val ocUpload = OCUpload(file.absolutePath, "/testFile.txt", account.name)
+
+ assertTrue(
+ UploadFileOperation(
+ uploadsStorageManager,
+ connectivityServiceMock,
+ powerManagementServiceMock,
+ user,
+ null,
+ ocUpload,
+ FileUploader.NameCollisionPolicy.CANCEL,
+ FileUploader.LOCAL_BEHAVIOUR_COPY,
+ targetContext,
+ false,
+ false
+ )
+ .setRemoteFolderToBeCreated()
+ .execute(client, storageManager)
+ .isSuccess
+ )
+
+ val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
+ assertTrue(result.isSuccess)
+
+ assertEquals(file.length(), (result.data[0] as RemoteFile).length)
+
+ val ocUpload2 = OCUpload(getDummyFile("/empty.txt").absolutePath, "/testFile.txt", account.name)
+
+ val uploadResult = UploadFileOperation(
+ uploadsStorageManager,
+ connectivityServiceMock,
+ powerManagementServiceMock,
+ user,
+ null,
+ ocUpload2,
+ FileUploader.NameCollisionPolicy.CANCEL,
+ FileUploader.LOCAL_BEHAVIOUR_COPY,
+ targetContext,
+ false,
+ false
+ )
+ .execute(client, storageManager)
+
+ assertFalse(uploadResult.isSuccess)
+ assertTrue(uploadResult.exception is OperationCancelledException)
+
+ val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
+ assertTrue(result2.isSuccess)
+
+ assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
+ }
+
+ /**
+ * uploads a file with "skip if exists" option set, so do nothing if file exists
+ */
+ @Test
+ fun testKeepCancelStatic() {
+ val file = getDummyFile("/chunkedFile.txt")
+
+ FileUploader.uploadNewFile(
+ targetContext,
+ account,
+ file.absolutePath,
+ "/testFile.txt",
+ FileUploader.LOCAL_BEHAVIOUR_COPY,
+ null,
+ true,
+ UploadFileOperation.CREATED_BY_USER,
+ false,
+ false,
+ FileUploader.NameCollisionPolicy.DEFAULT
+ )
+
+ longSleep()
+
+ val result = ReadFileRemoteOperation("/testFile.txt").execute(client)
+ assertTrue(result.isSuccess)
+
+ assertEquals(file.length(), (result.data[0] as RemoteFile).length)
+
+ val ocFile2 = OCFile("/testFile.txt")
+ ocFile2.setStoragePath(getDummyFile("/empty.txt").absolutePath)
+
+ FileUploader.uploadUpdateFile(
+ targetContext,
+ account,
+ ocFile2,
+ FileUploader.LOCAL_BEHAVIOUR_COPY,
+ FileUploader.NameCollisionPolicy.CANCEL
+ )
+
+ shortSleep()
+
+ val result2 = ReadFileRemoteOperation("/testFile.txt").execute(client)
+ assertTrue(result2.isSuccess)
+
+ assertEquals(file.length(), (result2.data[0] as RemoteFile).length)
+ }
}
diff --git a/src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java
index 0f3a21f782..3610ecc464 100644
--- a/src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java
+++ b/src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java
@@ -26,7 +26,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
-import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.style.StyleSpan;
@@ -113,11 +112,11 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
}
@Override
- public void onAttach(Activity activity) {
+ public void onAttach(@NonNull Activity activity) {
super.onAttach(activity);
if (!(activity instanceof OnSyncedFolderPreferenceListener)) {
throw new IllegalArgumentException("The host activity must implement "
- + OnSyncedFolderPreferenceListener.class.getCanonicalName());
+ + OnSyncedFolderPreferenceListener.class.getCanonicalName());
}
}
@@ -584,7 +583,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
/**
* Get index for name collision selection dialog.
- * @return 0 if ASK_USER, 1 if OVERWRITE, 2 if RENAME. Otherwise: 0
+ * @return 0 if ASK_USER, 1 if OVERWRITE, 2 if RENAME, 3 if SKIP, Otherwise: 0
*/
static private Integer getSelectionIndexForNameCollisionPolicy(FileUploader.NameCollisionPolicy nameCollisionPolicy) {
switch (nameCollisionPolicy) {
@@ -592,6 +591,8 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
return 1;
case RENAME:
return 2;
+ case CANCEL:
+ return 3;
case ASK_USER:
default:
return 0;
@@ -599,9 +600,9 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
}
/**
- * Get index for name collision selection dialog.
- * Inverse of getSelectionIndexForNameCollisionPolicy.
- * @return ASK_USER if 0, OVERWRITE if 1, RENAME if 2. Otherwise: ASK_USEr
+ * Get index for name collision selection dialog. Inverse of getSelectionIndexForNameCollisionPolicy.
+ *
+ * @return ASK_USER if 0, OVERWRITE if 1, RENAME if 2, SKIP if 3. Otherwise: ASK_USER
*/
static private FileUploader.NameCollisionPolicy getNameCollisionPolicyForSelectionIndex(int index) {
switch (index) {
@@ -609,6 +610,8 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
return FileUploader.NameCollisionPolicy.OVERWRITE;
case 2:
return FileUploader.NameCollisionPolicy.RENAME;
+ case 3:
+ return FileUploader.NameCollisionPolicy.CANCEL;
case 0:
default:
return FileUploader.NameCollisionPolicy.ASK_USER;
diff --git a/src/main/res/values/attrs.xml b/src/main/res/values/attrs.xml
index b58518a81a..30e8f30c00 100644
--- a/src/main/res/values/attrs.xml
+++ b/src/main/res/values/attrs.xml
@@ -16,5 +16,6 @@
- @string/pref_instant_name_collision_policy_entries_always_ask
- @string/pref_instant_name_collision_policy_entries_overwrite
- @string/pref_instant_name_collision_policy_entries_rename
+ - @string/pref_instant_name_collision_policy_entries_cancel
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 878c048d5e..92cf6a22b6 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -459,6 +459,7 @@
Ask me every time
Rename new version
Overwrite remote version
+ Skip uploading
Sharing
Share %1$s