mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-27 05:03:28 +00:00
Fix RTL display of CIV2 bubble corners.
This commit is contained in:
committed by
Cody Henthorne
parent
7d4ebd9d3b
commit
b3399b5242
@@ -142,6 +142,13 @@ class ChatColorsDrawable : Drawable() {
|
||||
return gradientColors == null
|
||||
}
|
||||
|
||||
fun setCorners(corners: FloatArray) {
|
||||
if (!this.corners.contentEquals(corners)) {
|
||||
this.corners = corners
|
||||
invalidateSelf()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the chat color and shape as specified. If the colors are a gradient,
|
||||
* we will use masking to draw, and we will draw every time we're told to by
|
||||
|
||||
@@ -39,7 +39,6 @@ class V2ConversationItemShape(
|
||||
* updates the class state.
|
||||
*/
|
||||
fun setMessageShape(
|
||||
isLtr: Boolean,
|
||||
currentMessage: MessageRecord,
|
||||
isGroupThread: Boolean,
|
||||
adapterPosition: Int
|
||||
@@ -48,42 +47,38 @@ class V2ConversationItemShape(
|
||||
val previousMessage: MessageRecord? = conversationContext.getPreviousMessage(adapterPosition)
|
||||
|
||||
if (isSingularMessage(currentMessage, previousMessage, nextMessage, isGroupThread)) {
|
||||
setBodyBubbleCorners(isLtr, bigRadius, bigRadius, bigRadius, bigRadius)
|
||||
setBodyBubbleCorners(bigRadius, bigRadius, bigRadius, bigRadius)
|
||||
return MessageShape.SINGLE
|
||||
} else if (isStartOfMessageCluster(currentMessage, previousMessage, isGroupThread)) {
|
||||
val bottomEnd = if (currentMessage.isOutgoing) smallRadius else bigRadius
|
||||
val bottomStart = if (currentMessage.isOutgoing) bigRadius else smallRadius
|
||||
setBodyBubbleCorners(isLtr, bigRadius, bigRadius, bottomEnd, bottomStart)
|
||||
setBodyBubbleCorners(bigRadius, bigRadius, bottomEnd, bottomStart)
|
||||
return MessageShape.START
|
||||
} else if (isEndOfMessageCluster(currentMessage, nextMessage)) {
|
||||
val topStart = if (currentMessage.isOutgoing) bigRadius else smallRadius
|
||||
val topEnd = if (currentMessage.isOutgoing) smallRadius else bigRadius
|
||||
setBodyBubbleCorners(isLtr, topStart, topEnd, bigRadius, bigRadius)
|
||||
setBodyBubbleCorners(topStart, topEnd, bigRadius, bigRadius)
|
||||
return MessageShape.END
|
||||
} else {
|
||||
val start = if (currentMessage.isOutgoing) bigRadius else smallRadius
|
||||
val end = if (currentMessage.isOutgoing) smallRadius else bigRadius
|
||||
setBodyBubbleCorners(isLtr, start, end, end, start)
|
||||
setBodyBubbleCorners(start, end, end, start)
|
||||
return MessageShape.MIDDLE
|
||||
}
|
||||
}
|
||||
|
||||
private fun setBodyBubbleCorners(
|
||||
isLtr: Boolean,
|
||||
topStart: Float,
|
||||
topEnd: Float,
|
||||
bottomEnd: Float,
|
||||
bottomStart: Float
|
||||
) {
|
||||
val newCorners = Projection.Corners(
|
||||
if (isLtr) topStart else topEnd,
|
||||
if (isLtr) topEnd else topStart,
|
||||
if (isLtr) bottomEnd else bottomStart,
|
||||
if (isLtr) bottomStart else bottomEnd
|
||||
topStart,
|
||||
topEnd,
|
||||
bottomEnd,
|
||||
bottomStart
|
||||
)
|
||||
if (corners == newCorners) {
|
||||
return
|
||||
}
|
||||
|
||||
corners = newCorners
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.thoughtcrime.securesms.util.SearchUtil
|
||||
import org.thoughtcrime.securesms.util.SignalLocalMetrics
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil
|
||||
import org.thoughtcrime.securesms.util.VibrateUtil
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
import org.thoughtcrime.securesms.util.adapter.mapping.MappingModel
|
||||
import org.thoughtcrime.securesms.util.hasExtraText
|
||||
import org.thoughtcrime.securesms.util.hasNoBubble
|
||||
@@ -191,7 +192,6 @@ open class V2ConversationItemTextOnlyViewHolder<Model : MappingModel<Model>>(
|
||||
conversationMessage = model.conversationMessage
|
||||
|
||||
shape = shapeDelegate.setMessageShape(
|
||||
isLtr = itemView.layoutDirection == View.LAYOUT_DIRECTION_LTR,
|
||||
currentMessage = conversationMessage.messageRecord,
|
||||
isGroupThread = conversationMessage.threadRecipient.isGroup,
|
||||
adapterPosition = bindingAdapterPosition
|
||||
@@ -345,6 +345,8 @@ open class V2ConversationItemTextOnlyViewHolder<Model : MappingModel<Model>>(
|
||||
}
|
||||
|
||||
private fun invalidateBodyBubbleDrawable(coordinateRoot: ViewGroup) {
|
||||
bodyBubbleDrawable.setCorners(shapeDelegate.corners.toRelativeRadii(ViewUtil.isLtr(coordinateRoot)))
|
||||
|
||||
if (bodyBubbleDrawable.isSolidColor()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -290,6 +290,17 @@ public final class Projection {
|
||||
return bottomRight;
|
||||
}
|
||||
|
||||
public float[] toRelativeRadii(boolean isLTR) {
|
||||
float[] radii = new float[8];
|
||||
|
||||
radii[0] = radii[1] = isLTR ? topLeft : topRight;
|
||||
radii[2] = radii[3] = isLTR ? topRight : topLeft;
|
||||
radii[4] = radii[5] = isLTR ? bottomRight : bottomLeft;
|
||||
radii[6] = radii[7] = isLTR ? bottomLeft : bottomRight;
|
||||
|
||||
return radii;
|
||||
}
|
||||
|
||||
public float[] toRadii() {
|
||||
float[] radii = new float[8];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user