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

Commit 270fd6c8 authored by Fan Zhang's avatar Fan Zhang
Browse files

Misc bug fixes around search bar in app list UI.

- Turn off DEBUG log flag, it's spammy and is a potential PII risk.
- Save search bar expand state so it stays open during screen rotation.
- Introduce a intent extra so callers can deep link into this UI with
  search bar pre-expanded.

Fixes: 130422388
Test: robotest
Change-Id: Ib81080733707306de516c49340571c543e70874e
parent 76ffb2df
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class ManageApplications extends InstrumentedFragment
        implements View.OnClickListener, OnItemSelectedListener, SearchView.OnQueryTextListener {

    static final String TAG = "ManageApplications";
    static final boolean DEBUG = true;
    static final boolean DEBUG = false;

    // Intent extras.
    public static final String EXTRA_CLASSNAME = "classname";
@@ -151,6 +151,7 @@ public class ManageApplications extends InstrumentedFragment
    private static final String EXTRA_HAS_ENTRIES = "hasEntries";
    private static final String EXTRA_HAS_BRIDGE = "hasBridge";
    private static final String EXTRA_FILTER_TYPE = "filterType";
    private static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";

    // attributes used as keys when passing values to AppInfoDashboardFragment activity
    public static final String APP_CHG = "chg";
@@ -220,6 +221,9 @@ public class ManageApplications extends InstrumentedFragment
    FilterSpinnerAdapter mFilterAdapter;
    @VisibleForTesting
    RecyclerView mRecyclerView;
    // Whether or not search view is expanded.
    @VisibleForTesting
    boolean mExpandSearch;

    private View mRootView;
    private Spinner mFilterSpinner;
@@ -307,12 +311,14 @@ public class ManageApplications extends InstrumentedFragment
        mFilter = appFilterRegistry.get(appFilterRegistry.getDefaultFilterType(mListType));
        mIsWorkOnly = args != null ? args.getBoolean(EXTRA_WORK_ONLY) : false;
        mWorkUserId = args != null ? args.getInt(EXTRA_WORK_ID) : NO_USER_SPECIFIED;
        mExpandSearch = activity.getIntent().getBooleanExtra(EXTRA_EXPAND_SEARCH_VIEW, false);

        if (savedInstanceState != null) {
            mSortOrder = savedInstanceState.getInt(EXTRA_SORT_ORDER, mSortOrder);
            mShowSystem = savedInstanceState.getBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
            mFilterType =
                    savedInstanceState.getInt(EXTRA_FILTER_TYPE, AppFilterRegistry.FILTER_APPS_ALL);
            mExpandSearch = savedInstanceState.getBoolean(EXTRA_EXPAND_SEARCH_VIEW);
        }

        mInvalidSizeStr = activity.getText(R.string.invalid_size_value);
@@ -501,6 +507,7 @@ public class ManageApplications extends InstrumentedFragment
        outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
        outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries);
        outState.putBoolean(EXTRA_HAS_BRIDGE, mApplications.mHasReceivedBridgeCallback);
        outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified());
        outState.putInt(EXTRA_FILTER_TYPE, mFilter.getFilterType());
        if (mApplications != null) {
            mApplications.onSaveInstanceState(outState);
@@ -607,6 +614,9 @@ public class ManageApplications extends InstrumentedFragment
            mSearchView = (SearchView) searchMenuItem.getActionView();
            mSearchView.setQueryHint(getText(R.string.search_settings));
            mSearchView.setOnQueryTextListener(this);
            if (mExpandSearch) {
                searchMenuItem.expandActionView();
            }
        }

        updateOptionsMenu();
+35 −20
Original line number Diff line number Diff line
@@ -19,17 +19,14 @@ package com.android.settings.applications.manageapplications;
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_DRAGGING;
import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;

import static com.android.settings.applications.manageapplications.AppFilterRegistry
        .FILTER_APPS_ALL;
import static com.android.settings.applications.manageapplications.ManageApplications
        .LIST_TYPE_MAIN;
import static com.android.settings.applications.manageapplications.ManageApplications
        .LIST_TYPE_NOTIFICATION;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_ALL;
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MAIN;
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_NOTIFICATION;

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

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
@@ -181,6 +178,24 @@ public class ManageApplicationsTest {
        verify(searchView).setOnQueryTextListener(mFragment);
    }

    @Test
    public void onCreateOptionsMenu_hasExpandSearchFlag_shouldExpandSearchView() {
        final SearchView searchView = mock(SearchView.class);
        final MenuItem searchMenu = mock(MenuItem.class);
        final MenuItem helpMenu = mock(MenuItem.class);
        when(searchMenu.getActionView()).thenReturn(searchView);
        when(mMenu.findItem(R.id.search_app_list_menu)).thenReturn(searchMenu);
        when(mMenu.add(anyInt() /* groupId */, anyInt() /* itemId */, anyInt() /* order */,
                anyInt() /* titleRes */)).thenReturn(helpMenu);
        doReturn("Test").when(mFragment).getText(anyInt() /* resId */);
        doNothing().when(mFragment).updateOptionsMenu();

        mFragment.mExpandSearch = true;
        mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class));

        verify(searchMenu).expandActionView();
    }

    @Test
    public void onQueryTextChange_shouldFilterSearchInApplicationsAdapter() {
        final ManageApplications.ApplicationsAdapter adapter =