Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bba04ac3 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Properly handle RTL on the preview pager

Bug: 129147364
Change-Id: I9021399a6615543f559121aca67bc1b62255b4d1
parent 5036f199
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
@@ -43,11 +44,12 @@
            android:id="@+id/arrow_previous"
            android:layout_width="@dimen/indicator_arrow_touch_area_size"
            android:layout_height="@dimen/indicator_arrow_touch_area_size"
            android:layout_gravity="center_vertical|start"
            android:layout_gravity="center_vertical|left"
            android:layout_marginStart="@dimen/indicator_arrow_container_margin_horizontal"
            android:background="?android:attr/selectableItemBackgroundBorderless"
            android:contentDescription="@string/previous_page_content_description"
            android:visibility="gone">
            android:visibility="gone"
            tools:ignore="RtlHardcoded">

            <ImageView
                android:layout_width="@dimen/indicator_arrow_size"
@@ -62,11 +64,12 @@
            android:id="@+id/arrow_next"
            android:layout_width="@dimen/indicator_arrow_touch_area_size"
            android:layout_height="@dimen/indicator_arrow_touch_area_size"
            android:layout_gravity="center_vertical|end"
            android:layout_gravity="center_vertical|right"
            android:layout_marginEnd="@dimen/indicator_arrow_container_margin_horizontal"
            android:background="?android:attr/selectableItemBackgroundBorderless"
            android:contentDescription="@string/next_page_content_description"
            android:visibility="gone">
            android:visibility="gone"
            tools:ignore="RtlHardcoded">

            <ImageView
                android:layout_width="@dimen/indicator_arrow_size"
+17 −3
Original line number Diff line number Diff line
@@ -23,16 +23,19 @@ import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.core.text.TextUtilsCompat;
import androidx.core.view.ViewCompat;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;

import com.android.wallpaper.R;

import java.util.Locale;

/**
 * A Widget consisting of a ViewPager linked to a PageIndicator and previous/next arrows that can be
 * used to page over that ViewPager.
@@ -72,6 +75,8 @@ public class PreviewPager extends LinearLayout {

        mPageStyle = a.getInteger(R.styleable.PreviewPager_card_style, STYLE_PEEKING);

        a.recycle();

        mViewPager = findViewById(R.id.preview_viewpager);
        mViewPager.setPageMargin(res.getDimensionPixelOffset(R.dimen.preview_page_gap));
        mViewPager.setClipToPadding(false);
@@ -148,7 +153,16 @@ public class PreviewPager extends LinearLayout {
    public void setAdapter(PagerAdapter adapter) {
        mAdapter = adapter;
        mViewPager.setAdapter(adapter);

        if (ViewCompat.isLayoutDirectionResolved(mViewPager)) {
            if (ViewCompat.getLayoutDirection(mViewPager) == ViewCompat.LAYOUT_DIRECTION_RTL) {
                mViewPager.setCurrentItem(mAdapter.getCount() - 1);
            }
        } else {
            if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault())
                    == ViewCompat.LAYOUT_DIRECTION_RTL) {
                mViewPager.setCurrentItem(mAdapter.getCount() - 1);
            }
        }
        mAdapter.registerDataSetObserver(new DataSetObserver() {
            @Override
            public void onChanged() {