From 746bd63fa7fed0f7bdfbe2f03f858e9326e318c7 Mon Sep 17 00:00:00 2001 From: MichaelArkh Date: Wed, 24 Apr 2024 22:34:11 -0400 Subject: [PATCH] Add gif preview support --- app/build.gradle | 5 +++++ app/src/main/java/io/heckel/ntfy/ui/DetailAdapter.kt | 12 +++++++----- app/src/main/java/io/heckel/ntfy/util/Util.kt | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 90dc1ed..3588321 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -128,4 +128,9 @@ dependencies { // Image viewer implementation 'com.github.stfalcon-studio:StfalconImageViewer:v1.0.1' + + //Glide + implementation 'com.github.bumptech.glide:glide:4.16.0' + kapt 'com.github.bumptech.glide:compiler:4.16.0' + } 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 0b56803..717f9c6 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailAdapter.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailAdapter.kt @@ -23,6 +23,7 @@ import androidx.core.view.allViews import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide import com.google.android.material.button.MaterialButton import com.stfalcon.imageviewer.StfalconImageViewer import io.heckel.ntfy.R @@ -176,7 +177,7 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope: val attachment = notification.attachment val image = attachment.contentUri != null && supportedImage(attachment.type) && previewableImage(attachmentFileStat) val bitmap = if (image) attachment.contentUri?.readBitmapFromUriOrNull(context) else null - maybeRenderAttachmentImage(context, bitmap) + maybeRenderAttachmentImage(context, bitmap, attachment) maybeRenderAttachmentBox(context, notification, attachment, attachmentFileStat, bitmap) } @@ -351,16 +352,17 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope: } } - private fun maybeRenderAttachmentImage(context: Context, bitmap: Bitmap?) { + private fun maybeRenderAttachmentImage(context: Context, bitmap: Bitmap?, attachment: Attachment) { if (bitmap == null) { attachmentImageView.visibility = View.GONE return } try { - attachmentImageView.setImageBitmap(bitmap) + Glide.with(context).load(attachment.contentUri).fitCenter().into(attachmentImageView) attachmentImageView.setOnClickListener { - val loadImage = { view: ImageView, image: Bitmap -> view.setImageBitmap(image) } - StfalconImageViewer.Builder(context, listOf(bitmap), loadImage) + StfalconImageViewer.Builder(context, listOf(bitmap)) { imageView, image -> + Glide.with(context).load(attachment.contentUri).into(imageView) + } .allowZooming(true) .withTransitionFrom(attachmentImageView) .withHiddenStatusBar(false) diff --git a/app/src/main/java/io/heckel/ntfy/util/Util.kt b/app/src/main/java/io/heckel/ntfy/util/Util.kt index 2ffbb76..20c7f9f 100644 --- a/app/src/main/java/io/heckel/ntfy/util/Util.kt +++ b/app/src/main/java/io/heckel/ntfy/util/Util.kt @@ -333,7 +333,7 @@ fun mimeTypeToIconResource(mimeType: String?): Int { } fun supportedImage(mimeType: String?): Boolean { - return listOf("image/jpeg", "image/png").contains(mimeType) + return listOf("image/jpeg", "image/png", "image/gif").contains(mimeType) } // Google Play doesn't allow us to install received .apk files anymore.