From 17962b57a052593827628d2db9932318ce2cb514 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 12 Apr 2020 14:10:51 +0430 Subject: [PATCH] Use more optimized way to detect direction in PagerIndicatorView --- .../java/de/danoeh/antennapod/view/PagerIndicatorView.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/view/PagerIndicatorView.java b/app/src/main/java/de/danoeh/antennapod/view/PagerIndicatorView.java index 780ee0d88..240a565c8 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/PagerIndicatorView.java +++ b/app/src/main/java/de/danoeh/antennapod/view/PagerIndicatorView.java @@ -9,10 +9,13 @@ import android.util.AttributeSet; import android.view.View; import androidx.annotation.Nullable; +import androidx.core.text.TextUtilsCompat; import androidx.core.view.ViewCompat; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager2.widget.ViewPager2; +import java.util.Locale; + public class PagerIndicatorView extends View { private final Paint paint = new Paint(); private float position = 0; @@ -56,11 +59,13 @@ public class PagerIndicatorView extends View { invalidate(); } }); + boolean isLocaleRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) + == ViewCompat.LAYOUT_DIRECTION_RTL; pager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { PagerIndicatorView.this.position = position + positionOffset; - if (ViewCompat.getLayoutDirection(pager) == ViewCompat.LAYOUT_DIRECTION_RTL) { + if (isLocaleRtl) { PagerIndicatorView.this.position = numPages - 1 - PagerIndicatorView.this.position; } invalidate();