Do not use View.getLayoutDirection().

This value doesn't populate until after the first layout pass. Instead,
it appears to be safer to just read it from the Configuration.
This commit is contained in:
Greyson Parrelli
2021-02-11 10:41:40 -05:00
committed by GitHub
parent 432a732e7c
commit 2a3f85008b
13 changed files with 68 additions and 35 deletions

View File

@@ -1084,8 +1084,8 @@ public class ConversationFragment extends LoggingFragment {
private void maybeShowSwipeToReplyTooltip() {
if (!TextSecurePreferences.hasSeenSwipeToReplyTooltip(requireContext())) {
int text = getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR ? R.string.ConversationFragment_you_can_swipe_to_the_right_reply
: R.string.ConversationFragment_you_can_swipe_to_the_left_reply;
int text = ViewUtil.isLtr(requireContext()) ? R.string.ConversationFragment_you_can_swipe_to_the_right_reply
: R.string.ConversationFragment_you_can_swipe_to_the_left_reply;
TooltipPopup.forTarget(requireActivity().findViewById(R.id.menu_context_reply))
.setText(text)
.setTextColor(getResources().getColor(R.color.core_white))

View File

@@ -176,10 +176,10 @@ public final class ConversationReactionOverlay extends RelativeLayout {
final float halfWidth = scrubberWidth / 2f + scrubberHorizontalMargin;
final float screenWidth = getResources().getDisplayMetrics().widthPixels;
final float downX = getLayoutDirection() == LAYOUT_DIRECTION_LTR ? lastSeenDownPoint.x : screenWidth - lastSeenDownPoint.x;
final float downX = ViewUtil.isLtr(this) ? lastSeenDownPoint.x : screenWidth - lastSeenDownPoint.x;
final float scrubberTranslationX = Util.clamp(downX - halfWidth,
scrubberHorizontalMargin,
screenWidth + scrubberHorizontalMargin - halfWidth * 2) * (getLayoutDirection() == LAYOUT_DIRECTION_LTR ? 1 : -1);
screenWidth + scrubberHorizontalMargin - halfWidth * 2) * (ViewUtil.isLtr(this) ? 1 : -1);
backgroundView.setTranslationX(scrubberTranslationX);
backgroundView.setTranslationY(scrubberTranslationY);
@@ -275,7 +275,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
}
private int getStart(@NonNull Rect rect) {
if (getLayoutDirection() == LAYOUT_DIRECTION_LTR) {
if (ViewUtil.isLtr(this)) {
return rect.left;
} else {
return rect.right;
@@ -283,7 +283,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
}
private int getEnd(@NonNull Rect rect) {
if (getLayoutDirection() == LAYOUT_DIRECTION_LTR) {
if (ViewUtil.isLtr(this)) {
return rect.right;
} else {
return rect.left;