Fixed crash when newly received/sent message should update group with last one in history + improved outgoing bubble background

This commit is contained in:
Sylvain Berfini 2023-11-28 10:36:39 +01:00
parent b10b51f839
commit 6badcc2887
8 changed files with 19 additions and 28 deletions

View file

@ -209,7 +209,9 @@ class ConversationEventAdapter : ListAdapter<EventLogModel, RecyclerView.ViewHol
} else if (!oldItem.isEvent && !newItem.isEvent) {
val oldModel = (oldItem.model as MessageModel)
val newModel = (newItem.model as MessageModel)
oldModel.statusIcon.value == newModel.statusIcon.value
oldModel.statusIcon.value == newModel.statusIcon.value &&
oldModel.isGroupedWithNextOne == newModel.isGroupedWithNextOne &&
oldModel.isGroupedWithPreviousOne == newModel.isGroupedWithPreviousOne
} else {
false
}

View file

@ -106,11 +106,7 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
val lastEvent = events.value.orEmpty().lastOrNull()
if (lastEvent != null && shouldWeGroupTwoEvents(eventLog, lastEvent.eventLog)) {
list.remove(lastEvent)
val eventsLogsArray = arrayOf<EventLog>()
eventsLogsArray[0] = lastEvent.eventLog
eventsLogsArray[1] = eventLog
val eventsLogsArray = arrayOf(lastEvent.eventLog, eventLog)
val newList = getEventsListFromHistory(
eventsLogsArray,
searchFilter.value.orEmpty().trim()
@ -156,15 +152,8 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
if (lastEvent != null && shouldWeGroupTwoEvents(eventLogs.first(), lastEvent.eventLog)) {
list.remove(lastEvent)
val eventsLogsArray = arrayOf<EventLog>()
eventsLogsArray[0] = lastEvent.eventLog
var index = 1
for (eventLog in eventLogs) {
eventsLogsArray[index] = eventLog
index += 1
}
val firstElement = arrayOf(lastEvent.eventLog)
val eventsLogsArray = firstElement.plus(eventLogs)
val newList = getEventsListFromHistory(
eventsLogsArray,
searchFilter.value.orEmpty().trim()
@ -418,7 +407,7 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
avatar,
groupChatRoom,
index > 0,
index == groupedEventLogs.size - 1,
index != groupedEventLogs.size - 1,
{ file ->
fileToDisplayEvent.postValue(Event(file))
},

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/shape_chat_bubble_outgoing_first_with_border" />
<item
android:drawable="@drawable/shape_chat_bubble_outgoing_first" />
</selector>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/shape_chat_bubble_outgoing_last_with_border" />
<item
android:drawable="@drawable/shape_chat_bubble_outgoing_last" />
</selector>

View file

@ -214,7 +214,7 @@
android:layout_height="wrap_content"
android:text="@{model.time, default=`13:40`}"
android:textSize="12sp"
android:visibility="@{model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"/>
android:visibility="@{!model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"/>
<ImageView
style="@style/default_text_style_300"
@ -225,7 +225,7 @@
android:layout_marginStart="5dp"
android:layout_marginTop="2dp"
android:src="@{model.statusIcon, default=@drawable/checks}"
android:visibility="@{model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"
android:visibility="@{!model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"
app:tint="@color/orange_main_500" />
</LinearLayout>

View file

@ -101,7 +101,7 @@
android:orientation="vertical"
android:gravity="end"
android:selected="@{model.isSelected}"
android:background="@{model.isGroupedWithPreviousOne ? @drawable/chat_bubble_outgoing_full_background : @drawable/chat_bubble_outgoing_first_background, default=@drawable/chat_bubble_outgoing_first_background}"
android:background="@{model.isGroupedWithNextOne ? @drawable/chat_bubble_outgoing_full_background : @drawable/chat_bubble_outgoing_last_background, default=@drawable/chat_bubble_outgoing_last_background}"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintWidth_max="@dimen/chat_bubble_max_width"
app:layout_constraintTop_toBottomOf="@id/reply"
@ -176,7 +176,7 @@
android:layout_height="wrap_content"
android:text="@{model.time, default=`13:40`}"
android:textSize="12sp"
android:visibility="@{model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"/>
android:visibility="@{!model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"/>
<ImageView
style="@style/default_text_style_300"
@ -187,7 +187,7 @@
android:layout_marginStart="5dp"
android:layout_marginTop="2dp"
android:src="@{model.statusIcon, default=@drawable/checks}"
android:visibility="@{model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"
android:visibility="@{!model.isGroupedWithNextOne ? View.VISIBLE : View.GONE}"
app:tint="@color/orange_main_500" />
</LinearLayout>