Show our reaction if any in long press menu + remove it if selected again
This commit is contained in:
parent
928a4f129b
commit
0e03420bd2
6 changed files with 84 additions and 6 deletions
|
@ -406,6 +406,27 @@ class ChatMessagesListAdapter(
|
|||
totalSize -= itemSize
|
||||
}
|
||||
|
||||
val reaction = chatMessage.ownReaction
|
||||
if (reaction != null) {
|
||||
when (reaction.body) {
|
||||
AppUtils.getString(R.string.emoji_love) -> {
|
||||
popupView.heartSelected = true
|
||||
}
|
||||
AppUtils.getString(R.string.emoji_laughing) -> {
|
||||
popupView.laughingSelected = true
|
||||
}
|
||||
AppUtils.getString(R.string.emoji_surprised) -> {
|
||||
popupView.surprisedSelected = true
|
||||
}
|
||||
AppUtils.getString(R.string.emoji_thumbs_up) -> {
|
||||
popupView.thumbsUpSelected = true
|
||||
}
|
||||
AppUtils.getString(R.string.emoji_tear) -> {
|
||||
popupView.cryingSelected = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When using WRAP_CONTENT instead of real size, fails to place the
|
||||
// popup window above if not enough space is available below
|
||||
val popupWindow = PopupWindow(
|
||||
|
@ -467,11 +488,21 @@ class ChatMessagesListAdapter(
|
|||
private fun reactToMessage(reaction: String) {
|
||||
val chatMessage = binding.data?.chatMessage
|
||||
if (chatMessage != null) {
|
||||
Log.i(
|
||||
"[Chat Message Data] Reacting to message [$chatMessage] with [$reaction] emoji"
|
||||
)
|
||||
val reactionMessage = chatMessage.createReaction(reaction)
|
||||
reactionMessage.send()
|
||||
val ownReaction = chatMessage.ownReaction
|
||||
if (ownReaction != null && ownReaction.body == reaction) {
|
||||
Log.i(
|
||||
"[Chat Message Data] Removing our reaction to message [$chatMessage] (previously [$reaction])"
|
||||
)
|
||||
// Empty string means remove existing reaction
|
||||
val reactionMessage = chatMessage.createReaction("")
|
||||
reactionMessage.send()
|
||||
} else {
|
||||
Log.i(
|
||||
"[Chat Message Data] Reacting to message [$chatMessage] with [$reaction] emoji"
|
||||
)
|
||||
val reactionMessage = chatMessage.createReaction(reaction)
|
||||
reactionMessage.send()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
|||
import org.linphone.R
|
||||
import org.linphone.contact.ContactsUpdatedListenerStub
|
||||
import org.linphone.contact.GenericContactData
|
||||
import org.linphone.core.Address
|
||||
import org.linphone.core.ChatMessage
|
||||
import org.linphone.core.ChatMessageListenerStub
|
||||
import org.linphone.core.ChatMessageReaction
|
||||
|
@ -95,6 +96,13 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
|||
)
|
||||
updateReactionsList()
|
||||
}
|
||||
|
||||
override fun onReactionRemoved(message: ChatMessage, address: Address) {
|
||||
Log.i(
|
||||
"[Chat Message Data] [${address.asStringUriOnly()}] removed it's previous reaction"
|
||||
)
|
||||
updateReactionsList()
|
||||
}
|
||||
}
|
||||
|
||||
private val contactsListener = object : ContactsUpdatedListenerStub() {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.linphone.activities.main.chat.data
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.linphone.core.Address
|
||||
import org.linphone.core.ChatMessage
|
||||
import org.linphone.core.ChatMessageListenerStub
|
||||
import org.linphone.core.ChatMessageReaction
|
||||
|
@ -40,6 +41,13 @@ class ChatMessageReactionsListData(private val chatMessage: ChatMessage) {
|
|||
)
|
||||
updateReactionsList(message)
|
||||
}
|
||||
|
||||
override fun onReactionRemoved(message: ChatMessage, address: Address) {
|
||||
Log.i(
|
||||
"[Chat Message Reactions List] Reaction removed by [${address.asStringUriOnly()}]"
|
||||
)
|
||||
updateReactionsList(message)
|
||||
}
|
||||
}
|
||||
|
||||
private var filter = ""
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<corners android:radius="10dp" />
|
||||
<solid android:color="@color/voip_light_gray"/>
|
||||
</shape>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<solid android:color="@color/transparent_color"/>
|
||||
</shape>
|
|
@ -46,6 +46,21 @@
|
|||
<variable
|
||||
name="replyHidden"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="heartSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="thumbsUpSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="laughingSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="surprisedSelected"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="cryingSelected"
|
||||
type="Boolean" />
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -56,7 +71,8 @@
|
|||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/chat_message_popup_item_height">
|
||||
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||
android:layout_marginTop="5dp">
|
||||
|
||||
<TextView
|
||||
style="@style/chat_message_emoji_reaction_font"
|
||||
|
@ -67,6 +83,7 @@
|
|||
android:padding="10dp"
|
||||
android:text="@string/emoji_love"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:background="@{heartSelected ? @drawable/shape_own_reaction_background : @drawable/shape_transparent_reaction_background, default=@drawable/shape_own_reaction_background}"
|
||||
app:layout_constraintEnd_toStartOf="@id/thumbs_up"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
@ -81,6 +98,7 @@
|
|||
android:padding="10dp"
|
||||
android:text="@string/emoji_thumbs_up"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:background="@{thumbsUpSelected ? @drawable/shape_own_reaction_background : @drawable/shape_transparent_reaction_background}"
|
||||
app:layout_constraintEnd_toStartOf="@id/laughing"
|
||||
app:layout_constraintStart_toEndOf="@id/love"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
@ -95,6 +113,7 @@
|
|||
android:padding="10dp"
|
||||
android:text="@string/emoji_laughing"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:background="@{laughingSelected ? @drawable/shape_own_reaction_background : @drawable/shape_transparent_reaction_background}"
|
||||
app:layout_constraintEnd_toStartOf="@id/surprised"
|
||||
app:layout_constraintStart_toEndOf="@id/thumbs_up"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
@ -109,6 +128,7 @@
|
|||
android:padding="10dp"
|
||||
android:text="@string/emoji_surprised"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:background="@{surprisedSelected ? @drawable/shape_own_reaction_background : @drawable/shape_transparent_reaction_background}"
|
||||
app:layout_constraintEnd_toStartOf="@id/tear"
|
||||
app:layout_constraintStart_toEndOf="@id/laughing"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
@ -123,6 +143,7 @@
|
|||
android:padding="10dp"
|
||||
android:text="@string/emoji_tear"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:background="@{cryingSelected ? @drawable/shape_own_reaction_background : @drawable/shape_transparent_reaction_background}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/surprised"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
@ -133,6 +154,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/chat_message_popup_item_height"
|
||||
android:layout_marginTop="5dp"
|
||||
android:background="@drawable/menu_background"
|
||||
android:visibility="@{resendHidden ? View.GONE : View.VISIBLE}"
|
||||
android:onClick="@{resendClickListener}"
|
||||
|
|
Loading…
Reference in a new issue