mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added simple text message sending + improved sent chat bubble
This commit is contained in:
parent
9c6533bceb
commit
db6f71c8cb
6 changed files with 155 additions and 10 deletions
|
|
@ -26,6 +26,8 @@ import androidx.lifecycle.ViewModel
|
|||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.Address
|
||||
import org.linphone.core.ChatRoom
|
||||
import org.linphone.core.ChatRoomListenerStub
|
||||
import org.linphone.core.EventLog
|
||||
import org.linphone.core.Factory
|
||||
import org.linphone.core.Friend
|
||||
import org.linphone.core.tools.Log
|
||||
|
|
@ -51,19 +53,41 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val subject = MutableLiveData<String>()
|
||||
|
||||
val isReadOnly = MutableLiveData<Boolean>()
|
||||
|
||||
val textToSend = MutableLiveData<String>()
|
||||
|
||||
val chatRoomFoundEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
private lateinit var chatRoom: ChatRoom
|
||||
|
||||
private val avatarsMap = hashMapOf<String, ContactAvatarModel>()
|
||||
|
||||
init {
|
||||
private val chatRoomListener = object : ChatRoomListenerStub() {
|
||||
override fun onChatMessageSending(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
val message = eventLog.chatMessage
|
||||
Log.i("$TAG Chat message [$message] is being sent")
|
||||
|
||||
val list = arrayListOf<EventLogModel>()
|
||||
list.addAll(events.value.orEmpty())
|
||||
|
||||
val avatarModel = getAvatarModelForAddress(message?.localAddress)
|
||||
list.add(EventLogModel(eventLog, avatarModel))
|
||||
|
||||
events.postValue(list)
|
||||
}
|
||||
|
||||
override fun onChatMessageSent(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||
val message = eventLog.chatMessage
|
||||
Log.i("$TAG Chat message [$message] has been sent")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
chatRoom.removeListener(chatRoomListener)
|
||||
avatarsMap.values.forEach(ContactAvatarModel::destroy)
|
||||
}
|
||||
}
|
||||
|
|
@ -88,6 +112,8 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
)
|
||||
if (found != null) {
|
||||
chatRoom = found
|
||||
chatRoom.addListener(chatRoomListener)
|
||||
|
||||
configureChatRoom()
|
||||
chatRoomFoundEvent.postValue(Event(true))
|
||||
} else {
|
||||
|
|
@ -101,6 +127,24 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun sendMessage() {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
val message = chatRoom.createEmptyMessage()
|
||||
|
||||
val toSend = textToSend.value.orEmpty().trim()
|
||||
if (toSend.isNotEmpty()) {
|
||||
message.addUtf8TextContent(toSend)
|
||||
}
|
||||
|
||||
if (message.contents.isNotEmpty()) {
|
||||
Log.i("$TAG Sending message")
|
||||
message.send()
|
||||
}
|
||||
textToSend.postValue("")
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun configureChatRoom() {
|
||||
isGroup.postValue(
|
||||
|
|
@ -108,6 +152,14 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
ChatRoom.Capabilities.Conference.toInt()
|
||||
)
|
||||
)
|
||||
|
||||
val empty = chatRoom.hasCapability(ChatRoom.Capabilities.Conference.toInt()) && chatRoom.participants.isEmpty()
|
||||
val readOnly = chatRoom.isReadOnly || empty
|
||||
isReadOnly.postValue(readOnly)
|
||||
if (readOnly) {
|
||||
Log.w("$TAG Chat room with subject [${chatRoom.subject}] is read only!")
|
||||
}
|
||||
|
||||
subject.postValue(chatRoom.subject)
|
||||
|
||||
val friends = arrayListOf<Friend>()
|
||||
|
|
|
|||
6
app/src/main/res/color/icon_color_selector.xml
Normal file
6
app/src/main/res/color/icon_color_selector.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="false" android:color="@color/gray_main2_200"/>
|
||||
<item android:state_pressed="true" android:color="@color/orange_main_500"/>
|
||||
<item android:color="@color/gray_main2_500"/>
|
||||
</selector>
|
||||
6
app/src/main/res/color/icon_primary_color_selector.xml
Normal file
6
app/src/main/res/color/icon_primary_color_selector.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="false" android:color="@color/gray_main2_200"/>
|
||||
<item android:state_pressed="true" android:color="@color/gray_main2_500"/>
|
||||
<item android:color="@color/orange_main_500"/>
|
||||
</selector>
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
<data>
|
||||
<import type="android.view.View" />
|
||||
<import type="org.linphone.core.ChatMessage.State" />
|
||||
<variable
|
||||
name="onLongClickListener"
|
||||
type="View.OnLongClickListener" />
|
||||
|
|
@ -26,19 +27,87 @@
|
|||
android:layout_marginTop="@{isGroupedWithPreviousOne ? @dimen/chat_bubble_grouped_top_margin : @dimen/chat_bubble_top_margin, default=@dimen/chat_bubble_top_margin}"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<org.linphone.ui.main.chat.view.ChatBubbleTextView
|
||||
style="@style/default_text_style"
|
||||
<ImageView
|
||||
android:id="@+id/background"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:src="@{isGroupedWithPreviousOne ? @drawable/shape_chat_bubble_outgoing_full : @drawable/shape_chat_bubble_outgoing_first, default=@drawable/shape_chat_bubble_outgoing_first}"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/bubble_bottom_barrier"
|
||||
app:layout_constraintStart_toStartOf="@id/bubble_start_barrier"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/bubble_start_barrier"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{model.text, default=`Lorem ipsum dolor sit amet`}"
|
||||
app:barrierDirection="start"
|
||||
app:barrierMargin="-18dp"
|
||||
app:constraint_referenced_ids="text_message, date_time"/>
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/bubble_bottom_barrier"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="bottom"
|
||||
app:constraint_referenced_ids="text_bottom_anchor, delivery_status"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/text_message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="18dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="18dp"
|
||||
android:text="@{model.text, default=`Lorem ipsum`}"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/gray_main2_700"
|
||||
android:gravity="center_vertical|end"
|
||||
android:padding="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:gravity="center_vertical|start"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintHorizontal_bias="1"
|
||||
app:layout_constraintTop_toTopOf="@id/background"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/background"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/text_bottom_anchor"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_message"
|
||||
app:layout_constraintStart_toStartOf="@id/text_message"/>
|
||||
|
||||
<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"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:text="@{model.time, default=`13:40`}"
|
||||
android:textSize="12sp"
|
||||
android:visibility="@{isLastOneOfGroup ? View.VISIBLE : View.GONE}"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_message"
|
||||
app:layout_constraintEnd_toStartOf="@id/delivery_status"
|
||||
app:layout_constraintBottom_toBottomOf="@id/background"/>
|
||||
|
||||
<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"
|
||||
android:layout_marginTop="2dp"
|
||||
android:src="@{model.state == State.Displayed ? @drawable/checks : model.state == State.DeliveredToUser ? @drawable/check : model.state == State.Delivered ? @drawable/envelope_simple : model.state == State.NotDelivered ? @drawable/warning_circle : @drawable/in_progress, default=@drawable/in_progress}"
|
||||
android:visibility="@{isLastOneOfGroup ? View.VISIBLE : View.GONE}"
|
||||
app:layout_constraintTop_toTopOf="@id/date_time"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:background="@{isGroupedWithPreviousOne ? @drawable/shape_chat_bubble_outgoing_full : @drawable/shape_chat_bubble_outgoing_first, default=@drawable/shape_chat_bubble_outgoing_first}"/>
|
||||
app:layout_constraintBottom_toBottomOf="@id/date_time"
|
||||
app:tint="@color/orange_main_500" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -186,6 +186,8 @@
|
|||
<include
|
||||
android:id="@+id/send_area"
|
||||
openEmojiPickerClickListener="@{openEmojiPickerClickListener}"
|
||||
viewModel="@{viewModel}"
|
||||
android:visibility="@{viewModel.isReadOnly ? View.GONE : View.VISIBLE}"
|
||||
layout="@layout/chat_conversation_send_area"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
<variable
|
||||
name="openEmojiPickerClickListener"
|
||||
type="View.OnClickListener" />
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="org.linphone.ui.main.chat.viewmodel.ConversationViewModel" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
|
@ -24,6 +27,7 @@
|
|||
android:layout_height="@dimen/icon_size"
|
||||
android:layout_marginStart="16dp"
|
||||
android:src="@drawable/smiley"
|
||||
app:tint="@color/icon_color_selector"
|
||||
app:layout_constraintTop_toTopOf="@id/message_area_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/message_area_background"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
|
@ -35,6 +39,7 @@
|
|||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:src="@drawable/paperclip"
|
||||
app:tint="@color/icon_color_selector"
|
||||
app:layout_constraintTop_toTopOf="@id/message_area_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/message_area_background"
|
||||
app:layout_constraintStart_toEndOf="@id/emoji_picker"
|
||||
|
|
@ -61,10 +66,12 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
android:minHeight="48dp"
|
||||
android:background="@color/transparent_color"
|
||||
android:text="@={viewModel.textToSend}"
|
||||
android:textSize="14sp"
|
||||
android:textColorHint="@color/gray_main2_400"
|
||||
android:maxLines="3"
|
||||
android:hint="@string/conversation_text_field_hint"
|
||||
android:inputType="text"
|
||||
app:layout_constraintStart_toStartOf="@id/message_area_background"
|
||||
app:layout_constraintEnd_toStartOf="@id/send_barrier"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
|
@ -83,17 +90,20 @@
|
|||
android:layout_marginEnd="12dp"
|
||||
android:src="@drawable/microphone"
|
||||
android:visibility="gone"
|
||||
app:tint="@color/icon_color_selector"
|
||||
app:layout_constraintTop_toTopOf="@id/message_area_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/message_area_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/message_area_background" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/send_message"
|
||||
android:onClick="@{() -> viewModel.sendMessage()}"
|
||||
android:layout_width="@dimen/icon_size"
|
||||
android:layout_height="@dimen/icon_size"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:src="@drawable/paper_plane_tilt"
|
||||
app:tint="@color/orange_main_500"
|
||||
android:enabled="@{viewModel.textToSend.length() > 0}"
|
||||
app:tint="@color/icon_primary_color_selector"
|
||||
app:layout_constraintTop_toTopOf="@id/message_area_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/message_area_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/message_area_background" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue