Merge "Show previous query upon configuration change" into tm-dev am: 9a14f087cd
am: 9a55ef5d47
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18158875 Change-Id: I3de0f134ac8f074f2a7a831b2e31dd60b76871ff Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -173,6 +173,8 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
private static final String EXTRA_HAS_BRIDGE = "hasBridge";
|
private static final String EXTRA_HAS_BRIDGE = "hasBridge";
|
||||||
private static final String EXTRA_FILTER_TYPE = "filterType";
|
private static final String EXTRA_FILTER_TYPE = "filterType";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
static final String EXTRA_SEARCH_QUERY = "search_query";
|
||||||
|
@VisibleForTesting
|
||||||
static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
|
static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
|
||||||
|
|
||||||
// attributes used as keys when passing values to AppInfoDashboardFragment activity
|
// attributes used as keys when passing values to AppInfoDashboardFragment activity
|
||||||
@@ -253,6 +255,8 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
// Whether or not search view is expanded.
|
// Whether or not search view is expanded.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mExpandSearch;
|
boolean mExpandSearch;
|
||||||
|
@VisibleForTesting
|
||||||
|
CharSequence mPreQuery;
|
||||||
|
|
||||||
private View mRootView;
|
private View mRootView;
|
||||||
private Spinner mFilterSpinner;
|
private Spinner mFilterSpinner;
|
||||||
@@ -358,6 +362,7 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
mFilterType =
|
mFilterType =
|
||||||
savedInstanceState.getInt(EXTRA_FILTER_TYPE, AppFilterRegistry.FILTER_APPS_ALL);
|
savedInstanceState.getInt(EXTRA_FILTER_TYPE, AppFilterRegistry.FILTER_APPS_ALL);
|
||||||
mExpandSearch = savedInstanceState.getBoolean(EXTRA_EXPAND_SEARCH_VIEW);
|
mExpandSearch = savedInstanceState.getBoolean(EXTRA_EXPAND_SEARCH_VIEW);
|
||||||
|
mPreQuery = savedInstanceState.getCharSequence(EXTRA_SEARCH_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
mInvalidSizeStr = activity.getText(R.string.invalid_size_value);
|
mInvalidSizeStr = activity.getText(R.string.invalid_size_value);
|
||||||
@@ -544,6 +549,7 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
|
outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
|
||||||
if (mSearchView != null) {
|
if (mSearchView != null) {
|
||||||
outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified());
|
outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified());
|
||||||
|
outState.putCharSequence(EXTRA_SEARCH_QUERY, mSearchView.getQuery());
|
||||||
}
|
}
|
||||||
if (mApplications != null) {
|
if (mApplications != null) {
|
||||||
outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries);
|
outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries);
|
||||||
@@ -683,6 +689,9 @@ public class ManageApplications extends InstrumentedFragment
|
|||||||
if (mExpandSearch) {
|
if (mExpandSearch) {
|
||||||
searchMenuItem.expandActionView();
|
searchMenuItem.expandActionView();
|
||||||
}
|
}
|
||||||
|
if (!TextUtils.isEmpty(mPreQuery)) {
|
||||||
|
mSearchView.setQuery(mPreQuery, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOptionsMenu();
|
updateOptionsMenu();
|
||||||
|
@@ -188,6 +188,24 @@ public class ManageApplicationsTest {
|
|||||||
verify(searchMenu).expandActionView();
|
verify(searchMenu).expandActionView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCreateOptionsMenu_hasPreQuery_shouldSetQuery() {
|
||||||
|
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.mPreQuery = "test";
|
||||||
|
mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class));
|
||||||
|
|
||||||
|
verify(searchView).setQuery("test", true);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onQueryTextChange_shouldFilterSearchInApplicationsAdapter() {
|
public void onQueryTextChange_shouldFilterSearchInApplicationsAdapter() {
|
||||||
final ManageApplications.ApplicationsAdapter adapter =
|
final ManageApplications.ApplicationsAdapter adapter =
|
||||||
@@ -518,6 +536,38 @@ public class ManageApplicationsTest {
|
|||||||
assertThat(bundle.getBoolean(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse();
|
assertThat(bundle.getBoolean(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSaveInstanceState_noSearchView_shouldNotSaveQuery() {
|
||||||
|
final Bundle bundle = new Bundle();
|
||||||
|
ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
|
||||||
|
ReflectionHelpers.setField(mFragment, "mFilter", mock(AppFilterItem.class));
|
||||||
|
ReflectionHelpers.setField(mFragment, "mApplications",
|
||||||
|
mock(ManageApplications.ApplicationsAdapter.class));
|
||||||
|
|
||||||
|
mFragment.onSaveInstanceState(bundle);
|
||||||
|
|
||||||
|
assertThat(bundle.containsKey(ManageApplications.EXTRA_SEARCH_QUERY)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSaveInstanceState_searchViewSet_shouldSaveQuery() {
|
||||||
|
final SearchView searchView = mock(SearchView.class);
|
||||||
|
final Bundle bundle = new Bundle();
|
||||||
|
ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
|
||||||
|
ReflectionHelpers.setField(mFragment, "mFilter", mock(AppFilterItem.class));
|
||||||
|
ReflectionHelpers.setField(mFragment, "mApplications",
|
||||||
|
mock(ManageApplications.ApplicationsAdapter.class));
|
||||||
|
ReflectionHelpers.setField(mFragment, "mSearchView", searchView);
|
||||||
|
when(searchView.isIconified()).thenReturn(true);
|
||||||
|
when(searchView.getQuery()).thenReturn("test");
|
||||||
|
|
||||||
|
mFragment.onSaveInstanceState(bundle);
|
||||||
|
|
||||||
|
assertThat(bundle.containsKey(ManageApplications.EXTRA_SEARCH_QUERY)).isTrue();
|
||||||
|
assertThat(bundle.getCharSequence(ManageApplications.EXTRA_SEARCH_QUERY))
|
||||||
|
.isEqualTo("test");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createHeader_batteryListType_hasCorrectItems() {
|
public void createHeader_batteryListType_hasCorrectItems() {
|
||||||
ReflectionHelpers.setField(mFragment, "mListType", ManageApplications.LIST_TYPE_HIGH_POWER);
|
ReflectionHelpers.setField(mFragment, "mListType", ManageApplications.LIST_TYPE_HIGH_POWER);
|
||||||
|
Reference in New Issue
Block a user