From 6ec6d990ffb2fff83783230e01149a00623eee66 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 17 Oct 2025 12:39:21 +0200 Subject: [PATCH 1/3] add: chunk upload listener Signed-off-by: alperozturk --- .../lib/resources/files/ChunkUploadListener.kt | 12 ++++++++++++ .../files/ChunkedFileUploadRemoteOperation.java | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt new file mode 100644 index 0000000000..d562ac12d3 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt @@ -0,0 +1,12 @@ +/* + * Nextcloud Android Library + * + * SPDX-FileCopyrightText: 2025 Alper Ozturk + * SPDX-License-Identifier: MIT + */ + +package com.owncloud.android.lib.resources.files + +interface ChunkUploadListener { + fun onChunkStarted(chunk: Chunk) +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java index 818c4e0e4a..6efa868bce 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java @@ -50,6 +50,7 @@ public class ChunkedFileUploadRemoteOperation extends UploadFileRemoteOperation private final boolean onWifiConnection; private String uploadFolderUri; private String destinationUri; + private ChunkUploadListener chunkUploadListener; public ChunkedFileUploadRemoteOperation(String storagePath, String remotePath, @@ -117,6 +118,10 @@ public ChunkedFileUploadRemoteOperation(String storagePath, this.onWifiConnection = onWifiConnection; } + public void setChunkUploadListener(ChunkUploadListener listener) { + chunkUploadListener = listener; + } + protected static Chunk calcNextChunk(long fileSize, int chunkId, long startByte, long chunkSize) { if (chunkId < 0 || String.valueOf(chunkId).length() > CHUNK_NAME_LENGTH) { throw new IllegalArgumentException( @@ -198,6 +203,10 @@ protected RemoteOperationResult run(OwnCloudClient client) { // determine size of next chunk Chunk chunk = calcNextChunk(file.length(), ++lastId, nextByte, chunkSize); + if (chunkUploadListener != null) { + chunkUploadListener.onChunkStarted(chunk); + } + RemoteOperationResult chunkResult = uploadChunk(client, chunk); if (!chunkResult.isSuccess()) { return chunkResult; From 7f5d4fa82e2d3a12aadec4f3e703f69a4fe6f966 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 17 Oct 2025 13:26:45 +0200 Subject: [PATCH 2/3] add: chunk upload listener Signed-off-by: alperozturk --- .../android/lib/resources/files/ChunkUploadListener.kt | 2 +- .../resources/files/ChunkedFileUploadRemoteOperation.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt index d562ac12d3..81500d7060 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkUploadListener.kt @@ -8,5 +8,5 @@ package com.owncloud.android.lib.resources.files interface ChunkUploadListener { - fun onChunkStarted(chunk: Chunk) + fun isCancelled(): Boolean = false } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java index 6efa868bce..88b8d23ea5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java @@ -203,17 +203,17 @@ protected RemoteOperationResult run(OwnCloudClient client) { // determine size of next chunk Chunk chunk = calcNextChunk(file.length(), ++lastId, nextByte, chunkSize); - if (chunkUploadListener != null) { - chunkUploadListener.onChunkStarted(chunk); + if (chunkUploadListener != null && chunkUploadListener.isCancelled()) { + return new RemoteOperationResult<>(new OperationCancelledException()); } - RemoteOperationResult chunkResult = uploadChunk(client, chunk); + final var chunkResult = uploadChunk(client, chunk); if (!chunkResult.isSuccess()) { return chunkResult; } if (cancellationRequested.get()) { - return new RemoteOperationResult(new OperationCancelledException()); + return new RemoteOperationResult<>(new OperationCancelledException()); } nextByte += chunk.getLength(); From 1dae051f1710dfff07f0e2bf0468c70d68ea75b2 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 17 Oct 2025 13:27:12 +0200 Subject: [PATCH 3/3] add: chunk upload listener Signed-off-by: alperozturk --- .../resources/files/ChunkedFileUploadRemoteOperation.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java index 88b8d23ea5..fbc4dc6652 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java @@ -203,7 +203,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { // determine size of next chunk Chunk chunk = calcNextChunk(file.length(), ++lastId, nextByte, chunkSize); - if (chunkUploadListener != null && chunkUploadListener.isCancelled()) { + if (cancellationRequested.get() || (chunkUploadListener != null && chunkUploadListener.isCancelled())) { return new RemoteOperationResult<>(new OperationCancelledException()); } @@ -212,10 +212,6 @@ protected RemoteOperationResult run(OwnCloudClient client) { return chunkResult; } - if (cancellationRequested.get()) { - return new RemoteOperationResult<>(new OperationCancelledException()); - } - nextByte += chunk.getLength(); }