feat: Show a preview for playable audio attachments (#426)

This commit is contained in:
Nik Clayton 2024-02-06 19:38:50 +01:00 committed by GitHub
parent 7fc8a5fb1e
commit 5a51310af8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 7 deletions

View File

@ -517,9 +517,8 @@ abstract class StatusBaseViewHolder<T : IStatusViewData> 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<T : IStatusViewData> protected constructor(i
companion object {
@JvmStatic
protected fun hasPreviewableAttachment(attachments: List<Attachment>): 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<T : IStatusViewData> 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
}