Fix Cancel Notification Appearance and Progress Bar Visibility

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-01-09 15:56:30 +01:00 committed by Alper Öztürk
parent 5aa41ce510
commit 17cdbc23a8
2 changed files with 20 additions and 7 deletions

View file

@ -102,14 +102,14 @@ class DownloadNotificationManager(
val fileName: String = filePath.substring(filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1)
val text =
String.format(context.getString(R.string.downloader_download_in_progress_content), percent, fileName)
updateNotificationText(text)
updateNotificationText(text, false)
}
}
@Suppress("MagicNumber")
fun showCompleteNotification(text: String) {
Handler(Looper.getMainLooper()).postDelayed({
updateNotificationText(text)
updateNotificationText(text, true)
dismissNotification()
}, 3000)
}
@ -117,7 +117,7 @@ class DownloadNotificationManager(
@Suppress("MagicNumber")
fun dismissNotification() {
Handler(Looper.getMainLooper()).postDelayed({
notificationManager.cancelAll()
notificationManager.cancel(id)
}, 2000)
}
@ -125,13 +125,18 @@ class DownloadNotificationManager(
val notifyId = SecureRandom().nextInt()
notificationBuilder.run {
setProgress(0, 0, false)
setContentText(text)
notificationManager.notify(notifyId, this.build())
}
}
private fun updateNotificationText(text: String) {
private fun updateNotificationText(text: String, cancelProgressBar: Boolean) {
notificationBuilder.run {
if (cancelProgressBar) {
setProgress(0, 0, false)
}
setContentText(text)
notificationManager.notify(id, this.build())
}

View file

@ -114,6 +114,7 @@ class FileDownloadWorker(
private var fileDataStorageManager: FileDataStorageManager? = null
private var folder: OCFile? = null
private var isAnyOperationFailed = false
@Suppress("TooGenericExceptionCaught")
override fun doWork(): Result {
@ -126,8 +127,7 @@ class FileDownloadWorker(
downloadFile(it)
}
showCompleteNotification()
showSuccessNotification()
setIdleWorkerState()
Log_OC.e(TAG, "FilesDownloadWorker successfully completed")
@ -171,7 +171,12 @@ class FileDownloadWorker(
}
@Suppress("MagicNumber")
private fun showCompleteNotification() {
private fun showSuccessNotification() {
if (isAnyOperationFailed) {
notificationManager.dismissNotification()
return
}
val successText = if (folder != null) {
context.getString(R.string.downloader_folder_downloaded, folder?.fileName)
} else if (currentDownload?.file != null) {
@ -184,6 +189,7 @@ class FileDownloadWorker(
}
private fun getRequestDownloads(): AbstractList<String> {
isAnyOperationFailed = false
setUser()
setFolder()
val files = getFiles()
@ -387,6 +393,8 @@ class FileDownloadWorker(
return
}
isAnyOperationFailed = true
val failMessage = if (result.isCancelled) {
context.getString(
R.string.downloader_file_download_cancelled,