mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Apply message corner radii
This commit is contained in:
parent
34522ede95
commit
2b21f199ea
@ -1,11 +1,13 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat
|
||||
@ -42,10 +44,9 @@ class VisibleMessageContentView : LinearLayout {
|
||||
// endregion
|
||||
|
||||
// region Updating
|
||||
fun bind(message: MessageRecord) {
|
||||
fun bind(message: MessageRecord, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
||||
// Background
|
||||
// TODO: Set background to one of sent/received + top/middle/bottom + color
|
||||
val background = ResourcesCompat.getDrawable(resources, R.drawable.message_bubble_background, context.theme)!!
|
||||
val background = getBackground(message.isOutgoing, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
val colorID = if (message.isOutgoing) R.attr.message_sent_background_color else R.attr.message_received_background_color
|
||||
val color = ThemeUtil.getThemedColor(context, colorID)
|
||||
val filter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, BlendModeCompat.SRC_IN)
|
||||
@ -77,6 +78,21 @@ class VisibleMessageContentView : LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBackground(isOutgoing: Boolean, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean): Drawable {
|
||||
val isSingleMessage = (isStartOfMessageCluster && isEndOfMessageCluster)
|
||||
@DrawableRes val backgroundID: Int
|
||||
if (isSingleMessage) {
|
||||
backgroundID = if (isOutgoing) R.drawable.message_bubble_background_sent_alone else R.drawable.message_bubble_background_received_alone
|
||||
} else if (isStartOfMessageCluster) {
|
||||
backgroundID = if (isOutgoing) R.drawable.message_bubble_background_sent_start else R.drawable.message_bubble_background_received_start
|
||||
} else if (isEndOfMessageCluster) {
|
||||
backgroundID = if (isOutgoing) R.drawable.message_bubble_background_sent_end else R.drawable.message_bubble_background_received_end
|
||||
} else {
|
||||
backgroundID = if (isOutgoing) R.drawable.message_bubble_background_sent_middle else R.drawable.message_bubble_background_received_middle;
|
||||
}
|
||||
return ResourcesCompat.getDrawable(resources, backgroundID, context.theme)!!
|
||||
}
|
||||
|
||||
fun recycle() {
|
||||
mainContainer.removeAllViews()
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import kotlinx.android.synthetic.main.view_visible_message.view.*
|
||||
import network.loki.messenger.R
|
||||
import nl.komponents.kovenant.combine.Tuple8
|
||||
import org.session.libsession.messaging.contacts.Contact.ContactContext
|
||||
import org.session.libsession.utilities.ViewUtil
|
||||
import org.session.libsignal.utilities.guava.Optional
|
||||
@ -76,22 +77,20 @@ class VisibleMessageView : LinearLayout {
|
||||
else resources.getDimension(R.dimen.very_large_spacing).toInt()
|
||||
messageContentView.layoutParams = messageContentViewLayoutParams
|
||||
// Set inter-message spacing
|
||||
setMessageSpacing(message, previous, next, isGroupThread)
|
||||
val isStartOfMessageCluster = isStartOfMessageCluster(message, previous, isGroupThread)
|
||||
val isEndOfMessageCluster = isEndOfMessageCluster(message, next, isGroupThread)
|
||||
setMessageSpacing(isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
// Gravity
|
||||
val gravity = if (message.isOutgoing) Gravity.RIGHT else Gravity.LEFT
|
||||
mainContainer.gravity = gravity or Gravity.BOTTOM
|
||||
// Populate content view
|
||||
messageContentView.bind(message)
|
||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||
}
|
||||
|
||||
private fun setMessageSpacing(current: MessageRecord, previous: MessageRecord?, next: MessageRecord?, isGroupThread: Boolean) {
|
||||
val isStartOfMessageCluster = (isStartOfMessageCluster(current, previous, isGroupThread))
|
||||
val topPadding = if (isStartOfMessageCluster) R.dimen.conversation_vertical_message_spacing_default
|
||||
else R.dimen.conversation_vertical_message_spacing_collapse
|
||||
private fun setMessageSpacing(isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) {
|
||||
val topPadding = if (isStartOfMessageCluster) R.dimen.conversation_vertical_message_spacing_default else R.dimen.conversation_vertical_message_spacing_collapse
|
||||
ViewUtil.setPaddingTop(this, resources.getDimension(topPadding).roundToInt())
|
||||
val isEndOfMessageCluster = (isEndOfMessageCluster(current, previous, isGroupThread))
|
||||
val bottomPadding = if (isEndOfMessageCluster) R.dimen.conversation_vertical_message_spacing_default
|
||||
else R.dimen.conversation_vertical_message_spacing_collapse
|
||||
val bottomPadding = if (isEndOfMessageCluster) R.dimen.conversation_vertical_message_spacing_default else R.dimen.conversation_vertical_message_spacing_collapse
|
||||
ViewUtil.setPaddingBottom(this, resources.getDimension(bottomPadding).roundToInt())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user