From 433fad761a7f3777e8a622f01c2428606d6eaaf7 Mon Sep 17 00:00:00 2001 From: Hunter Kehoe Date: Tue, 6 Sep 2022 21:42:40 -0600 Subject: [PATCH] remove attachment download limit if userAction --- .../io/heckel/ntfy/msg/DownloadAttachmentWorker.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/heckel/ntfy/msg/DownloadAttachmentWorker.kt b/app/src/main/java/io/heckel/ntfy/msg/DownloadAttachmentWorker.kt index bc22e9d..cffd591 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/DownloadAttachmentWorker.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/DownloadAttachmentWorker.kt @@ -82,11 +82,7 @@ class DownloadAttachmentWorker(private val context: Context, params: WorkerParam Log.d(TAG, "Starting download to content URI: $uri") var bytesCopied: Long = 0 val outFile = resolver.openOutputStream(uri) ?: throw Exception("Cannot open output stream") - val downloadLimit = if (repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_NEVER && repository.getAutoDownloadMaxSize() != Repository.AUTO_DOWNLOAD_ALWAYS) { - repository.getAutoDownloadMaxSize() - } else { - null - } + val downloadLimit = getDownloadLimit(userAction) outFile.use { fileOut -> val fileIn = response.body!!.byteStream() val buffer = ByteArray(BUFFER_SIZE) @@ -192,6 +188,14 @@ class DownloadAttachmentWorker(private val context: Context, params: WorkerParam } } + private fun getDownloadLimit(userAction: Boolean): Long? { + return if (userAction || repository.getAutoDownloadMaxSize() == Repository.AUTO_DOWNLOAD_ALWAYS) { + null + } else { + repository.getAutoDownloadMaxSize() + } + } + private fun createUri(notification: Notification): Uri { val attachmentDir = File(context.cacheDir, ATTACHMENT_CACHE_DIR) if (!attachmentDir.exists() && !attachmentDir.mkdirs()) {