kopia lustrzana https://github.com/ryukoposting/Signal-Android
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.fork-5.53.8
rodzic
432a732e7c
commit
2a3f85008b
|
@ -76,6 +76,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.UsernameUtil;
|
import org.thoughtcrime.securesms.util.UsernameUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
import org.thoughtcrime.securesms.util.adapter.FixedViewsAdapter;
|
import org.thoughtcrime.securesms.util.adapter.FixedViewsAdapter;
|
||||||
import org.thoughtcrime.securesms.util.adapter.RecyclerViewConcatenateAdapterStickyHeader;
|
import org.thoughtcrime.securesms.util.adapter.RecyclerViewConcatenateAdapterStickyHeader;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||||
|
@ -672,7 +673,7 @@ public final class ContactSelectionListFragment extends LoggingFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
private void smoothScrollChipsToEnd() {
|
private void smoothScrollChipsToEnd() {
|
||||||
int x = chipGroupScrollContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR ? chipGroup.getWidth() : 0;
|
int x = ViewUtil.isLtr(chipGroupScrollContainer) ? chipGroup.getWidth() : 0;
|
||||||
chipGroupScrollContainer.smoothScrollTo(x, 0);
|
chipGroupScrollContainer.smoothScrollTo(x, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,8 +275,8 @@ public class ConversationItemFooter extends LinearLayout {
|
||||||
addView(audioDuration, 0);
|
addView(audioDuration, 0);
|
||||||
|
|
||||||
int padStart = ViewUtil.dpToPx(60);
|
int padStart = ViewUtil.dpToPx(60);
|
||||||
int padLeft = getLayoutDirection() == LAYOUT_DIRECTION_LTR ? padStart : 0;
|
int padLeft = ViewUtil.isLtr(this) ? padStart : 0;
|
||||||
int padRight = getLayoutDirection() == LAYOUT_DIRECTION_RTL ? padStart : 0;
|
int padRight = ViewUtil.isRtl(this) ? padStart : 0;
|
||||||
|
|
||||||
audioDuration.setPadding(padLeft, 0, padRight, 0);
|
audioDuration.setPadding(padLeft, 0, padRight, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,11 +335,10 @@ public class InputPanel extends LinearLayout
|
||||||
public void onRecordMoved(float offsetX, float absoluteX) {
|
public void onRecordMoved(float offsetX, float absoluteX) {
|
||||||
slideToCancel.moveTo(offsetX);
|
slideToCancel.moveTo(offsetX);
|
||||||
|
|
||||||
int direction = ViewCompat.getLayoutDirection(this);
|
|
||||||
float position = absoluteX / recordingContainer.getWidth();
|
float position = absoluteX / recordingContainer.getWidth();
|
||||||
|
|
||||||
if (direction == ViewCompat.LAYOUT_DIRECTION_LTR && position <= 0.5 ||
|
if (ViewUtil.isLtr(this) && position <= 0.5 ||
|
||||||
direction == ViewCompat.LAYOUT_DIRECTION_RTL && position >= 0.6)
|
ViewUtil.isRtl(this) && position >= 0.6)
|
||||||
{
|
{
|
||||||
this.microphoneRecorderView.cancelAction();
|
this.microphoneRecorderView.cancelAction();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.constraintlayout.widget.Guideline;
|
import androidx.constraintlayout.widget.Guideline;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
public class InsetAwareConstraintLayout extends ConstraintLayout {
|
public class InsetAwareConstraintLayout extends ConstraintLayout {
|
||||||
|
|
||||||
|
@ -45,11 +46,19 @@ public class InsetAwareConstraintLayout extends ConstraintLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentStartGuideline != null) {
|
if (parentStartGuideline != null) {
|
||||||
|
if (ViewUtil.isLtr(this)) {
|
||||||
parentStartGuideline.setGuidelineBegin(insets.left);
|
parentStartGuideline.setGuidelineBegin(insets.left);
|
||||||
|
} else {
|
||||||
|
parentStartGuideline.setGuidelineBegin(insets.right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentEndGuideline != null) {
|
if (parentEndGuideline != null) {
|
||||||
|
if (ViewUtil.isLtr(this)) {
|
||||||
parentEndGuideline.setGuidelineEnd(insets.right);
|
parentEndGuideline.setGuidelineEnd(insets.right);
|
||||||
|
} else {
|
||||||
|
parentEndGuideline.setGuidelineEnd(insets.left);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import androidx.core.view.ViewCompat;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
public final class MicrophoneRecorderView extends FrameLayout implements View.OnTouchListener {
|
public final class MicrophoneRecorderView extends FrameLayout implements View.OnTouchListener {
|
||||||
|
|
||||||
|
@ -224,8 +225,8 @@ public final class MicrophoneRecorderView extends FrameLayout implements View.On
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getXOffset(float x) {
|
private float getXOffset(float x) {
|
||||||
return ViewCompat.getLayoutDirection(recordButtonFab) == ViewCompat.LAYOUT_DIRECTION_LTR ?
|
return ViewUtil.isLtr(recordButtonFab) ? -Math.max(0, this.startPositionX - x)
|
||||||
-Math.max(0, this.startPositionX - x) : Math.max(0, x - this.startPositionX);
|
: Math.max(0, x - this.startPositionX);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getYOffset(float y) {
|
private float getYOffset(float y) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import androidx.core.view.GestureDetectorCompat;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.animation.AnimationCompleteListener;
|
import org.thoughtcrime.securesms.animation.AnimationCompleteListener;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
import org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout;
|
import org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -259,7 +260,7 @@ public class PictureInPictureGestureHelper extends GestureDetector.SimpleOnGestu
|
||||||
|
|
||||||
private Point findNearestCornerPosition(Point projection) {
|
private Point findNearestCornerPosition(Point projection) {
|
||||||
if (isLockedToBottomEnd) {
|
if (isLockedToBottomEnd) {
|
||||||
return parent.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR ? calculateBottomRightCoordinates(parent)
|
return ViewUtil.isLtr(parent) ? calculateBottomRightCoordinates(parent)
|
||||||
: calculateBottomLeftCoordinates(parent);
|
: calculateBottomLeftCoordinates(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1084,7 +1084,7 @@ public class ConversationFragment extends LoggingFragment {
|
||||||
|
|
||||||
private void maybeShowSwipeToReplyTooltip() {
|
private void maybeShowSwipeToReplyTooltip() {
|
||||||
if (!TextSecurePreferences.hasSeenSwipeToReplyTooltip(requireContext())) {
|
if (!TextSecurePreferences.hasSeenSwipeToReplyTooltip(requireContext())) {
|
||||||
int text = getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR ? R.string.ConversationFragment_you_can_swipe_to_the_right_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;
|
: R.string.ConversationFragment_you_can_swipe_to_the_left_reply;
|
||||||
TooltipPopup.forTarget(requireActivity().findViewById(R.id.menu_context_reply))
|
TooltipPopup.forTarget(requireActivity().findViewById(R.id.menu_context_reply))
|
||||||
.setText(text)
|
.setText(text)
|
||||||
|
|
|
@ -176,10 +176,10 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
||||||
|
|
||||||
final float halfWidth = scrubberWidth / 2f + scrubberHorizontalMargin;
|
final float halfWidth = scrubberWidth / 2f + scrubberHorizontalMargin;
|
||||||
final float screenWidth = getResources().getDisplayMetrics().widthPixels;
|
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,
|
final float scrubberTranslationX = Util.clamp(downX - halfWidth,
|
||||||
scrubberHorizontalMargin,
|
scrubberHorizontalMargin,
|
||||||
screenWidth + scrubberHorizontalMargin - halfWidth * 2) * (getLayoutDirection() == LAYOUT_DIRECTION_LTR ? 1 : -1);
|
screenWidth + scrubberHorizontalMargin - halfWidth * 2) * (ViewUtil.isLtr(this) ? 1 : -1);
|
||||||
|
|
||||||
backgroundView.setTranslationX(scrubberTranslationX);
|
backgroundView.setTranslationX(scrubberTranslationX);
|
||||||
backgroundView.setTranslationY(scrubberTranslationY);
|
backgroundView.setTranslationY(scrubberTranslationY);
|
||||||
|
@ -275,7 +275,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStart(@NonNull Rect rect) {
|
private int getStart(@NonNull Rect rect) {
|
||||||
if (getLayoutDirection() == LAYOUT_DIRECTION_LTR) {
|
if (ViewUtil.isLtr(this)) {
|
||||||
return rect.left;
|
return rect.left;
|
||||||
} else {
|
} else {
|
||||||
return rect.right;
|
return rect.right;
|
||||||
|
@ -283,7 +283,7 @@ public final class ConversationReactionOverlay extends RelativeLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getEnd(@NonNull Rect rect) {
|
private int getEnd(@NonNull Rect rect) {
|
||||||
if (getLayoutDirection() == LAYOUT_DIRECTION_LTR) {
|
if (ViewUtil.isLtr(this)) {
|
||||||
return rect.right;
|
return rect.right;
|
||||||
} else {
|
} else {
|
||||||
return rect.left;
|
return rect.left;
|
||||||
|
|
|
@ -60,6 +60,7 @@ import org.thoughtcrime.securesms.util.AsynchronousCallback;
|
||||||
import org.thoughtcrime.securesms.util.DateUtils;
|
import org.thoughtcrime.securesms.util.DateUtils;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
import org.thoughtcrime.securesms.util.LifecycleCursorWrapper;
|
import org.thoughtcrime.securesms.util.LifecycleCursorWrapper;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
import org.thoughtcrime.securesms.util.views.LearnMoreTextView;
|
import org.thoughtcrime.securesms.util.views.LearnMoreTextView;
|
||||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
||||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaperActivity;
|
import org.thoughtcrime.securesms.wallpaper.ChatWallpaperActivity;
|
||||||
|
@ -261,7 +262,7 @@ public class ManageGroupFragment extends LoggingFragment {
|
||||||
threadPhotoRailView.setListener(mediaRecord ->
|
threadPhotoRailView.setListener(mediaRecord ->
|
||||||
startActivityForResult(MediaPreviewActivity.intentFromMediaRecord(context,
|
startActivityForResult(MediaPreviewActivity.intentFromMediaRecord(context,
|
||||||
mediaRecord,
|
mediaRecord,
|
||||||
ViewCompat.getLayoutDirection(threadPhotoRailView) == ViewCompat.LAYOUT_DIRECTION_LTR),
|
ViewUtil.isLtr(threadPhotoRailView)),
|
||||||
RETURN_FROM_MEDIA));
|
RETURN_FROM_MEDIA));
|
||||||
|
|
||||||
groupLinkCard.setVisibility(vs.getGroupRecipient().requireGroupId().isV2() ? View.VISIBLE : View.GONE);
|
groupLinkCard.setVisibility(vs.getGroupRecipient().requireGroupId().isV2() ? View.VISIBLE : View.GONE);
|
||||||
|
|
|
@ -16,6 +16,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ public final class RecipientSettingsCoordinatorLayoutBehavior extends Coordinato
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getStart(@NonNull CoordinatorLayout parent, @NonNull Rect rect) {
|
private static int getStart(@NonNull CoordinatorLayout parent, @NonNull Rect rect) {
|
||||||
return parent.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR ? rect.left : rect.right;
|
return ViewUtil.isLtr(parent) ? rect.left : rect.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ViewReference {
|
private static final class ViewReference {
|
||||||
|
|
|
@ -54,6 +54,7 @@ import org.thoughtcrime.securesms.util.DateUtils;
|
||||||
import org.thoughtcrime.securesms.util.LifecycleCursorWrapper;
|
import org.thoughtcrime.securesms.util.LifecycleCursorWrapper;
|
||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaperActivity;
|
import org.thoughtcrime.securesms.wallpaper.ChatWallpaperActivity;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -351,7 +352,7 @@ public class ManageRecipientFragment extends LoggingFragment {
|
||||||
threadPhotoRailView.setListener(mediaRecord ->
|
threadPhotoRailView.setListener(mediaRecord ->
|
||||||
startActivityForResult(MediaPreviewActivity.intentFromMediaRecord(requireContext(),
|
startActivityForResult(MediaPreviewActivity.intentFromMediaRecord(requireContext(),
|
||||||
mediaRecord,
|
mediaRecord,
|
||||||
ViewCompat.getLayoutDirection(threadPhotoRailView) == ViewCompat.LAYOUT_DIRECTION_LTR),
|
ViewUtil.isLtr(threadPhotoRailView)),
|
||||||
REQUEST_CODE_RETURN_FROM_MEDIA));
|
REQUEST_CODE_RETURN_FROM_MEDIA));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.util;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
@ -166,7 +167,7 @@ public final class ViewUtil {
|
||||||
|
|
||||||
@SuppressLint("RtlHardcoded")
|
@SuppressLint("RtlHardcoded")
|
||||||
public static void setTextViewGravityStart(final @NonNull TextView textView, @NonNull Context context) {
|
public static void setTextViewGravityStart(final @NonNull TextView textView, @NonNull Context context) {
|
||||||
if (DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
|
if (isRtl(context)) {
|
||||||
textView.setGravity(Gravity.RIGHT);
|
textView.setGravity(Gravity.RIGHT);
|
||||||
} else {
|
} else {
|
||||||
textView.setGravity(Gravity.LEFT);
|
textView.setGravity(Gravity.LEFT);
|
||||||
|
@ -174,11 +175,27 @@ public final class ViewUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void mirrorIfRtl(View view, Context context) {
|
public static void mirrorIfRtl(View view, Context context) {
|
||||||
if (DynamicLanguage.getLayoutDirection(context) == View.LAYOUT_DIRECTION_RTL) {
|
if (isRtl(context)) {
|
||||||
view.setScaleX(-1.0f);
|
view.setScaleX(-1.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isLtr(@NonNull View view) {
|
||||||
|
return isLtr(view.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isLtr(@NonNull Context context) {
|
||||||
|
return context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRtl(@NonNull View view) {
|
||||||
|
return isRtl(view.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRtl(@NonNull Context context) {
|
||||||
|
return context.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||||
|
}
|
||||||
|
|
||||||
public static float pxToDp(float px) {
|
public static float pxToDp(float px) {
|
||||||
return px / Resources.getSystem().getDisplayMetrics().density;
|
return px / Resources.getSystem().getDisplayMetrics().density;
|
||||||
}
|
}
|
||||||
|
@ -212,21 +229,21 @@ public final class ViewUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getLeftMargin(@NonNull View view) {
|
public static int getLeftMargin(@NonNull View view) {
|
||||||
if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_LTR) {
|
if (isLtr(view)) {
|
||||||
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin;
|
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin;
|
||||||
}
|
}
|
||||||
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin;
|
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRightMargin(@NonNull View view) {
|
public static int getRightMargin(@NonNull View view) {
|
||||||
if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_LTR) {
|
if (isLtr(view)) {
|
||||||
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin;
|
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin;
|
||||||
}
|
}
|
||||||
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin;
|
return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLeftMargin(@NonNull View view, int margin) {
|
public static void setLeftMargin(@NonNull View view, int margin) {
|
||||||
if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_LTR) {
|
if (isLtr(view)) {
|
||||||
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin = margin;
|
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin = margin;
|
||||||
} else {
|
} else {
|
||||||
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin = margin;
|
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin = margin;
|
||||||
|
@ -236,7 +253,7 @@ public final class ViewUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setRightMargin(@NonNull View view, int margin) {
|
public static void setRightMargin(@NonNull View view, int margin) {
|
||||||
if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_LTR) {
|
if (isLtr(view)) {
|
||||||
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin = margin;
|
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).rightMargin = margin;
|
||||||
} else {
|
} else {
|
||||||
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin = margin;
|
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin = margin;
|
||||||
|
@ -268,7 +285,7 @@ public final class ViewUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPaddingStart(@NonNull View view, int padding) {
|
public static void setPaddingStart(@NonNull View view, int padding) {
|
||||||
if (view.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR) {
|
if (isLtr(view)) {
|
||||||
view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
|
view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
|
||||||
} else {
|
} else {
|
||||||
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), padding, view.getPaddingBottom());
|
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), padding, view.getPaddingBottom());
|
||||||
|
@ -276,10 +293,10 @@ public final class ViewUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPaddingEnd(@NonNull View view, int padding) {
|
public static void setPaddingEnd(@NonNull View view, int padding) {
|
||||||
if (view.getLayoutDirection() != View.LAYOUT_DIRECTION_LTR) {
|
if (isLtr(view)) {
|
||||||
view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
|
|
||||||
} else {
|
|
||||||
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), padding, view.getPaddingBottom());
|
view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), padding, view.getPaddingBottom());
|
||||||
|
} else {
|
||||||
|
view.setPadding(padding, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ import android.view.ViewGroup;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
class ChatWallpaperAlignmentDecoration extends RecyclerView.ItemDecoration {
|
class ChatWallpaperAlignmentDecoration extends RecyclerView.ItemDecoration {
|
||||||
@Override
|
@Override
|
||||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||||
|
@ -27,14 +29,14 @@ class ChatWallpaperAlignmentDecoration extends RecyclerView.ItemDecoration {
|
||||||
|
|
||||||
int extraCellsNeeded = itemsPerRow - ((itemPosition + 1) % itemsPerRow);
|
int extraCellsNeeded = itemsPerRow - ((itemPosition + 1) % itemsPerRow);
|
||||||
|
|
||||||
setEnd(outRect, view.getLayoutDirection(), extraCellsNeeded * viewWidth);
|
setEnd(outRect, ViewUtil.isLtr(view), extraCellsNeeded * viewWidth);
|
||||||
} else {
|
} else {
|
||||||
super.getItemOffsets(outRect, view, parent, state);
|
super.getItemOffsets(outRect, view, parent, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEnd(@NonNull Rect outRect, int layoutDirection, int end) {
|
private void setEnd(@NonNull Rect outRect, boolean ltr, int end) {
|
||||||
if (layoutDirection == View.LAYOUT_DIRECTION_LTR) {
|
if (ltr) {
|
||||||
outRect.right = end;
|
outRect.right = end;
|
||||||
} else {
|
} else {
|
||||||
outRect.left = end;
|
outRect.left = end;
|
||||||
|
|
Ładowanie…
Reference in New Issue