Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import org.fossify.messages.extensions.updateScheduledMessagesThreadId
import org.fossify.messages.helpers.CAPTURE_AUDIO_INTENT
import org.fossify.messages.helpers.CAPTURE_PHOTO_INTENT
import org.fossify.messages.helpers.CAPTURE_VIDEO_INTENT
import org.fossify.messages.helpers.EmojiReactionHelper
import org.fossify.messages.helpers.FILE_SIZE_NONE
import org.fossify.messages.helpers.IS_LAUNCHED_FROM_SHORTCUT
import org.fossify.messages.helpers.IS_RECYCLE_BIN
Expand Down Expand Up @@ -447,6 +448,7 @@ class ThreadActivity : SimpleActivity() {
messages.removeAll { it.isScheduled && it.millis() < System.currentTimeMillis() }

messages.sortBy { it.date }
messages = EmojiReactionHelper.applyEmojiReactions(messages)
if (messages.size > MESSAGES_LIMIT) {
messages = ArrayList(messages.takeLast(MESSAGES_LIMIT))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.util.TypedValue
import android.view.Menu
import android.view.View
Expand All @@ -13,6 +14,7 @@ import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toDrawable
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.DiffUtil
Expand All @@ -35,10 +37,12 @@ import org.fossify.commons.extensions.beVisible
import org.fossify.commons.extensions.beVisibleIf
import org.fossify.commons.extensions.copyToClipboard
import org.fossify.commons.extensions.formatDateOrTime
import org.fossify.commons.extensions.getBottomNavigationBackgroundColor
import org.fossify.commons.extensions.getContrastColor
import org.fossify.commons.extensions.getProperPrimaryColor
import org.fossify.commons.extensions.getTextSize
import org.fossify.commons.extensions.getTimeFormat
import org.fossify.commons.extensions.isDynamicTheme
import org.fossify.commons.extensions.shareTextIntent
import org.fossify.commons.extensions.showErrorToast
import org.fossify.commons.extensions.usableScreenSize
Expand All @@ -61,6 +65,7 @@ import org.fossify.messages.databinding.ItemThreadSendingBinding
import org.fossify.messages.databinding.ItemThreadSuccessBinding
import org.fossify.messages.dialogs.DeleteConfirmationDialog
import org.fossify.messages.dialogs.MessageDetailsDialog
import org.fossify.messages.dialogs.ReactionDetailsDialog
import org.fossify.messages.dialogs.SelectTextDialog
import org.fossify.messages.extensions.config
import org.fossify.messages.extensions.getContactFromAddress
Expand Down Expand Up @@ -101,6 +106,9 @@ class ThreadAdapter(
@SuppressLint("MissingPermission")
private val hasMultipleSIMCards = (activity.subscriptionManagerCompat().activeSubscriptionInfoList?.size ?: 0) > 1
private val maxChatBubbleWidth = (activity.usableScreenSize.x * 0.8f).toInt()
private val reactionHorizontalOverlap = 8.dpToPx()
private val reactionVerticalOverlap = 4.dpToPx()
private val reactionElevation = 1.dpToPx()

companion object {
private const val MAX_MEDIA_HEIGHT_RATIO = 3
Expand All @@ -111,6 +119,7 @@ class ThreadAdapter(
init {
setupDragListener(true)
setHasStableIds(true)
recyclerView.clipChildren = false
(recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
}

Expand Down Expand Up @@ -385,6 +394,7 @@ class ThreadAdapter(
} else {
setupSentMessageView(messageBinding = this, message = message)
}
setupEmojiReactions(messageBinding = this, message = message)

if (message.attachment?.attachments?.isNotEmpty() == true) {
threadMessageAttachmentsHolder.beVisible()
Expand All @@ -406,6 +416,73 @@ class ThreadAdapter(
}
}

private fun setupEmojiReactions(messageBinding: ItemMessageBinding, message: Message) {
val reactions = message.emojiReactions
messageBinding.threadMessageReactions.apply {
beVisibleIf(reactions.isNotEmpty())
if (reactions.isEmpty()) {
text = ""
setOnLongClickListener(null)
return
}

val uniqueEmojis = reactions.map { it.emoji }.distinct()
text = if (reactions.size == 1) {
uniqueEmojis.first()
} else {
"${uniqueEmojis.joinToString("")}\u00A0${reactions.size}"
}
setOnLongClickListener {
showReactionDetails(message)
true
}

if (message.isReceivedMessage()) {
background = createReactionBackground()
elevation = reactionElevation
translationX = reactionHorizontalOverlap
translationY = -reactionVerticalOverlap
setTextColor(textColor)
updateLayoutParams<RelativeLayout.LayoutParams> {
removeRule(RelativeLayout.END_OF)
removeRule(RelativeLayout.ALIGN_PARENT_END)
removeRule(RelativeLayout.ALIGN_END)
removeRule(RelativeLayout.ALIGN_RIGHT)
removeRule(RelativeLayout.ALIGN_START)
removeRule(RelativeLayout.ALIGN_LEFT)
addRule(RelativeLayout.ALIGN_END, messageBinding.threadMessageBody.id)
}
} else {
background = createReactionBackground()
elevation = reactionElevation
translationX = -reactionHorizontalOverlap
translationY = -reactionVerticalOverlap
setTextColor(textColor)
updateLayoutParams<RelativeLayout.LayoutParams> {
removeRule(RelativeLayout.END_OF)
removeRule(RelativeLayout.ALIGN_PARENT_END)
removeRule(RelativeLayout.ALIGN_END)
removeRule(RelativeLayout.ALIGN_RIGHT)
removeRule(RelativeLayout.ALIGN_LEFT)
addRule(RelativeLayout.ALIGN_START, messageBinding.threadMessageBody.id)
}
}
}
}

private fun showReactionDetails(message: Message) {
val rows = message.emojiReactions.map { reaction ->
val contactName = message.participants
.firstOrNull { participant -> participant.doesHavePhoneNumber(reaction.senderPhoneNumber) }
?.name
?.takeIf { it.isNotBlank() }
?: reaction.senderPhoneNumber

"${reaction.emoji} $contactName"
}
ReactionDetailsDialog(activity, rows)
}

private fun setupReceivedMessageView(messageBinding: ItemMessageBinding, message: Message) {
messageBinding.apply {
with(ConstraintSet()) {
Expand Down Expand Up @@ -635,6 +712,26 @@ class ThreadAdapter(
}

inner class ThreadViewHolder(val binding: ViewBinding) : ViewHolder(binding.root)

private fun Int.dpToPx(): Float {
return this * resources.displayMetrics.density
}

private fun createReactionBackground(): GradientDrawable {
return GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE
cornerRadius = 18.dpToPx()
setColor(getBottomBarColor())
}
}

private fun getBottomBarColor(): Int {
return if (activity.isDynamicTheme()) {
ContextCompat.getColor(activity, org.fossify.commons.R.color.you_bottom_bar_color)
} else {
activity.getBottomNavigationBackgroundColor()
}
}
}

private class ThreadItemDiffCallback : DiffUtil.ItemCallback<ThreadItem>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.fossify.messages.dialogs

import android.view.ViewGroup
import org.fossify.commons.activities.BaseSimpleActivity
import org.fossify.commons.extensions.getAlertDialogBuilder
import org.fossify.commons.extensions.getProperTextColor
import org.fossify.commons.extensions.setupDialogStuff
import org.fossify.commons.views.MyTextView
import org.fossify.messages.R
import org.fossify.messages.databinding.DialogReactionDetailsBinding

class ReactionDetailsDialog(
private val activity: BaseSimpleActivity,
reactions: List<String>,
) {
init {
val binding = DialogReactionDetailsBinding.inflate(activity.layoutInflater).apply {
val rowPadding = 8.dpToPx()
reactions.forEach { reaction ->
dialogReactionDetailsHolder.addView(
MyTextView(activity).apply {
layoutParams = ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
)
text = reaction
setTextColor(activity.getProperTextColor())
textSize = REACTION_TEXT_SIZE
setPadding(0, rowPadding, 0, rowPadding)
}
)
}
}

activity.getAlertDialogBuilder().apply {
activity.setupDialogStuff(binding.root, this, R.string.reactions)
}
}

private fun Int.dpToPx(): Int {
return (this * activity.resources.displayMetrics.density).toInt()
}

private companion object {
const val REACTION_TEXT_SIZE = 22f
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import org.fossify.messages.R
import org.fossify.messages.databases.MessagesDatabase
import org.fossify.messages.helpers.AttachmentUtils.parseAttachmentNames
import org.fossify.messages.helpers.Config
import org.fossify.messages.helpers.EmojiReactionHelper
import org.fossify.messages.helpers.FILE_SIZE_NONE
import org.fossify.messages.helpers.MAX_MESSAGE_LENGTH
import org.fossify.messages.helpers.MESSAGES_LIMIT
Expand Down Expand Up @@ -205,7 +206,7 @@ fun Context.getMessages(
}
}

messages = messages
messages = EmojiReactionHelper.applyEmojiReactions(messages)
.filter { it.participants.isNotEmpty() }
.filterNot { it.isScheduled && it.millis() < System.currentTimeMillis() }
.sortedWith(compareBy<Message> { it.date }.thenBy { it.id })
Expand Down
Loading
Loading