mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Parse and render emoji reactions
Fixes part of #152 To keep this PR simple, I've left out: - when long-pressing on the emoji in a group MMS, a popup should come up listing which contact sent each emoji - notifications (untested) - sending emoji reactions
This commit is contained in:
@@ -26,6 +26,7 @@ object BubbleUtils {
|
||||
|
||||
const val TIMESTAMP_THRESHOLD = 10
|
||||
|
||||
// TODO: update to consider emoji reactions
|
||||
fun canGroup(message: Message, other: Message?): Boolean {
|
||||
if (other == null) return false
|
||||
val diff = TimeUnit.MILLISECONDS.toMinutes(Math.abs(message.date - other.date))
|
||||
|
||||
@@ -64,6 +64,7 @@ import dev.octoshrimpy.quik.feature.compose.BubbleUtils.getBubble
|
||||
import dev.octoshrimpy.quik.feature.compose.part.PartsAdapter
|
||||
import dev.octoshrimpy.quik.feature.extensions.isEmojiOnly
|
||||
import dev.octoshrimpy.quik.model.Conversation
|
||||
import dev.octoshrimpy.quik.model.EmojiReaction
|
||||
import dev.octoshrimpy.quik.model.Message
|
||||
import dev.octoshrimpy.quik.model.Recipient
|
||||
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
||||
@@ -71,10 +72,13 @@ import dev.octoshrimpy.quik.util.Preferences
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.body
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.reactionText
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.parts
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.reactions
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.sim
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.simIndex
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.status
|
||||
@@ -389,6 +393,59 @@ class MessagesAdapter @Inject constructor(
|
||||
contextMenuValue = message.id
|
||||
clicks.subscribe(partClicks) // part clicks gets passed back to compose view model
|
||||
}
|
||||
|
||||
bindEmojiReactions(holder, message)
|
||||
}
|
||||
|
||||
private fun bindEmojiReactions(holder: QkViewHolder, message: Message) {
|
||||
holder.reactions?.let { reactionsContainer ->
|
||||
val reactions = getReactionsForMessage(message.id)
|
||||
val hasReactions = reactions.isNotEmpty()
|
||||
|
||||
if (hasReactions) {
|
||||
val reactionCounts = reactions.groupBy { it.emoji }
|
||||
.mapValues { it.value.size }
|
||||
.toList()
|
||||
.sortedByDescending { it.second } // Sort by count, most reactions first
|
||||
|
||||
// For now, show just the first (most popular) reaction
|
||||
val topReaction = reactionCounts.first()
|
||||
val reactionText = if (topReaction.second == 1) {
|
||||
topReaction.first
|
||||
} else {
|
||||
"${topReaction.first} ${topReaction.second}"
|
||||
}
|
||||
|
||||
holder.reactionText?.text = reactionText
|
||||
reactionsContainer.setVisible(true)
|
||||
makeRoomForEmojis(holder)
|
||||
} else {
|
||||
reactionsContainer.setVisible(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun makeRoomForEmojis(holder: QkViewHolder) {
|
||||
val paddingBottom = 21.dpToPx(context)
|
||||
|
||||
// Adjust the container padding
|
||||
(holder.reactions?.parent as? ViewGroup)?.let { parent ->
|
||||
parent.setPadding(
|
||||
parent.paddingLeft,
|
||||
parent.paddingTop,
|
||||
parent.paddingRight,
|
||||
paddingBottom
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getReactionsForMessage(messageId: Long): List<EmojiReaction> {
|
||||
return Realm.getDefaultInstance().use { realm ->
|
||||
realm.where(EmojiReaction::class.java)
|
||||
.equalTo("targetMessageId", messageId)
|
||||
.findAll()
|
||||
.let { realm.copyFromRealm(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindStatus(
|
||||
|
||||
@@ -89,16 +89,19 @@
|
||||
app:layout_constraintBottom_toBottomOf="@id/body"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:orientation="vertical">
|
||||
android:paddingBottom="20dp"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerViewLongMmsPart
|
||||
android:id="@+id/parts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:orientation="vertical"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
@@ -110,6 +113,8 @@
|
||||
style="@style/TextPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/parts"
|
||||
android:layout_marginTop="2dp"
|
||||
android:autoLink="email|phone|web"
|
||||
android:background="@drawable/message_only"
|
||||
@@ -118,7 +123,37 @@
|
||||
android:textIsSelectable="true"
|
||||
tools:backgroundTint="@color/tools_theme"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/reactions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@id/body"
|
||||
android:layout_alignEnd="@id/body"
|
||||
android:layout_marginEnd="-12dp"
|
||||
android:layout_marginBottom="-20dp"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reactionText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/message_only"
|
||||
android:backgroundTint="?android:attr/colorBackground"
|
||||
android:elevation="2dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="😂 2"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -92,7 +92,8 @@
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/cancelFrame"
|
||||
@@ -145,17 +146,54 @@
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<dev.octoshrimpy.quik.common.widget.TightTextView
|
||||
android:id="@+id/body"
|
||||
style="@style/TextPrimary"
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autoLink="email|phone|web"
|
||||
android:background="@drawable/message_only"
|
||||
android:backgroundTint="?attr/bubbleColor"
|
||||
android:gravity="start|center_vertical"
|
||||
android:minHeight="36dp"
|
||||
android:textIsSelectable="true" />
|
||||
android:paddingStart="18dp"
|
||||
android:paddingBottom="21dp"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<dev.octoshrimpy.quik.common.widget.TightTextView
|
||||
android:id="@+id/body"
|
||||
style="@style/TextPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:autoLink="email|phone|web"
|
||||
android:background="@drawable/message_only"
|
||||
android:backgroundTint="?attr/bubbleColor"
|
||||
android:gravity="start|center_vertical"
|
||||
android:minHeight="36dp"
|
||||
android:textIsSelectable="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/reactions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|start"
|
||||
android:layout_marginStart="-16dp"
|
||||
android:layout_marginBottom="-20dp"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reactionText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/message_only"
|
||||
android:backgroundTint="?android:attr/colorBackground"
|
||||
android:elevation="2dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="👍 1"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
|
||||
Reference in New Issue
Block a user