Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@
android:name="com.nextcloud.client.jobs.folderDownload.FolderDownloadWorkerReceiver"
android:exported="false" />

<receiver
android:name="com.nextcloud.client.jobs.download.FileDownloadCancelReceiver"
android:exported="false" />

<activity
android:name=".ui.activity.CopyToClipboardActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,35 @@ class DownloadNotificationManager(id: Int, private val context: Context, viewThe
setContentTitle(currentOperationTitle)
setOngoing(false)
setProgress(100, 0, operation.size < 0)
clearActions()
addAction(
R.drawable.ic_cancel,
context.getString(R.string.common_cancel),
getCancelPendingIntent(operation)
)
}

showNotification()
}

private fun getCancelPendingIntent(operation: DownloadFileOperation): PendingIntent {
val intent = Intent(context, FileDownloadCancelReceiver::class.java).apply {
putExtra(FileDownloadCancelReceiver.ACCOUNT_NAME, operation.user.accountName)
putExtra(FileDownloadCancelReceiver.FILE_ID, operation.file.fileId)
setPackage(context.packageName)
}

return PendingIntent.getBroadcast(
context,
getId(),
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}

fun prepareForResult() {
notificationBuilder
.clearActions()
.setAutoCancel(true)
.setOngoing(false)
.setProgress(0, 0, false)
Expand All @@ -61,6 +83,7 @@ class DownloadNotificationManager(id: Int, private val context: Context, viewThe
val notifyId = SecureRandom().nextInt()

notificationBuilder.run {
clearActions()
setProgress(0, 0, false)
setContentTitle(text)
setOngoing(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.nextcloud.client.jobs.download

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.owncloud.android.lib.common.utils.Log_OC

class FileDownloadCancelReceiver : BroadcastReceiver() {

companion object {
private const val TAG = "FileDownloadCancelReceiver"
private const val INVALID_FILE_ID = -1L

const val ACCOUNT_NAME = "ACCOUNT_NAME"
const val FILE_ID = "FILE_ID"
}

override fun onReceive(context: Context, intent: Intent) {
val accountName = intent.getStringExtra(ACCOUNT_NAME)
if (accountName.isNullOrEmpty()) {
return
}

val fileId = intent.getLongExtra(FILE_ID, INVALID_FILE_ID)
if (fileId == INVALID_FILE_ID) {
return
}

Log_OC.d(TAG, "cancelling download of file: $fileId")
FileDownloadWorker.cancelOperation(accountName, fileId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class FileDownloadWorker(
private fun showDownloadErrorNotification(downloadError: FileDownloadError) {
val text = when (downloadError) {
FileDownloadError.Cancelled -> {
context.getString(R.string.downloader_file_download_cancelled)
context.getString(R.string.downloader_download_canceled)
}

FileDownloadError.Failed -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class DownloadFileOperation(
private val cancellationRequested = AtomicBoolean(false)
private val mainThreadHandler = Handler(Looper.getMainLooper())

@Volatile
private var downloadOperation: DownloadFileRemoteOperation? = null

constructor(user: User, file: OCFile, context: Context?) : this(
user,
file,
Expand Down Expand Up @@ -165,6 +168,8 @@ class DownloadFileOperation(
if (downloadType == DownloadType.DOWNLOAD) {
dataTransferListeners.forEach { op.addProgressListener(it) }
}
downloadOperation = op
if (cancellationRequested.get()) op.cancel()
}
val result = operation.execute(client.toNextcloudClient(operationContext)) as RemoteOperationResult<Unit>
return DownloadResult(operation, result)
Expand Down Expand Up @@ -261,6 +266,7 @@ class DownloadFileOperation(

fun cancel() {
cancellationRequested.set(true)
downloadOperation?.cancel()
}

fun addProgressListener(listener: OnDatatransferProgressListener) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
<string name="downloader_download_failed_ticker">Download failed</string>
<string name="downloader_download_failed_content">Could not download %1$s</string>
<string name="downloader_not_downloaded_yet">Not downloaded yet</string>
<string name="downloader_file_download_cancelled">Certain files were canceled during the download by user</string>
<string name="downloader_download_canceled">Download canceled</string>
<string name="downloader_file_download_failed">Error occurred while downloading files</string>
<string name="downloader_unexpected_error">Unexpected error occurred while downloading files</string>
<string name="downloader_download_failed_credentials_error">Download failed, log in again</string>
Expand Down
Loading