From 5a51310af8f5491f126284246f50fa6424bccd3c Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Tue, 6 Feb 2024 19:38:50 +0100 Subject: [PATCH] feat: Show a preview for playable audio attachments (#426) --- .../pachli/adapter/StatusBaseViewHolder.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt b/app/src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt index a3765e58d..0fb660ad1 100644 --- a/app/src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt +++ b/app/src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt @@ -517,9 +517,8 @@ abstract class StatusBaseViewHolder protected constructor(i if (useBlurhash) attachment.blurhash else null, ) val type = attachment.type - if (showingContent && (type === Attachment.Type.VIDEO || type === Attachment.Type.GIFV)) { - imageView.foreground = - ContextCompat.getDrawable(context, R.drawable.play_indicator_overlay) + if (showingContent && type.isPlayable()) { + imageView.foreground = ContextCompat.getDrawable(context, R.drawable.play_indicator_overlay) } else { imageView.foreground = null } @@ -900,10 +899,8 @@ abstract class StatusBaseViewHolder protected constructor(i companion object { @JvmStatic protected fun hasPreviewableAttachment(attachments: List): Boolean { - for ((_, _, _, _, type) in attachments) { - if (type === Attachment.Type.AUDIO || type === Attachment.Type.UNKNOWN) { - return false - } + for (attachment in attachments) { + if (attachment.type == Attachment.Type.UNKNOWN) return false } return true } @@ -940,3 +937,12 @@ abstract class StatusBaseViewHolder protected constructor(i } } } + +/** + * @return True if this attachment type is playable and should show the playable indicator, + * otherwise false. + */ +fun Attachment.Type.isPlayable() = when (this) { + Attachment.Type.AUDIO, Attachment.Type.GIFV, Attachment.Type.VIDEO -> true + Attachment.Type.IMAGE, Attachment.Type.UNKNOWN -> false +}