diff --git a/app/src/main/java/io/heckel/ntfy/msg/DownloadManager.kt b/app/src/main/java/io/heckel/ntfy/msg/DownloadManager.kt index 8655dc2..4ff45e2 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/DownloadManager.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/DownloadManager.kt @@ -18,13 +18,13 @@ class DownloadManager { private const val TAG = "NtfyDownloadManager" private const val DOWNLOAD_WORK_NAME_PREFIX = "io.heckel.ntfy.DOWNLOAD_FILE_" - fun enqueue(context: Context, id: String, userAction: Boolean) { + fun enqueue(context: Context, notificationId: String, userAction: Boolean) { val workManager = WorkManager.getInstance(context) - val workName = DOWNLOAD_WORK_NAME_PREFIX + id - Log.d(TAG,"Enqueuing work to download attachment for notification $id, work: $workName") + val workName = DOWNLOAD_WORK_NAME_PREFIX + notificationId + Log.d(TAG,"Enqueuing work to download attachment for notification $notificationId, work: $workName") val workRequest = OneTimeWorkRequest.Builder(DownloadWorker::class.java) .setInputData(workDataOf( - DownloadWorker.INPUT_DATA_ID to id, + DownloadWorker.INPUT_DATA_ID to notificationId, DownloadWorker.INPUT_DATA_USER_ACTION to userAction )) .build() diff --git a/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt b/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt index 1a7e0b5..8bd5f2b 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/NotificationDispatcher.kt @@ -49,15 +49,20 @@ class NotificationDispatcher(val context: Context, val repository: Repository) { if (notification.attachment == null) { return false } + val attachment = notification.attachment + if (attachment.expires != null && attachment.expires < System.currentTimeMillis()/1000) { + Log.d(TAG, "Attachment already expired at ${attachment.expires}, not downloading") + return false + } val maxAutoDownloadSize = repository.getAutoDownloadMaxSize() when (maxAutoDownloadSize) { Repository.AUTO_DOWNLOAD_ALWAYS -> return true Repository.AUTO_DOWNLOAD_NEVER -> return false else -> { - if (notification.attachment.size == null) { + if (attachment.size == null) { return true // DownloadWorker will bail out if attachment is too large! } - return notification.attachment.size <= maxAutoDownloadSize + return attachment.size <= maxAutoDownloadSize } } } diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailAdapter.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailAdapter.kt index d007032..6029d16 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailAdapter.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailAdapter.kt @@ -305,7 +305,13 @@ class DetailAdapter(private val activity: Activity, private val repository: Repo infos.add(context.getString(R.string.detail_item_download_info_deleted)) } } else if (failed) { - infos.add(context.getString(R.string.detail_item_download_info_download_failed)) + if (expired) { + infos.add(context.getString(R.string.detail_item_download_info_download_failed_expired)) + } else if (expires) { + infos.add(context.getString(R.string.detail_item_download_info_download_failed_expires_x, formatDateShort(attachment.expires!!))) + } else { + infos.add(context.getString(R.string.detail_item_download_info_download_failed)) + } } return if (infos.size > 0) { "$name\n${infos.joinToString(", ")}" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6bc8392..e2cd1a4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -156,6 +156,8 @@ deleted, link expired deleted, link expires %1$s download failed + download failed, link expired + download failed, link expires %1$s Notifications enabled diff --git a/fastlane/metadata/android/en-US/changelog/22.txt b/fastlane/metadata/android/en-US/changelog/22.txt index 188322a..b48eecd 100644 --- a/fastlane/metadata/android/en-US/changelog/22.txt +++ b/fastlane/metadata/android/en-US/changelog/22.txt @@ -1,3 +1,6 @@ Features: * Dark theme: Improvements around style and contrast (#119, thanks @kzshantonu for reporting) * Automatically delete notifications (#71, thanks @arjan-s for reporting) + +Bug fixes: +* Do not attempt to download attachments if they are already expired (#135)