Add gif preview support

This commit is contained in:
MichaelArkh 2024-04-24 22:34:11 -04:00
parent c15efff72c
commit 746bd63fa7
3 changed files with 13 additions and 6 deletions

View file

@ -128,4 +128,9 @@ dependencies {
// Image viewer // Image viewer
implementation 'com.github.stfalcon-studio:StfalconImageViewer:v1.0.1' 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'
} }

View file

@ -23,6 +23,7 @@ import androidx.core.view.allViews
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.stfalcon.imageviewer.StfalconImageViewer import com.stfalcon.imageviewer.StfalconImageViewer
import io.heckel.ntfy.R import io.heckel.ntfy.R
@ -176,7 +177,7 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
val attachment = notification.attachment val attachment = notification.attachment
val image = attachment.contentUri != null && supportedImage(attachment.type) && previewableImage(attachmentFileStat) val image = attachment.contentUri != null && supportedImage(attachment.type) && previewableImage(attachmentFileStat)
val bitmap = if (image) attachment.contentUri?.readBitmapFromUriOrNull(context) else null val bitmap = if (image) attachment.contentUri?.readBitmapFromUriOrNull(context) else null
maybeRenderAttachmentImage(context, bitmap) maybeRenderAttachmentImage(context, bitmap, attachment)
maybeRenderAttachmentBox(context, notification, attachment, attachmentFileStat, bitmap) 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) { if (bitmap == null) {
attachmentImageView.visibility = View.GONE attachmentImageView.visibility = View.GONE
return return
} }
try { try {
attachmentImageView.setImageBitmap(bitmap) Glide.with(context).load(attachment.contentUri).fitCenter().into(attachmentImageView)
attachmentImageView.setOnClickListener { attachmentImageView.setOnClickListener {
val loadImage = { view: ImageView, image: Bitmap -> view.setImageBitmap(image) } StfalconImageViewer.Builder<Any?>(context, listOf(bitmap)) { imageView, image ->
StfalconImageViewer.Builder(context, listOf(bitmap), loadImage) Glide.with(context).load(attachment.contentUri).into(imageView)
}
.allowZooming(true) .allowZooming(true)
.withTransitionFrom(attachmentImageView) .withTransitionFrom(attachmentImageView)
.withHiddenStatusBar(false) .withHiddenStatusBar(false)

View file

@ -333,7 +333,7 @@ fun mimeTypeToIconResource(mimeType: String?): Int {
} }
fun supportedImage(mimeType: String?): Boolean { 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. // Google Play doesn't allow us to install received .apk files anymore.