Fixed chat message attachment when failing to get video preview picture to display

This commit is contained in:
Sylvain Berfini 2023-05-23 13:53:20 +02:00
parent e841a8fbc8
commit 09f5f4f254
7 changed files with 105 additions and 74 deletions

View file

@ -33,6 +33,7 @@ Group changes to describe their impact on the project, as follows:
### Fixed
- Messages not marked as reply in basic chat room if sending more than 1 content
- Chat message video attachment display when failing to get a preview picture
## [5.0.12] - 2023-05-23

View file

@ -339,7 +339,7 @@ fun setImageViewScaleType(imageView: ImageView, scaleType: ImageView.ScaleType)
@BindingAdapter("coilRounded")
fun loadRoundImageWithCoil(imageView: ImageView, path: String?) {
if (path != null && path.isNotEmpty() && FileUtils.isExtensionImage(path)) {
if (!path.isNullOrEmpty() && FileUtils.isExtensionImage(path)) {
imageView.load(path) {
transformations(CircleCropTransformation())
}
@ -350,7 +350,7 @@ fun loadRoundImageWithCoil(imageView: ImageView, path: String?) {
@BindingAdapter("coil")
fun loadImageWithCoil(imageView: ImageView, path: String?) {
if (path != null && path.isNotEmpty() && FileUtils.isExtensionImage(path)) {
if (!path.isNullOrEmpty() && FileUtils.isExtensionImage(path)) {
if (corePreferences.vfsEnabled && path.startsWith(corePreferences.vfsCachePath)) {
imageView.load(path) {
diskCachePolicy(CachePolicy.DISABLED)
@ -547,9 +547,23 @@ fun loadAvatarWithCoil(imageView: ImageView, path: String?) {
@BindingAdapter("coilVideoPreview")
fun loadVideoPreview(imageView: ImageView, path: String?) {
if (path != null && path.isNotEmpty() && FileUtils.isExtensionVideo(path)) {
if (!path.isNullOrEmpty() && FileUtils.isExtensionVideo(path)) {
imageView.load(path) {
videoFrameMillis(0)
listener(
onError = { _, result ->
Log.e(
"[Data Binding] [Coil] Error getting preview picture from video? [$path]: ${result.throwable}"
)
},
onSuccess = { _, _ ->
// Display "play" button above video preview
LayoutInflater.from(imageView.context).inflate(
R.layout.video_play_button,
imageView.parent as ViewGroup
)
}
)
}
}
}

View file

@ -14,8 +14,15 @@
android:layout_margin="5dp"
android:orientation="vertical">
<View
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="?attr/backgroundColor"/>
<ImageView
android:visibility="@{data.image ? View.VISIBLE : View.GONE}"
android:visibility="@{data.image ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_pending_file_transfer"
android:layout_width="100dp"
android:layout_height="100dp"
@ -25,8 +32,25 @@
android:scaleType="centerCrop"
coil="@{data.path}"/>
<TextView
android:visibility="@{data.video ? View.VISIBLE : View.GONE, default=gone}"
style="@style/chat_file_attachment_font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:ellipsize="middle"
android:singleLine="true"
android:padding="10dp"
android:gravity="center"
android:textAlignment="center"
android:drawablePadding="5dp"
android:drawableTop="@drawable/file_video"
android:text="@{data.fileName, default=`test.mkv`}"/>
<ImageView
android:visibility="@{data.video ? View.VISIBLE : View.GONE}"
android:visibility="@{data.video ? View.VISIBLE : View.GONE, default=gone}"
android:contentDescription="@string/content_description_pending_file_transfer"
android:layout_width="100dp"
android:layout_height="100dp"
@ -36,41 +60,22 @@
android:scaleType="centerCrop"
coilVideoPreview="@{data.path}"/>
<ImageView
android:visibility="@{data.video ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="@dimen/play_pause_button_size"
android:layout_height="@dimen/play_pause_button_size"
android:padding="9dp"
android:src="@drawable/record_play_dark"
android:background="@drawable/round_recording_button_background_dark"
android:contentDescription="@string/content_description_chat_message_video_attachment"
android:layout_centerInParent="true"/>
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
<TextView
style="@style/chat_file_attachment_font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:ellipsize="middle"
android:singleLine="true"
android:padding="10dp"
android:gravity="center"
android:background="?attr/backgroundColor"
android:visibility="@{data.image || data.video ? View.GONE : View.VISIBLE}">
<TextView
style="@style/chat_file_attachment_font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:ellipsize="middle"
android:singleLine="true"
android:padding="10dp"
android:gravity="center"
android:textAlignment="center"
android:drawablePadding="5dp"
android:drawableTop="@{data.pdf ? @drawable/file_pdf : (data.audio ? @drawable/file_audio : @drawable/file), default=@drawable/file}"
android:text="@{data.fileName, default=`test.txt`}"/>
</LinearLayout>
android:textAlignment="center"
android:drawablePadding="5dp"
android:drawableTop="@{data.pdf ? @drawable/file_pdf : (data.audio ? @drawable/file_audio : @drawable/file), default=@drawable/file}"
android:visibility="@{data.image || data.video ? View.GONE : View.VISIBLE, default=gone}"
android:text="@{data.fileName, default=`test.txt`}"/>
<ImageView
android:onClick="@{() -> data.delete()}"

View file

@ -26,6 +26,15 @@
android:scaleType="@{ScaleType.CENTER_CROP}"
android:adjustViewBounds="true" />
<ImageView
android:layout_width="@dimen/chat_message_small_bubble_file_size"
android:layout_height="@dimen/chat_message_small_bubble_file_size"
android:background="@drawable/chat_bubble_reply_file_background"
android:contentDescription="@{data.fileName}"
android:padding="10dp"
android:src="@drawable/file_video"
android:visibility="@{data.video ? View.VISIBLE : View.GONE, default=gone}" />
<ImageView
android:contentDescription="@string/content_description_downloaded_file_transfer"
android:layout_width="wrap_content"
@ -37,16 +46,6 @@
android:scaleType="@{ScaleType.CENTER_CROP}"
android:adjustViewBounds="true" />
<ImageView
android:visibility="@{data.video ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="@dimen/play_pause_button_size"
android:layout_height="@dimen/play_pause_button_size"
android:padding="9dp"
android:src="@drawable/record_play_dark"
android:background="@drawable/round_recording_button_background_dark"
android:contentDescription="@string/content_description_chat_message_video_attachment"
android:layout_centerInParent="true"/>
<TextView
android:visibility="@{data.isVoiceRecording ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="wrap_content"

View file

@ -24,6 +24,16 @@
android:scaleType="@{ScaleType.CENTER_CROP}"
android:adjustViewBounds="true" />
<ImageView
android:layout_width="@dimen/chat_message_small_bubble_file_size"
android:layout_height="@dimen/chat_message_small_bubble_file_size"
android:layout_margin="5dp"
android:background="@drawable/chat_bubble_reply_file_background"
android:contentDescription="@{data.fileName}"
android:padding="10dp"
android:src="@drawable/file_video"
android:visibility="@{data.video ? View.VISIBLE : View.GONE, default=gone}" />
<ImageView
android:contentDescription="@string/content_description_downloaded_file_transfer"
android:layout_width="@dimen/chat_message_small_bubble_file_size"
@ -34,17 +44,6 @@
android:scaleType="@{ScaleType.CENTER_CROP}"
android:adjustViewBounds="true" />
<ImageView
android:visibility="@{data.video ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="@dimen/play_pause_button_size"
android:layout_height="@dimen/play_pause_button_size"
android:layout_margin="5dp"
android:padding="9dp"
android:src="@drawable/record_play_dark"
android:background="@drawable/round_recording_button_background_dark"
android:contentDescription="@string/content_description_chat_message_video_attachment"
android:layout_centerInParent="true"/>
<TextView
android:visibility="@{data.isVoiceRecording ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="wrap_content"
@ -74,10 +73,7 @@
<ImageView
android:layout_width="@dimen/chat_message_small_bubble_file_size"
android:layout_height="@dimen/chat_message_small_bubble_file_size"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_margin="5dp"
android:background="@drawable/chat_bubble_reply_file_background"
android:contentDescription="@{data.fileName}"
android:padding="10dp"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View" />
@ -19,7 +20,22 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{inflatedVisibility}"
inflatedLifecycleOwner="@{true}">
inflatedLifecycleOwner="@{true}"
android:background="?attr/backgroundColor">
<TextView
style="@style/chat_file_attachment_font"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="middle"
android:singleLine="true"
android:padding="10dp"
android:gravity="center"
android:textAlignment="center"
android:drawablePadding="5dp"
android:text="@{data.fileName, default=`test.mkv`}"
app:drawableTopCompat="@drawable/file_video" />
<ImageView
android:onClick="@{() -> data.openFile()}"
@ -33,15 +49,6 @@
android:scaleType="@{data.alone ? ScaleType.FIT_CENTER : ScaleType.CENTER_CROP}"
android:adjustViewBounds="true" />
<ImageView
android:layout_width="@dimen/play_pause_button_size"
android:layout_height="@dimen/play_pause_button_size"
android:padding="9dp"
android:src="@drawable/record_play_dark"
android:background="@drawable/round_recording_button_background_dark"
android:contentDescription="@string/content_description_chat_message_video_attachment"
android:layout_centerInParent="true"/>
</RelativeLayout>
</layout>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/play_pause_button_size"
android:layout_height="@dimen/play_pause_button_size"
android:padding="9dp"
android:src="@drawable/record_play_dark"
android:background="@drawable/round_recording_button_background_dark"
android:contentDescription="@null"
android:layout_centerInParent="true"/>