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

Commit 83a271b7 authored by Kelvin Kwan's avatar Kelvin Kwan Committed by Android (Google) Code Review
Browse files

Merge "Hide apps during search across profile" into rvc-dev

parents 0e3146f1 2d7e73fd
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ public abstract class BaseActivity

    protected SearchViewManager mSearchManager;
    protected AppsRowManager mAppsRowManager;
    protected UserIdManager mUserIdManager;
    protected State mState;

    @Injected
@@ -199,6 +200,9 @@ public abstract class BaseActivity
            @Override
            public void onSearchViewChanged(boolean opened) {
                mNavigator.update();
                // We also need to update AppsRowManager because we may want to show/hide the
                // appsRow in cross-profile search according to the searching conditions.
                mAppsRowManager.updateView(BaseActivity.this);
            }

            @Override
@@ -248,6 +252,7 @@ public abstract class BaseActivity
                        cmdInterceptor);

        ViewGroup chipGroup = findViewById(R.id.search_chip_group);
        mUserIdManager = DocumentsApplication.getUserIdManager(this);
        mSearchManager = new SearchViewManager(searchListener, queryInterceptor,
                chipGroup, icicle);
        // initialize the chip sets by accept mime types
+13 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.widget.TextView;
import com.android.documentsui.ActionHandler;
import com.android.documentsui.BaseActivity;
import com.android.documentsui.R;
import com.android.documentsui.UserIdManager;
import com.android.documentsui.base.State;
import com.android.documentsui.base.UserId;
import com.android.documentsui.dirlist.AppsRowItemData.AppData;
@@ -47,11 +48,14 @@ public class AppsRowManager {
    private final ActionHandler mActionHandler;
    private final List<AppsRowItemData> mDataList;
    private final boolean mMaybeShowBadge;
    private final UserIdManager mUserIdManager;

    public AppsRowManager(ActionHandler handler, boolean maybeShowBadge) {
    public AppsRowManager(ActionHandler handler, boolean maybeShowBadge,
            UserIdManager userIdManager) {
        mDataList = new ArrayList<>();
        mActionHandler = handler;
        mMaybeShowBadge = maybeShowBadge;
        mUserIdManager = userIdManager;
    }

    public List<AppsRowItemData> updateList(List<Item> itemList) {
@@ -80,17 +84,22 @@ public class AppsRowManager {
        return mDataList;
    }

    private boolean shouldShow(State state) {
    private boolean shouldShow(State state, boolean isTextSearching) {
        boolean isHiddenAction = state.action == State.ACTION_CREATE
                || state.action == State.ACTION_OPEN_TREE
                || state.action == State.ACTION_PICK_COPY_DESTINATION;
        return state.stack.isRecents() && !isHiddenAction && mDataList.size() > 0;
        boolean isTextSearchingAcrossProfile = mUserIdManager.getUserIds().size() > 1
                && state.supportsCrossProfile()
                && isTextSearching;

        return state.stack.isRecents() && !isHiddenAction && mDataList.size() > 0
                && !isTextSearchingAcrossProfile;
    }

    public void updateView(BaseActivity activity) {
        final View appsRowLayout = activity.findViewById(R.id.apps_row);

        if (!shouldShow(activity.getDisplayState())) {
        if (!shouldShow(activity.getDisplayState(), activity.isTextSearching())) {
            appsRowLayout.setVisibility(View.GONE);
            return;
        }
+2 −1
Original line number Diff line number Diff line
@@ -155,7 +155,8 @@ public class FilesActivity extends BaseActivity implements AbstractActionHandler
                mInjector.selectionMgr,
                mProfileTabsAddonsStub);

        mAppsRowManager = new AppsRowManager(mInjector.actions, mState.supportsCrossProfile());
        mAppsRowManager = new AppsRowManager(mInjector.actions, mState.supportsCrossProfile(),
                mUserIdManager);
        mInjector.appsRowManager = mAppsRowManager;

        mActivityInputHandler =
+3 −2
Original line number Diff line number Diff line
@@ -138,13 +138,14 @@ public class PickActivity extends BaseActivity implements ActionHandler.Addons {
                ProviderExecutor::forAuthority,
                mInjector,
                LastAccessedStorage.create(),
                DocumentsApplication.getUserIdManager(this));
                mUserIdManager);

        mInjector.searchManager = mSearchManager;

        Intent intent = getIntent();

        mAppsRowManager = new AppsRowManager(mInjector.actions, mState.supportsCrossProfile());
        mAppsRowManager = new AppsRowManager(mInjector.actions, mState.supportsCrossProfile(),
                mUserIdManager);
        mInjector.appsRowManager = mAppsRowManager;

        mSharedInputHandler =
+53 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.documentsui.dirlist;

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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -33,6 +35,7 @@ import androidx.test.InstrumentationRegistry;
import com.android.documentsui.ActionHandler;
import com.android.documentsui.BaseActivity;
import com.android.documentsui.R;
import com.android.documentsui.TestUserIdManager;
import com.android.documentsui.base.State;
import com.android.documentsui.base.UserId;
import com.android.documentsui.sidebar.AppItem;
@@ -42,6 +45,8 @@ import com.android.documentsui.testing.TestActionHandler;
import com.android.documentsui.testing.TestProvidersAccess;
import com.android.documentsui.testing.TestResolveInfo;

import com.google.common.collect.Lists;

import org.junit.Before;
import org.junit.Test;

@@ -55,6 +60,7 @@ public class AppsRowManagerTest {
    private ActionHandler mActionHandler;
    private boolean mMaybeShowBadge;
    private BaseActivity mActivity;
    private TestUserIdManager mTestUserIdManager;
    private State mState;

    private View mAppsRow;
@@ -63,8 +69,9 @@ public class AppsRowManagerTest {
    @Before
    public void setUp() {
        mActionHandler = new TestActionHandler();
        mTestUserIdManager = new TestUserIdManager();

        mAppsRowManager = new AppsRowManager(mActionHandler, mMaybeShowBadge);
        mAppsRowManager = new AppsRowManager(mActionHandler, mMaybeShowBadge, mTestUserIdManager);

        Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
        LayoutInflater layoutInflater = LayoutInflater.from(context);
@@ -78,6 +85,9 @@ public class AppsRowManagerTest {
        when(mActivity.findViewById(R.id.apps_row)).thenReturn(mAppsRow);
        when(mActivity.findViewById(R.id.apps_group)).thenReturn(mAppsGroup);
        when(mActivity.getSelectedUser()).thenReturn(TestProvidersAccess.USER_ID);

        mTestUserIdManager.userIds =
                Lists.newArrayList(UserId.DEFAULT_USER, TestProvidersAccess.OtherUser.USER_ID);
    }

    @Test
@@ -219,6 +229,48 @@ public class AppsRowManagerTest {
        assertEquals(View.GONE, mAppsRow.getVisibility());
    }

    @Test
    public void testUpdateView_crossProfileSearch_hideRow() {
        mState.action = State.ACTION_GET_CONTENT;
        when(mActivity.isTextSearching()).thenReturn(true);

        mState.stack.changeRoot(TestProvidersAccess.RECENTS);
        final List<Item> rootList = new ArrayList<>();
        rootList.add(new RootItem(TestProvidersAccess.INSPECTOR, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.AUDIO, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.HAMMY, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.IMAGE, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.OtherUser.DOWNLOADS, mActionHandler,
                mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.OtherUser.PICKLES, mActionHandler,
                mMaybeShowBadge));
        mAppsRowManager.updateList(rootList);
        mAppsRowManager.updateView(mActivity);

        assertThat(mAppsRow.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void testUpdateView_notCrossProfileSearch_showRow() {
        mState.action = State.ACTION_GET_CONTENT;
        when(mActivity.isTextSearching()).thenReturn(false);

        mState.stack.changeRoot(TestProvidersAccess.RECENTS);
        final List<Item> rootList = new ArrayList<>();
        rootList.add(new RootItem(TestProvidersAccess.INSPECTOR, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.AUDIO, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.HAMMY, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.IMAGE, mActionHandler, mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.OtherUser.DOWNLOADS, mActionHandler,
                mMaybeShowBadge));
        rootList.add(new RootItem(TestProvidersAccess.OtherUser.PICKLES, mActionHandler,
                mMaybeShowBadge));
        mAppsRowManager.updateList(rootList);
        mAppsRowManager.updateView(mActivity);

        assertThat(mAppsRow.getVisibility()).isEqualTo(View.VISIBLE);
    }

    @Test
    public void testUpdateView_noItemsOnSelectedUser_hideRow() {
        mState.action = State.ACTION_GET_CONTENT;