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

Commit d1c4052f authored by Wenbo Jie (介文博)'s avatar Wenbo Jie (介文博) Committed by Android (Google) Code Review
Browse files

Merge "[DocsUI] Click search chip should reset scroll view" into main

parents 0c4bfe79 ff7dd896
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -521,7 +521,7 @@ public class SearchChipViewManager {
            }

            // Let the first checked chip can be shown.
            View parent = (View) mChipGroup.getParent();
            View parent = (View) mChipGroup.getParent().getParent();
            if (parent instanceof HorizontalScrollView) {
                final int scrollToX = isRtl ? parent.getWidth() : 0;
                ((HorizontalScrollView) parent).smoothScrollTo(scrollToX, 0);
+35 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.documentsui.queries;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;

@@ -35,6 +36,9 @@ import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.DocumentsContract;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -235,6 +239,37 @@ public final class SearchChipViewManagerTest {
        assertThat(View.VISIBLE).isEqualTo(mirror.getVisibility());
    }

    @Test
    public void testChipChecked_resetScroll() {
        // Mock chip group's parent chain according to search_chip_row.xml.
        FrameLayout parent = spy(new FrameLayout(mContext));
        HorizontalScrollView grandparent = spy(new HorizontalScrollView(mContext));
        parent.addView(mChipGroup);
        grandparent.addView(parent);
        // Verify that getParent().getParent() returns the HorizontalScrollView mock.
        ViewParent result = mChipGroup.getParent().getParent();
        assertEquals(grandparent, result);

        mSearchChipViewManager.initChipSets(
                new String[] {"image/*", "audio/*", "video/*", "text/*"});
        mSearchChipViewManager.updateChips(new String[] {"*/*"});

        // Manually set HorizontalScrollView's scrollX to something larger than 0.
        grandparent.scrollTo(100, 0);
        assertTrue(grandparent.getScaleX() > 0);

        assertEquals(6, mChipGroup.getChildCount());
        Chip lastChip = (Chip) mChipGroup.getChildAt(5);

        // chip.setChecked will trigger reorder animation, which needs to be run inside
        // the looper thread.
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            // Check last chip will move it to the first child and reset scroll view.
            lastChip.setChecked(true);
            assertEquals(0, grandparent.getScrollX());
        });
    }

    private static Set<SearchChipData> getFakeSearchChipDataList() {
        final Set<SearchChipData> chipDataList = new HashSet<>();
        chipDataList.add(new SearchChipData(CHIP_TYPE, 0 /* titleRes */, TEST_MIME_TYPES));