Removed now useless RelativeLayout for chat message bubble

This commit is contained in:
Sylvain Berfini 2022-04-20 13:22:47 +02:00
parent 0c085ed0b5
commit 4aeef970bb
2 changed files with 174 additions and 180 deletions

View file

@ -222,6 +222,7 @@ dependencies {
implementation "androidx.security:security-crypto-ktx:1.1.0-alpha03" implementation "androidx.security:security-crypto-ktx:1.1.0-alpha03"
implementation 'androidx.core:core-splashscreen:1.0.0-beta02' implementation 'androidx.core:core-splashscreen:1.0.0-beta02'
// https://github.com/material-components/material-components-android/blob/master/LICENSE Apache v2.0
implementation 'com.google.android.material:material:1.5.0' implementation 'com.google.android.material:material:1.5.0'
// https://github.com/google/flexbox-layout/blob/main/LICENSE Apache v2.0 // https://github.com/google/flexbox-layout/blob/main/LICENSE Apache v2.0
implementation 'com.google.android.flexbox:flexbox:3.0.0' implementation 'com.google.android.flexbox:flexbox:3.0.0'

View file

@ -4,12 +4,12 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<import type="android.view.View"/> <import type="android.view.View" />
<import type="android.view.Gravity"/> <import type="android.view.Gravity" />
<import type="com.google.android.flexbox.JustifyContent"/> <import type="com.google.android.flexbox.JustifyContent" />
<variable <variable
name="contextMenuClickListener" name="contextMenuClickListener"
type="android.view.View.OnLongClickListener"/> type="android.view.View.OnLongClickListener" />
<variable <variable
name="clickListener" name="clickListener"
type="android.view.View.OnClickListener" /> type="android.view.View.OnClickListener" />
@ -18,7 +18,7 @@
type="android.view.View.OnClickListener" /> type="android.view.View.OnClickListener" />
<variable <variable
name="position" name="position"
type="Integer"/> type="Integer" />
<variable <variable
name="data" name="data"
type="org.linphone.activities.main.chat.data.ChatMessageData" /> type="org.linphone.activities.main.chat.data.ChatMessageData" />
@ -28,26 +28,20 @@
</data> </data>
<RelativeLayout <RelativeLayout
android:onClick="@{clickListener}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:onClick="@{clickListener}">
<!-- Weirdly enough this "useless" RelativeLayout prevents the measuring issue
in child LinearLayout (which size depends on the MultiLineWrapContentWidthTextView) -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox <CheckBox
android:id="@+id/select" android:id="@+id/select"
android:onClick="@{() -> selectionListViewModel.onToggleSelect(position)}"
android:visibility="@{selectionListViewModel.isEditionEnabled ? View.VISIBLE : View.GONE, default=gone}"
android:checked="@{selectionListViewModel.selectedItems.contains(position)}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@id/background" android:layout_alignTop="@id/background"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_marginRight="5dp" /> android:layout_marginRight="5dp"
android:checked="@{selectionListViewModel.selectedItems.contains(position)}"
android:onClick="@{() -> selectionListViewModel.onToggleSelect(position)}"
android:visibility="@{selectionListViewModel.isEditionEnabled ? View.VISIBLE : View.GONE, default=gone}" />
<!-- To align with security badge if visible --> <!-- To align with security badge if visible -->
<View <View
@ -58,165 +52,164 @@
<ImageView <ImageView
android:id="@+id/imdn" android:id="@+id/imdn"
android:visibility="@{data.chatMessage.outgoing ? (data.showImdn ? View.VISIBLE : View.INVISIBLE) : View.INVISIBLE}"
android:src="@{data.imdnIcon, default=@drawable/chat_delivered}"
android:contentDescription="@string/content_description_delivery_status"
android:layout_width="10dp" android:layout_width="10dp"
android:layout_height="10dp" android:layout_height="10dp"
android:layout_alignBottom="@id/background"
android:layout_toLeftOf="@{selectionListViewModel.isEditionEnabled ? @id/select : @id/rightMark}" android:layout_toLeftOf="@{selectionListViewModel.isEditionEnabled ? @id/select : @id/rightMark}"
android:layout_alignBottom="@id/background" /> android:contentDescription="@string/content_description_delivery_status"
android:src="@{data.imdnIcon, default=@drawable/chat_delivered}"
android:visibility="@{data.chatMessage.outgoing ? (data.showImdn ? View.VISIBLE : View.INVISIBLE) : View.INVISIBLE}" />
<org.linphone.contact.ContactAvatarView <org.linphone.contact.ContactAvatarView
android:id="@+id/avatar" android:id="@+id/avatar"
android:visibility="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? View.GONE : (data.hideAvatar ? View.INVISIBLE : View.VISIBLE)}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/time" android:layout_below="@id/time"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:gravity="center" android:gravity="center"
android:visibility="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? View.GONE : (data.hideAvatar ? View.INVISIBLE : View.VISIBLE)}"
app:data="@{data}" app:data="@{data}"
tools:layout="@layout/contact_avatar" /> tools:layout="@layout/contact_avatar" />
<LinearLayout <LinearLayout
android:id="@+id/background" android:id="@+id/background"
android:onClick="@{clickListener}"
android:onLongClick="@{contextMenuClickListener}"
backgroundImage="@{data.backgroundRes, default=@drawable/chat_bubble_outgoing_full}" backgroundImage="@{data.backgroundRes, default=@drawable/chat_bubble_outgoing_full}"
android:descendantFocusability="blocksDescendants"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_below="@id/time"
android:layout_marginLeft="@{selectionListViewModel.isEditionEnabled ? @dimen/edit_chat_message_bubble_left_margin : !data.chatMessage.outgoing ? @dimen/incoming_chat_message_bubble_left_margin : @dimen/outgoing_chat_message_bubble_left_margin}"
android:layout_marginRight="@{data.chatMessage.outgoing ? @dimen/outgoing_chat_message_bubble_right_margin : @dimen/incoming_chat_message_bubble_right_margin}"
android:layout_marginBottom="1dp"
android:layout_toLeftOf="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? @id/imdn : 0}" android:layout_toLeftOf="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? @id/imdn : 0}"
android:layout_toRightOf="@id/avatar" android:layout_toRightOf="@id/avatar"
android:layout_below="@id/time" android:descendantFocusability="blocksDescendants"
android:layout_marginBottom="1dp" android:onClick="@{clickListener}"
android:layout_marginRight="@{data.chatMessage.outgoing ? @dimen/outgoing_chat_message_bubble_right_margin : @dimen/incoming_chat_message_bubble_right_margin}" android:onLongClick="@{contextMenuClickListener}"
android:layout_marginLeft="@{selectionListViewModel.isEditionEnabled ? @dimen/edit_chat_message_bubble_left_margin : !data.chatMessage.outgoing ? @dimen/incoming_chat_message_bubble_left_margin : @dimen/outgoing_chat_message_bubble_left_margin}" android:orientation="vertical"
android:paddingBottom="5dp"> android:paddingBottom="5dp">
<TextView <TextView
android:visibility="@{data.chatMessage.forward ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:drawablePadding="3dp"
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:lineSpacingExtra="3.3sp"
android:text="@string/chat_message_forwarded"
android:textColor="@color/chat_bubble_text_color" android:textColor="@color/chat_bubble_text_color"
android:textSize="10sp" android:textSize="10sp"
android:fontFamily="sans-serif"
android:textStyle="normal" android:textStyle="normal"
android:lineSpacingExtra="3.3sp" android:visibility="@{data.chatMessage.forward ? View.VISIBLE : View.GONE, default=gone}"
android:drawablePadding="3dp" app:drawableLeftCompat="@drawable/icon_forwarded_message"
android:text="@string/chat_message_forwarded" tools:ignore="SmallSp" />
tools:ignore="SmallSp"
android:gravity="center_vertical"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
app:drawableLeftCompat="@drawable/icon_forwarded_message" />
<TextView <TextView
android:visibility="@{data.chatMessage.reply ? View.VISIBLE : View.GONE, default=gone}"
android:gravity="center_vertical"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/chat_bubble_text_color" android:layout_marginLeft="5dp"
android:textSize="10sp" android:layout_marginTop="5dp"
android:drawablePadding="3dp"
android:fontFamily="sans-serif" android:fontFamily="sans-serif"
android:textStyle="normal" android:gravity="center_vertical"
android:lineSpacingExtra="3.3sp" android:lineSpacingExtra="3.3sp"
android:text="@string/chat_message_replied" android:text="@string/chat_message_replied"
tools:ignore="SmallSp" android:textColor="@color/chat_bubble_text_color"
android:drawablePadding="3dp" android:textSize="10sp"
app:drawableLeftCompat="@drawable/icon_replied_message" /> android:textStyle="normal"
android:visibility="@{data.chatMessage.reply ? View.VISIBLE : View.GONE, default=gone}"
app:drawableLeftCompat="@drawable/icon_replied_message"
tools:ignore="SmallSp" />
<include layout="@layout/chat_message_reply_bubble" <include
layout="@layout/chat_message_reply_bubble"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_gravity="@{data.chatMessage.outgoing ? Gravity.RIGHT : Gravity.LEFT}" android:layout_gravity="@{data.chatMessage.outgoing ? Gravity.RIGHT : Gravity.LEFT}"
app:data="@{data.replyData}" android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:visibility="@{data.replyData != null ? View.VISIBLE : View.GONE, default=gone}"
app:clickListener="@{replyClickListener}" app:clickListener="@{replyClickListener}"
android:visibility="@{data.replyData != null ? View.VISIBLE : View.GONE, default=gone}" /> app:data="@{data.replyData}" />
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:longClickable="true" android:longClickable="true"
app:entries="@{data.contents}"
app:layout="@{@layout/chat_message_content_cell}"
app:onLongClick="@{contextMenuClickListener}"
app:flexWrap="wrap"
app:alignItems="center" app:alignItems="center"
app:justifyContent="@{data.chatMessage.outgoing ? JustifyContent.FLEX_END : JustifyContent.FLEX_START}"/> app:entries="@{data.contents}"
app:flexWrap="wrap"
app:justifyContent="@{data.chatMessage.outgoing ? JustifyContent.FLEX_END : JustifyContent.FLEX_START}"
app:layout="@{@layout/chat_message_content_cell}"
app:onLongClick="@{contextMenuClickListener}" />
<org.linphone.activities.main.chat.views.MultiLineWrapContentWidthTextView <org.linphone.activities.main.chat.views.MultiLineWrapContentWidthTextView
android:onClick="@{clickListener}"
android:onLongClick="@{contextMenuClickListener}"
android:text="@{data.text}"
android:visibility="@{data.text.length > 0 ? View.VISIBLE : View.GONE}"
android:layout_gravity="@{data.chatMessage.outgoing ? Gravity.RIGHT : Gravity.LEFT}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="@{data.chatMessage.outgoing ? Gravity.RIGHT : Gravity.LEFT}"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:fontFamily="sans-serif"
android:lineSpacingExtra="-1.7sp"
android:longClickable="true" android:longClickable="true"
android:onClick="@{clickListener}"
android:onLongClick="@{contextMenuClickListener}"
android:text="@{data.text}"
android:textColor="@color/dark_grey_color" android:textColor="@color/dark_grey_color"
android:textSize="15sp" android:textSize="15sp"
android:fontFamily="sans-serif"
android:textStyle="normal" android:textStyle="normal"
android:lineSpacingExtra="-1.7sp"/> android:visibility="@{data.text.length > 0 ? View.VISIBLE : View.GONE}" />
<TextView <TextView
android:visibility="@{data.chatMessage.ephemeral ? View.VISIBLE : View.GONE, default=gone}"
android:text="@{data.ephemeralLifetime, default=`00:00`}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="right"
android:gravity="center_vertical|right"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawablePadding="3dp" android:drawablePadding="3dp"
android:fontFamily="sans-serif"
android:gravity="center_vertical|right"
android:lineSpacingExtra="3.3sp"
android:text="@{data.ephemeralLifetime, default=`00:00`}"
android:textColor="@color/primary_color" android:textColor="@color/primary_color"
android:textSize="12sp" android:textSize="12sp"
android:fontFamily="sans-serif"
android:textStyle="normal" android:textStyle="normal"
android:lineSpacingExtra="3.3sp" android:visibility="@{data.chatMessage.ephemeral ? View.VISIBLE : View.GONE, default=gone}"
app:drawableRightCompat="@drawable/icon_ephemeral_message" /> app:drawableRightCompat="@drawable/icon_ephemeral_message" />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:id="@+id/time" android:id="@+id/time"
android:text="@{data.chatMessage.outgoing ? data.time : data.time + ` - ` + (data.contact.name ?? data.displayName)}"
android:visibility="@{data.hideTime ? View.GONE : View.VISIBLE}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignLeft="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? 0 : @id/background}" android:layout_alignLeft="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? 0 : @id/background}"
android:layout_alignRight="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? @id/background : 0}" android:layout_alignRight="@{data.chatMessage.outgoing || selectionListViewModel.isEditionEnabled ? @id/background : 0}"
android:layout_alignParentTop="true"
android:layout_marginTop="7dp" android:layout_marginTop="7dp"
android:fontFamily="sans-serif"
android:lineSpacingExtra="0sp"
android:text="@{data.chatMessage.outgoing ? data.time : data.time + ` - ` + (data.contact.name ?? data.displayName)}"
android:textColor="@color/chat_bubble_text_color" android:textColor="@color/chat_bubble_text_color"
android:textSize="13sp" android:textSize="13sp"
android:fontFamily="sans-serif"
android:textStyle="normal" android:textStyle="normal"
android:lineSpacingExtra="0sp" /> android:visibility="@{data.hideTime ? View.GONE : View.VISIBLE}" />
<ProgressBar <ProgressBar
android:visibility="@{data.transferInProgress || data.sendInProgress ? View.VISIBLE : View.GONE}"
android:layout_width="10dp" android:layout_width="10dp"
android:layout_height="10dp" android:layout_height="10dp"
android:layout_toRightOf="@id/background"
android:layout_alignBottom="@id/background" android:layout_alignBottom="@id/background"
android:indeterminateTint="?attr/accentColor" /> android:layout_toRightOf="@id/background"
android:indeterminateTint="?attr/accentColor"
</RelativeLayout> android:visibility="@{data.transferInProgress || data.sendInProgress ? View.VISIBLE : View.GONE}" />
</RelativeLayout> </RelativeLayout>