Skip to content

Commit

Permalink
feat: Show a preview for playable audio attachments (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikclayton authored Feb 6, 2024
1 parent 7fc8a5f commit 5a51310
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit 5a51310

Please sign in to comment.