diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt b/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt index 1457e603fb8e..a1083e537019 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/DownloadNotificationManager.kt @@ -53,6 +53,7 @@ class DownloadNotificationManager(private val context: Context, private val view setContentText(context.resources.getString(R.string.worker_download)) setSmallIcon(R.drawable.notification_icon) setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_icon)) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD) } @@ -117,6 +118,26 @@ class DownloadNotificationManager(private val context: Context, private val view ) } + fun notifyForFolderResult(isAnyOperationFailed: Boolean, folderName: String) { + val notifyId = SecureRandom().nextInt() + val message = if (!isAnyOperationFailed) { + context.getString(R.string.downloader_folder_downloaded, folderName) + } else { + context.getString(R.string.downloader_folder_download_failed, folderName) + } + + notificationBuilder.run { + setContentText(message) + notificationManager.notify(notifyId, this.build()) + } + + NotificationUtils.cancelWithDelay( + notificationManager, + notifyId, + 2000 + ) + } + private fun getResultText(result: RemoteOperationResult<*>, download: DownloadFileOperation): String { return if (result.isSuccess) { download.file.fileName diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt index c6c4eae88ebc..b89dbfd792ab 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt @@ -57,7 +57,7 @@ import java.util.Vector @Suppress("LongParameterList", "TooManyFunctions") class FileDownloadWorker( - private val viewThemeUtils: ViewThemeUtils, + viewThemeUtils: ViewThemeUtils, private val accountManager: UserAccountManager, private val uploadsStorageManager: UploadsStorageManager, private var localBroadcastManager: LocalBroadcastManager, @@ -68,7 +68,7 @@ class FileDownloadWorker( companion object { private val TAG = FileDownloadWorker::class.java.simpleName - const val FOLDER_ID = "FOLDER_ID" + const val FOLDER = "FOLDER" const val USER_NAME = "USER" const val FILE = "FILE" const val FILES = "FILES" @@ -103,6 +103,8 @@ class FileDownloadWorker( private var storageManager: FileDataStorageManager? = null private var downloadClient: OwnCloudClient? = null private var user: User? = null + private var folder: OCFile? = null + private var isAnyOperationFailed = true private val gson = Gson() private val pendingDownloads = IndexedForest() @@ -119,6 +121,9 @@ class FileDownloadWorker( } setIdleWorkerState() + folder?.let { + notifyForFolderResult(it) + } Log_OC.e(TAG, "FilesDownloadWorker successfully completed") Result.success() @@ -139,11 +144,16 @@ class FileDownloadWorker( super.onStopped() } + private fun notifyForFolderResult(folder: OCFile) { + notificationManager.notifyForFolderResult(isAnyOperationFailed, folder.fileName) + } + private fun getRequestDownloads(): AbstractList { val files = getFiles() val downloadType = getDownloadType() setUser() + folder = gson.fromJson(inputData.keyValueMap[FOLDER] as? String, OCFile::class.java) ?: null conflictUploadId = inputData.keyValueMap[CONFLICT_UPLOAD_ID] as Long? val behaviour = inputData.keyValueMap[BEHAVIOUR] as String? ?: "" val activityName = inputData.keyValueMap[ACTIVITY_NAME] as String? ?: "" @@ -312,6 +322,10 @@ class FileDownloadWorker( } private fun cleanupDownloadProcess(result: RemoteOperationResult<*>?) { + result?.let { + isAnyOperationFailed = !it.isSuccess + } + val removeResult = pendingDownloads.removePayload( currentDownload?.user?.accountName, currentDownload?.remotePath @@ -321,11 +335,13 @@ class FileDownloadWorker( currentDownload?.run { notifyDownloadResult(this, downloadResult) + val downloadFinishedIntent = intents.downloadFinishedIntent( this, downloadResult, removeResult.second ) + localBroadcastManager.sendBroadcast(downloadFinishedIntent) } } @@ -353,7 +369,9 @@ class FileDownloadWorker( setContentIntent(intents.detailsIntent(null), PendingIntent.FLAG_IMMUTABLE) } - notifyForResult(downloadResult, download) + if (folder == null) { + notifyForResult(downloadResult, download) + } } } diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt index caf4e4fd0bf3..fafc632deee4 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt @@ -522,7 +522,7 @@ internal class BackgroundJobManagerImpl( override fun startFolderDownloadJob(folder: OCFile, user: User, files: List) { val data = workDataOf( FileDownloadWorker.USER_NAME to user.accountName, - FileDownloadWorker.FOLDER_ID to folder.fileId, + FileDownloadWorker.FOLDER to gson.toJson(folder), FileDownloadWorker.FILES to gson.toJson(files), FileDownloadWorker.DOWNLOAD_TYPE to DownloadType.DOWNLOAD.toString() ) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index d54374c1c4e0..fa290e500d4f 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1585,7 +1585,6 @@ protected ServiceConnection newTransferenceServiceConnection() { return new ListServiceConnection(); } - // FIXME ServiceConnection will not trigger anymore /** * Defines callbacks for service binding, passed to bindService() */ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad817caff92b..1657a79e527a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -174,6 +174,8 @@ Download failed Could not download %1$s Not downloaded yet + Error occurred while downloading %s folder + %s folder successfully downloaded Download failed, log in again Choose account Switch account