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

Commit 649ecd41 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Run 'Format file' on all files that are getting changed" into main

parents 0a1934d7 c18605ea
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ package com.android.documentsui.sorting;
import android.animation.AnimatorInflater;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import androidx.annotation.AnimatorRes;
import androidx.annotation.StringRes;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
@@ -29,14 +27,14 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.AnimatorRes;
import androidx.annotation.StringRes;

import com.android.documentsui.R;
import com.android.documentsui.sorting.SortDimension;

/**
 * A clickable, sortable table header cell layout.
 *
 * It updates its display when it binds to {@link SortDimension} and changes the status of sorting
 * when it's clicked.
 * A clickable, sortable table header cell layout. It updates its display when it binds to {@link
 * SortDimension} and changes the status of sorting when it's clicked.
 */
public class HeaderCell extends LinearLayout {

@@ -62,7 +60,7 @@ public class HeaderCell extends LinearLayout {
        setVisibility(dimension.getVisibility());

        if (dimension.getVisibility() == View.VISIBLE) {
            TextView label = (TextView) findViewById(R.id.label);
            TextView label = findViewById(R.id.label);
            label.setText(dimension.getLabelId());
            switch (dimension.getDataType()) {
                case SortDimension.DATA_TYPE_NUMBER:
@@ -77,17 +75,21 @@ public class HeaderCell extends LinearLayout {
            }

            if (mCurDirection != dimension.getSortDirection()) {
                ImageView arrow = (ImageView) findViewById(R.id.sort_arrow);
                ImageView arrow = findViewById(R.id.sort_arrow);
                switch (dimension.getSortDirection()) {
                    case SortDimension.SORT_DIRECTION_NONE:
                        arrow.setVisibility(View.GONE);
                        break;
                    case SortDimension.SORT_DIRECTION_ASCENDING:
                        showArrow(arrow, R.animator.arrow_rotate_up,
                        showArrow(
                                arrow,
                                R.animator.arrow_rotate_up,
                                R.string.sort_direction_ascending);
                        break;
                    case SortDimension.SORT_DIRECTION_DESCENDING:
                        showArrow(arrow, R.animator.arrow_rotate_down,
                        showArrow(
                                arrow,
                                R.animator.arrow_rotate_down,
                                R.string.sort_direction_descending);
                        break;
                    default:
+17 −21
Original line number Diff line number Diff line
@@ -22,24 +22,19 @@ import com.android.documentsui.R;

import javax.annotation.Nullable;

/**
 * View controller for table header that associates header cells in table header and columns.
 */
/** View controller for table header that associates header cells in table header and columns. */
public final class TableHeaderController implements SortController.WidgetController {
    private View mTableHeader;

    private final HeaderCell mTitleCell;
    private final HeaderCell mSummaryCell;
    private final HeaderCell mSizeCell;
    private final HeaderCell mFileTypeCell;
    private final HeaderCell mDateCell;

    private final SortModel mModel;
    // We assign this here porque each method reference creates a new object
    // instance (which is wasteful).
    private final View.OnClickListener mOnCellClickListener = this::onCellClicked;
    private final SortModel.UpdateListener mModelListener = this::onModelUpdate;

    private final SortModel mModel;
    private final View mTableHeader;

    private TableHeaderController(SortModel sortModel, View tableHeader) {
        assert (sortModel != null);
@@ -48,17 +43,23 @@ public final class TableHeaderController implements SortController.WidgetControl
        mModel = sortModel;
        mTableHeader = tableHeader;

        mTitleCell = (HeaderCell) tableHeader.findViewById(android.R.id.title);
        mSummaryCell = (HeaderCell) tableHeader.findViewById(android.R.id.summary);
        mSizeCell = (HeaderCell) tableHeader.findViewById(R.id.size);
        mFileTypeCell = (HeaderCell) tableHeader.findViewById(R.id.file_type);
        mDateCell = (HeaderCell) tableHeader.findViewById(R.id.date);
        mTitleCell = tableHeader.findViewById(android.R.id.title);
        mSummaryCell = tableHeader.findViewById(android.R.id.summary);
        mSizeCell = tableHeader.findViewById(R.id.size);
        mFileTypeCell = tableHeader.findViewById(R.id.file_type);
        mDateCell = tableHeader.findViewById(R.id.date);

        onModelUpdate(mModel, SortModel.UPDATE_TYPE_UNSPECIFIED);

        mModel.addListener(mModelListener);
    }

    /** Creates a TableHeaderController. */
    public static @Nullable TableHeaderController create(
            SortModel sortModel, @Nullable View tableHeader) {
        return (tableHeader == null) ? null : new TableHeaderController(sortModel, tableHeader);
    }

    private void onModelUpdate(SortModel model, int updateTypeUnspecified) {
        bindCell(mTitleCell, SortModel.SORT_DIMENSION_ID_TITLE);
        bindCell(mSummaryCell, SortModel.SORT_DIMENSION_ID_SUMMARY);
@@ -97,9 +98,4 @@ public final class TableHeaderController implements SortController.WidgetControl

        mModel.sortByUser(dimension.getId(), dimension.getNextDirection());
    }

    public static @Nullable TableHeaderController create(
            SortModel sortModel, @Nullable View tableHeader) {
        return (tableHeader == null) ? null : new TableHeaderController(sortModel, tableHeader);
    }
}
+13 −14
Original line number Diff line number Diff line
@@ -49,10 +49,11 @@ import com.android.documentsui.sorting.SortModel;
import org.hamcrest.Matcher;

/**
 * A test helper class that provides support for controlling the UI Breadcrumb
 * programmatically, and making assertions against the state of the UI.
 * <p>
 * Support for working directly with Roots and Directory view can be found in the respective bots.
 * A test helper class that provides support for controlling the UI Breadcrumb programmatically, and
 * making assertions against the state of the UI.
 *
 * <p>Support for working directly with Roots and Directory view can be found in the respective
 * bots.
 */
public class SortBot extends Bots.BaseBot {

@@ -78,16 +79,15 @@ public class SortBot extends Bots.BaseBot {
            result = sortByMenu(id, direction);
        }

        assertTrue("Sorting by id: " + id + " in direction: " + direction + " failed.",
                result);
        assertTrue("Sorting by id: " + id + " in direction: " + direction + " failed.", result);
    }

    public boolean isHeaderShow() {
        return Matchers.present(mColumnBot.MATCHER);
        return Matchers.present(ColumnSortBot.MATCHER);
    }

    public void assertHeaderHide() {
        assertFalse(Matchers.present(mColumnBot.MATCHER));
        assertFalse(Matchers.present(ColumnSortBot.MATCHER));
    }

    public void assertHeaderShow() {
@@ -98,7 +98,7 @@ public class SortBot extends Bots.BaseBot {
        // or with espresso. It's sad that I'm leaving you
        // with this little gremlin, but we all have to
        // move on and get stuff done :)
        assertTrue(Matchers.present(mColumnBot.MATCHER));
        assertTrue(Matchers.present(ColumnSortBot.MATCHER));
    }

    private boolean sortByMenu(int id, @SortDirection int direction) {
@@ -131,9 +131,8 @@ public class SortBot extends Bots.BaseBot {
        private static final Matcher<View> MATCHER = withId(R.id.table_header);

        private boolean sortBy(String label, @SortDirection int direction) {
            final Matcher<View> cellMatcher = allOf(
                    withChild(withText(label)),
                    isDescendantOfA(MATCHER));
            final Matcher<View> cellMatcher =
                    allOf(withChild(withText(label)), isDescendantOfA(MATCHER));
            onView(cellMatcher).perform(click());

            final @SortDirection int viewDirection = getDirection(cellMatcher);
+30 −41
Original line number Diff line number Diff line
@@ -39,20 +39,16 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {
    private static final String MIME_3 = "image/jpeg"; // JPG image

    private static final String[] FILES = {FILE_1, FILE_3, FILE_2};
    private static final String[] FILES_IN_MODIFIED_DESC = reverse(FILES);
    private static final String[] MIMES = {MIME_1, MIME_3, MIME_2};
    private static final String[] DIRS = {DIR_1, DIR_2};

    private static final String[] DIRS_IN_MODIFIED_DESC = reverse(DIRS);
    private static final String[] DIRS_IN_NAME_ASC = {DIR_2, DIR_1};
    private static final String[] DIRS_IN_NAME_DESC = reverse(DIRS_IN_NAME_ASC);
    private static final String[] FILES_IN_NAME_ASC = {FILE_2, FILE_1, FILE_3};
    private static final String[] FILES_IN_NAME_DESC = reverse(FILES_IN_NAME_ASC);

    private static final String[] FILES_IN_SIZE_ASC = {FILE_2, FILE_1, FILE_3};
    private static final String[] FILES_IN_SIZE_DESC = reverse(FILES_IN_SIZE_ASC);

    private static final String[] DIRS_IN_MODIFIED_DESC = reverse(DIRS);
    private static final String[] FILES_IN_MODIFIED_DESC = reverse(FILES);

    private static final String[] FILES_IN_TYPE_ASC = {FILE_2, FILE_3, FILE_1};
    private static final String[] FILES_IN_TYPE_DESC = reverse(FILES_IN_TYPE_ASC);

@@ -60,6 +56,16 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {
        super(FilesActivity.class);
    }

    private static String[] reverse(String[] array) {
        String[] ret = new String[array.length];

        for (int i = 0; i < array.length; ++i) {
            ret[ret.length - i - 1] = array[i];
        }

        return ret;
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
@@ -71,8 +77,9 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {
    }

    /**
     * Initiate test files. It allows waiting between creations of files, so that we can assure
     * the modified date of each document is different.
     * Initiate test files. It allows waiting between creations of files, so that we can assure the
     * modified date of each document is different.
     *
     * @param sleep time to sleep in ms
     */
    private void initFiles(long sleep) throws Exception {
@@ -110,8 +117,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToListMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_ASC);
    }

@@ -120,8 +126,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToListMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_DESC);
    }

@@ -130,8 +135,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToListMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS, FILES);
    }

@@ -140,8 +144,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToListMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_MODIFIED_DESC, FILES_IN_MODIFIED_DESC);
    }

@@ -180,8 +183,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToGridMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_ASC);
    }

@@ -190,8 +192,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToGridMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_SIZE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_SIZE_DESC);
    }

@@ -200,8 +201,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToGridMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_ASCENDING);
        bots.directory.assertOrder(DIRS, FILES);
    }

@@ -210,8 +210,7 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {

        bots.main.switchToGridMode();

        bots.sort.sortBy(
                SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.sort.sortBy(SortModel.SORT_DIMENSION_ID_DATE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_MODIFIED_DESC, FILES_IN_MODIFIED_DESC);
    }

@@ -234,14 +233,4 @@ public class SortDocumentUiTest extends ActivityTest<FilesActivity> {
                SortModel.SORT_DIMENSION_ID_FILE_TYPE, SortDimension.SORT_DIRECTION_DESCENDING);
        bots.directory.assertOrder(DIRS_IN_NAME_ASC, FILES_IN_TYPE_DESC);
    }

    private static String[] reverse(String[] array) {
        String[] ret = new String[array.length];

        for (int i = 0; i < array.length; ++i) {
            ret[ret.length - i - 1] = array[i];
        }

        return ret;
    }
}