Display media in square grid if exactly 4 of them

This commit is contained in:
Sylvain Berfini 2024-12-04 11:23:52 +01:00
parent 3a7265295e
commit 877565e516
4 changed files with 34 additions and 34 deletions

View file

@ -44,6 +44,7 @@ class FileModel @AnyThread constructor(
val isEncrypted: Boolean,
val originalPath: String,
val isWaitingToBeDownloaded: Boolean = false,
val flexboxLayoutWrapBefore: Boolean = false,
private val onClicked: ((model: FileModel) -> Unit)? = null
) {
companion object {

View file

@ -384,6 +384,13 @@ class MessageModel @WorkerThread constructor(
val contents = chatMessage.contents
allFilesDownloaded = true
val notMediaContent = contents.find {
it.isIcalendar || it.isVoiceRecording || (it.isText && !it.isFile) || it.isFileTransfer || (it.isFile && !(it.type == "video" || it.type == "image"))
}
val allContentsAreMedia = notMediaContent == null
val exactly4Contents = contents.size == 4
for (content in contents) {
val isFileEncrypted = content.isFileEncrypted
@ -401,6 +408,7 @@ class MessageModel @WorkerThread constructor(
Log.d("$TAG Found voice recording content")
isVoiceRecord.postValue(true)
computeVoiceRecordContent(content)
displayableContentFound = true
} else {
if (content.isFile) {
@ -424,40 +432,23 @@ class MessageModel @WorkerThread constructor(
"$TAG Found file ready to be displayed [$path] with MIME [${content.type}/${content.subtype}] for message [${chatMessage.messageId}]"
)
val wrapBefore = allContentsAreMedia && filesContentCount == 3
val fileSize = content.fileSize.toLong()
val timestamp = content.creationTimestamp
when (content.type) {
"image", "video" -> {
val fileModel = FileModel(
path,
name,
fileSize,
timestamp,
isFileEncrypted,
originalPath
) { model ->
onContentClicked?.invoke(model)
}
filesPath.add(fileModel)
displayableContentFound = true
}
else -> {
val fileModel = FileModel(
path,
name,
fileSize,
timestamp,
isFileEncrypted,
originalPath
) { model ->
onContentClicked?.invoke(model)
}
filesPath.add(fileModel)
displayableContentFound = true
}
val fileModel = FileModel(
path,
name,
fileSize,
timestamp,
isFileEncrypted,
originalPath,
flexboxLayoutWrapBefore = wrapBefore
) { model ->
onContentClicked?.invoke(model)
}
filesPath.add(fileModel)
displayableContentFound = true
} else {
Log.e("$TAG No path found for File Content!")
}
@ -478,8 +469,7 @@ class MessageModel @WorkerThread constructor(
content.fileSize.toLong(),
timestamp,
isFileEncrypted,
path,
false
path
) { model ->
onContentClicked?.invoke(model)
}
@ -491,7 +481,7 @@ class MessageModel @WorkerThread constructor(
timestamp,
isFileEncrypted,
name,
true
isWaitingToBeDownloaded = true
) { model ->
downloadContent(model, content)
}

View file

@ -58,6 +58,7 @@ import coil.request.videoFrameMillis
import coil.size.Dimension
import coil.transform.CircleCropTransformation
import coil.transform.RoundedCornersTransformation
import com.google.android.flexbox.FlexboxLayout
import org.linphone.BR
import org.linphone.R
import org.linphone.contacts.AbstractAvatarModel
@ -605,6 +606,13 @@ fun validateOnInput(editText: EditText, onValidate: () -> (Unit)) {
})
}
@BindingAdapter("app:layout_wrapBefore")
fun setFlexboxLayoutWrapBefore(view: View, wrap: Boolean = false) {
val params = view.layoutParams as FlexboxLayout.LayoutParams
params.isWrapBefore = wrap
view.layoutParams = params
}
@BindingAdapter("emojiPickedListener")
fun EmojiPickerView.setEmojiPickedListener(listener: EmojiPickedListener) {
setOnEmojiPickedListener { emoji ->

View file

@ -17,6 +17,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_wrapBefore="@{model.flexboxLayoutWrapBefore}"
android:padding="1dp">
<androidx.constraintlayout.widget.Group