Started proto for IMDNs display

This commit is contained in:
Sylvain Berfini 2023-10-18 17:05:41 +02:00
parent 0defb639c2
commit be908cdf0e
12 changed files with 260 additions and 10 deletions

View file

@ -47,6 +47,10 @@ class ConversationEventAdapter(
val chatMessageLongPressEvent = MutableLiveData<Event<ChatMessageModel>>()
val showDeliveryForChatMessageModelEvent: MutableLiveData<Event<ChatMessageModel>> by lazy {
MutableLiveData<Event<ChatMessageModel>>()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
INCOMING_CHAT_MESSAGE -> createIncomingChatBubble(parent)
@ -116,6 +120,10 @@ class ConversationEventAdapter(
true
}
setShowDeliveryInfoClickListener {
showDeliveryForChatMessageModelEvent.value = Event(message)
}
lifecycleOwner = viewLifecycleOwner
executePendingBindings()
}

View file

@ -177,6 +177,16 @@ class ConversationFragment : GenericFragment() {
emojisBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
emojisBottomSheetBehavior.isDraggable = false // To allow scrolling through the emojis
val imdnBottomSheetBehavior = BottomSheetBehavior.from(binding.deliveryBottomSheet.root)
imdnBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
adapter.showDeliveryForChatMessageModelEvent.observe(viewLifecycleOwner) {
it.consume { model ->
binding.deliveryBottomSheet.model = model
imdnBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}
}
binding.setOpenFilePickerClickListener {
Log.i("$TAG Opening media picker")
pickMedia.launch(

View file

@ -0,0 +1,14 @@
package org.linphone.ui.main.chat.model
import androidx.annotation.WorkerThread
import org.linphone.core.Friend
import org.linphone.core.ParticipantImdnState
import org.linphone.ui.main.contacts.model.ContactAvatarModel
import org.linphone.utils.TimestampUtils
class ChatMessageDeliveryModel @WorkerThread constructor(
friend: Friend,
imdnState: ParticipantImdnState
) : ContactAvatarModel(friend) {
val time = TimestampUtils.toString(imdnState.stateChangeTime)
}

View file

@ -28,6 +28,7 @@ import org.linphone.core.Address
import org.linphone.core.ChatMessage
import org.linphone.core.ChatMessageListenerStub
import org.linphone.core.ChatMessageReaction
import org.linphone.core.ParticipantImdnState
import org.linphone.core.tools.Log
import org.linphone.ui.main.contacts.model.ContactAvatarModel
import org.linphone.utils.Event
@ -59,6 +60,8 @@ class ChatMessageModel @WorkerThread constructor(
val chatRoomIsReadOnly = chatMessage.chatRoom.isReadOnly
val deliveryModels = MutableLiveData<ArrayList<ChatMessageDeliveryModel>>()
val dismissLongPressMenuEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
@ -85,6 +88,8 @@ class ChatMessageModel @WorkerThread constructor(
init {
chatMessage.addListener(chatMessageListener)
computeStatusIcon(chatMessage.state)
computeDeliveryStatus()
}
@WorkerThread
@ -102,10 +107,6 @@ class ChatMessageModel @WorkerThread constructor(
}
}
@UiThread
fun showDeliveryInfo() {
}
@WorkerThread
private fun computeStatusIcon(state: ChatMessage.State) {
val icon = when (state) {
@ -127,4 +128,35 @@ class ChatMessageModel @WorkerThread constructor(
}
statusIcon.postValue(icon)
}
@WorkerThread
private fun computeDeliveryStatus() {
val list = arrayListOf<ChatMessageDeliveryModel>()
for (participant in chatMessage.getParticipantsByImdnState(ChatMessage.State.Displayed)) {
list.add(getDeliveryModelForAddress(participant))
}
deliveryModels.postValue(list)
}
@WorkerThread
private fun getDeliveryModelForAddress(participantImdnState: ParticipantImdnState): ChatMessageDeliveryModel {
val address = participantImdnState.participant.address
Log.i("$TAG Looking for participant model with address [${address.asStringUriOnly()}]")
val clone = address.clone()
clone.clean()
val friend = coreContext.contactsManager.findContactByAddress(clone)
val avatar = if (friend != null) {
ChatMessageDeliveryModel(friend, participantImdnState)
} else {
val fakeFriend = coreContext.core.createFriend()
fakeFriend.address = clone
ChatMessageDeliveryModel(fakeFriend, participantImdnState)
}
return avatar
}
}

View file

@ -33,7 +33,6 @@ class ParticipantModel @WorkerThread constructor(
val isParticipantAdmin: Boolean,
private val onMenuClicked: ((view: View, model: ParticipantModel) -> Unit)? = null
) : ContactAvatarModel(friend) {
val sipUri = address.asStringUriOnly()
@UiThread

View file

@ -10,6 +10,9 @@
<variable
name="onLongClickListener"
type="View.OnLongClickListener" />
<variable
name="showDeliveryInfoClickListener"
type="View.OnClickListener" />
<variable
name="model"
type="org.linphone.ui.main.chat.model.ChatMessageModel" />
@ -86,7 +89,7 @@
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style_300"
android:id="@+id/date_time"
android:onClick="@{() -> model.showDeliveryInfo()}"
android:onClick="@{showDeliveryInfoClickListener}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
@ -100,7 +103,7 @@
<ImageView
style="@style/default_text_style_300"
android:id="@+id/delivery_status"
android:onClick="@{() -> model.showDeliveryInfo()}"
android:onClick="@{showDeliveryInfoClickListener}"
android:layout_width="@dimen/small_icon_size"
android:layout_height="@dimen/small_icon_size"
android:layout_marginStart="5dp"

View file

@ -75,7 +75,6 @@
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style_300"
android:id="@+id/date_time"
android:onClick="@{() -> model.showDeliveryInfo()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
@ -91,7 +90,6 @@
<ImageView
style="@style/default_text_style_300"
android:id="@+id/delivery_status"
android:onClick="@{() -> model.showDeliveryInfo()}"
android:layout_width="@dimen/small_icon_size"
android:layout_height="@dimen/small_icon_size"
android:layout_marginEnd="18dp"

View file

@ -222,6 +222,10 @@
android:visibility="@{viewModel.isReadOnly ? View.GONE : View.VISIBLE}"
layout="@layout/chat_conversation_send_area"/>
<include
android:id="@+id/delivery_bottom_sheet"
layout="@layout/chat_message_delivery_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

View file

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<import type="org.linphone.core.ConsolidatedPresence" />
<import type="org.linphone.core.ChatRoom.SecurityLevel" />
<variable
name="model"
type="org.linphone.ui.main.chat.model.ChatMessageDeliveryModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/primary_cell_background"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
<com.google.android.material.imageview.ShapeableImageView
style="@style/avatar_imageview"
android:id="@+id/avatar"
android:layout_width="@dimen/avatar_list_cell_size"
android:layout_height="@dimen/avatar_list_cell_size"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
coilAvatar="@{model}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/presence_badge"
android:layout_width="@dimen/avatar_presence_badge_size"
android:layout_height="@dimen/avatar_presence_badge_size"
android:layout_marginEnd="@dimen/avatar_presence_badge_end_margin"
android:background="@drawable/led_background"
android:padding="@dimen/avatar_presence_badge_padding"
app:presenceIcon="@{model.presenceStatus}"
android:visibility="@{model.presenceStatus == ConsolidatedPresence.Offline ? View.GONE : View.VISIBLE}"
app:layout_constraintEnd_toEndOf="@id/avatar"
app:layout_constraintBottom_toBottomOf="@id/avatar"/>
<ImageView
android:id="@+id/trust_badge"
android:layout_width="@dimen/avatar_presence_badge_size"
android:layout_height="@dimen/avatar_presence_badge_size"
android:src="@{model.trust == SecurityLevel.Safe ? @drawable/trusted : @drawable/not_trusted, default=@drawable/trusted}"
android:visibility="@{model.trust == SecurityLevel.Safe || model.trust == SecurityLevel.Unsafe ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="@id/avatar"
app:layout_constraintBottom_toBottomOf="@id/avatar"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@{model.name, default=`John Doe`}"
android:textSize="14sp"
android:layout_marginStart="10dp"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintStart_toEndOf="@id/avatar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/date_time"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style_300"
android:id="@+id/date_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@{model.time, default=`16:18`}"
android:textSize="12sp"
android:textColor="@color/gray_main2_600"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/name"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginEnd="10dp"
android:background="@color/gray_main2_200"
app:layout_constraintStart_toStartOf="@id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<variable
name="handleClickedListener"
type="View.OnClickListener" />
<variable
name="model"
type="org.linphone.ui.main.chat.model.ChatMessageModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_bottom_sheet_background"
android:clickable="true"
android:focusable="true"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
android:id="@+id/handle"
android:onClick="@{handleClickedListener}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="11dp"
android:src="@drawable/shape_drawer_handle"
app:tint="@color/gray_main2_300"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent_color"
app:layout_constraintTop_toBottomOf="@id/handle"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabPadding="0dp"
app:tabInlineLabel="true"
app:tabTextColor="@color/gray_main2_400"
app:tabSelectedTextColor="@color/gray_main2_600">
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lu" />
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reçu" />
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Envoyé" />
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Erreur" />
</com.google.android.material.tabs.TabLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tabs">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
entries="@{model.deliveryModels}"
layout="@{@layout/chat_delivery_list_cell}" />
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -15,7 +15,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_numpad_background"
android:background="@drawable/shape_bottom_sheet_background"
android:clickable="true"
android:focusable="true"
app:behavior_hideable="true"