Fix shape of message bubbles in RTL langauges.

Fixes #9894
fork-5.53.8
Fumiaki Yoshimatsu 2021-03-05 17:36:40 -05:00 zatwierdzone przez Cody Henthorne
rodzic c36f9646f9
commit 22d5fc6cba
8 zmienionych plików z 157 dodań i 41 usunięć

Wyświetl plik

@ -28,6 +28,7 @@ import java.text.SimpleDateFormat;
import java.util.Locale; import java.util.Locale;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import org.thoughtcrime.securesms.util.ViewUtil;
/** /**
* The view shown in the compose box or conversation that represents the state of the link preview. * The view shown in the compose box or conversation that represents the state of the link preview.
@ -181,10 +182,16 @@ public class LinkPreviewView extends FrameLayout {
} }
} }
public void setCorners(int topLeft, int topRight) { public void setCorners(int topStart, int topEnd) {
cornerMask.setRadii(topLeft, topRight, 0, 0); if (ViewUtil.isRtl(this)) {
outliner.setRadii(topLeft, topRight, 0, 0); cornerMask.setRadii(topEnd, topStart, 0, 0);
thumbnail.setCorners(topLeft, defaultRadius, defaultRadius, defaultRadius); outliner.setRadii(topEnd, topStart, 0, 0);
thumbnail.setCorners(defaultRadius, topEnd, defaultRadius, defaultRadius);
} else {
cornerMask.setRadii(topStart, topEnd, 0, 0);
outliner.setRadii(topStart, topEnd, 0, 0);
thumbnail.setCorners(topStart, defaultRadius, defaultRadius, defaultRadius);
}
postInvalidate(); postInvalidate();
} }

Wyświetl plik

@ -889,59 +889,63 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
int defaultRadius = readDimen(R.dimen.message_corner_radius); int defaultRadius = readDimen(R.dimen.message_corner_radius);
int collapseRadius = readDimen(R.dimen.message_corner_collapse_radius); int collapseRadius = readDimen(R.dimen.message_corner_collapse_radius);
int topLeft = defaultRadius; int topStart = defaultRadius;
int topRight = defaultRadius; int topEnd = defaultRadius;
int bottomLeft = defaultRadius; int bottomStart = defaultRadius;
int bottomRight = defaultRadius; int bottomEnd = defaultRadius;
if (isSingularMessage(current, previous, next, isGroupThread)) { if (isSingularMessage(current, previous, next, isGroupThread)) {
topLeft = defaultRadius; topStart = defaultRadius;
topRight = defaultRadius; topEnd = defaultRadius;
bottomLeft = defaultRadius; bottomStart = defaultRadius;
bottomRight = defaultRadius; bottomEnd = defaultRadius;
} else if (isStartOfMessageCluster(current, previous, isGroupThread)) { } else if (isStartOfMessageCluster(current, previous, isGroupThread)) {
if (current.isOutgoing()) { if (current.isOutgoing()) {
bottomRight = collapseRadius; bottomEnd = collapseRadius;
} else { } else {
bottomLeft = collapseRadius; bottomStart = collapseRadius;
} }
} else if (isEndOfMessageCluster(current, next, isGroupThread)) { } else if (isEndOfMessageCluster(current, next, isGroupThread)) {
if (current.isOutgoing()) { if (current.isOutgoing()) {
topRight = collapseRadius; topEnd = collapseRadius;
} else { } else {
topLeft = collapseRadius; topStart = collapseRadius;
} }
} else { } else {
if (current.isOutgoing()) { if (current.isOutgoing()) {
topRight = collapseRadius; topEnd = collapseRadius;
bottomRight = collapseRadius; bottomEnd = collapseRadius;
} else { } else {
topLeft = collapseRadius; topStart = collapseRadius;
bottomLeft = collapseRadius; bottomStart = collapseRadius;
} }
} }
if (!TextUtils.isEmpty(current.getDisplayBody(getContext()))) { if (!TextUtils.isEmpty(current.getDisplayBody(getContext()))) {
bottomLeft = 0; bottomStart = 0;
bottomRight = 0; bottomEnd = 0;
} }
if (isStartOfMessageCluster(current, previous, isGroupThread) && !current.isOutgoing() && isGroupThread) { if (isStartOfMessageCluster(current, previous, isGroupThread) && !current.isOutgoing() && isGroupThread) {
topLeft = 0; topStart = 0;
topRight = 0; topEnd = 0;
} }
if (hasQuote(messageRecord)) { if (hasQuote(messageRecord)) {
topLeft = 0; topStart = 0;
topRight = 0; topEnd = 0;
} }
if (hasLinkPreview(messageRecord) || hasExtraText(messageRecord)) { if (hasLinkPreview(messageRecord) || hasExtraText(messageRecord)) {
bottomLeft = 0; bottomStart = 0;
bottomRight = 0; bottomEnd = 0;
} }
mediaThumbnailStub.get().setCorners(topLeft, topRight, bottomRight, bottomLeft); if (ViewUtil.isRtl(this)) {
mediaThumbnailStub.get().setCorners(topEnd, topStart, bottomStart, bottomEnd);
} else {
mediaThumbnailStub.get().setCorners(topStart, topEnd, bottomEnd, bottomStart);
}
} }
private void setSharedContactCorners(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) { private void setSharedContactCorners(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
@ -1229,6 +1233,14 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
} }
} }
private void setOutlinerRadii(Outliner outliner, int topStart, int topEnd, int bottomEnd, int bottomStart) {
if (ViewUtil.isRtl(this)) {
outliner.setRadii(topEnd, topStart, bottomStart, bottomEnd);
} else {
outliner.setRadii(topStart, topEnd, bottomEnd, bottomStart);
}
}
private void setMessageShape(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) { private void setMessageShape(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
int bigRadius = readDimen(R.dimen.message_corner_radius); int bigRadius = readDimen(R.dimen.message_corner_radius);
int smallRadius = readDimen(R.dimen.message_corner_collapse_radius); int smallRadius = readDimen(R.dimen.message_corner_collapse_radius);
@ -1248,32 +1260,32 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
} else if (isStartOfMessageCluster(current, previous, isGroupThread)) { } else if (isStartOfMessageCluster(current, previous, isGroupThread)) {
if (current.isOutgoing()) { if (current.isOutgoing()) {
background = R.drawable.message_bubble_background_sent_start; background = R.drawable.message_bubble_background_sent_start;
outliner.setRadii(bigRadius, bigRadius, smallRadius, bigRadius); setOutlinerRadii(outliner, bigRadius, bigRadius, smallRadius, bigRadius);
pulseOutliner.setRadii(bigRadius, bigRadius, smallRadius, bigRadius); setOutlinerRadii(pulseOutliner, bigRadius, bigRadius, smallRadius, bigRadius);
} else { } else {
background = R.drawable.message_bubble_background_received_start; background = R.drawable.message_bubble_background_received_start;
outliner.setRadii(bigRadius, bigRadius, bigRadius, smallRadius); setOutlinerRadii(outliner, bigRadius, bigRadius, bigRadius, smallRadius);
pulseOutliner.setRadii(bigRadius, bigRadius, bigRadius, smallRadius); setOutlinerRadii(pulseOutliner, bigRadius, bigRadius, bigRadius, smallRadius);
} }
} else if (isEndOfMessageCluster(current, next, isGroupThread)) { } else if (isEndOfMessageCluster(current, next, isGroupThread)) {
if (current.isOutgoing()) { if (current.isOutgoing()) {
background = R.drawable.message_bubble_background_sent_end; background = R.drawable.message_bubble_background_sent_end;
outliner.setRadii(bigRadius, smallRadius, bigRadius, bigRadius); setOutlinerRadii(outliner, bigRadius, smallRadius, bigRadius, bigRadius);
pulseOutliner.setRadii(bigRadius, smallRadius, bigRadius, bigRadius); setOutlinerRadii(pulseOutliner, bigRadius, smallRadius, bigRadius, bigRadius);
} else { } else {
background = R.drawable.message_bubble_background_received_end; background = R.drawable.message_bubble_background_received_end;
outliner.setRadii(smallRadius, bigRadius, bigRadius, bigRadius); setOutlinerRadii(outliner, smallRadius, bigRadius, bigRadius, bigRadius);
pulseOutliner.setRadii(smallRadius, bigRadius, bigRadius, bigRadius); setOutlinerRadii(pulseOutliner, smallRadius, bigRadius, bigRadius, bigRadius);
} }
} else { } else {
if (current.isOutgoing()) { if (current.isOutgoing()) {
background = R.drawable.message_bubble_background_sent_middle; background = R.drawable.message_bubble_background_sent_middle;
outliner.setRadii(bigRadius, smallRadius, smallRadius, bigRadius); setOutlinerRadii(outliner, bigRadius, smallRadius, smallRadius, bigRadius);
pulseOutliner.setRadii(bigRadius, smallRadius, smallRadius, bigRadius); setOutlinerRadii(pulseOutliner, bigRadius, smallRadius, smallRadius, bigRadius);
} else { } else {
background = R.drawable.message_bubble_background_received_middle; background = R.drawable.message_bubble_background_received_middle;
outliner.setRadii(smallRadius, bigRadius, bigRadius, smallRadius); setOutlinerRadii(outliner, smallRadius, bigRadius, bigRadius, smallRadius);
pulseOutliner.setRadii(smallRadius, bigRadius, bigRadius, smallRadius); setOutlinerRadii(pulseOutliner, smallRadius, bigRadius, bigRadius, smallRadius);
} }
} }

Wyświetl plik

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="2px"
android:top="2px">
<shape android:shape="rectangle">
<corners
android:bottomLeftRadius="@dimen/message_corner_radius"
android:bottomRightRadius="@dimen/message_corner_radius"
android:topLeftRadius="@dimen/message_corner_radius"
android:topRightRadius="@dimen/message_corner_collapse_radius" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>

Wyświetl plik

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="2px"
android:top="2px">
<shape android:shape="rectangle">
<corners
android:bottomLeftRadius="@dimen/message_corner_radius"
android:bottomRightRadius="@dimen/message_corner_collapse_radius"
android:topLeftRadius="@dimen/message_corner_radius"
android:topRightRadius="@dimen/message_corner_collapse_radius" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>

Wyświetl plik

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="2px"
android:top="2px">
<shape android:shape="rectangle">
<corners
android:bottomLeftRadius="@dimen/message_corner_radius"
android:bottomRightRadius="@dimen/message_corner_collapse_radius"
android:topLeftRadius="@dimen/message_corner_radius"
android:topRightRadius="@dimen/message_corner_radius" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>

Wyświetl plik

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="2px"
android:bottom="2px">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="@dimen/message_corner_collapse_radius"
android:topRightRadius="@dimen/message_corner_radius"
android:bottomRightRadius="@dimen/message_corner_radius"
android:bottomLeftRadius="@dimen/message_corner_radius" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>

Wyświetl plik

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="2px"
android:bottom="2px">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="@dimen/message_corner_collapse_radius"
android:topRightRadius="@dimen/message_corner_radius"
android:bottomLeftRadius="@dimen/message_corner_collapse_radius"
android:bottomRightRadius="@dimen/message_corner_radius" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>

Wyświetl plik

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="2px"
android:bottom="2px">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="@dimen/message_corner_radius"
android:topRightRadius="@dimen/message_corner_radius"
android:bottomLeftRadius="@dimen/message_corner_collapse_radius"
android:bottomRightRadius="@dimen/message_corner_radius" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>