Commit 774b016f authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

Save password search query in activity state

When under memory pressure, the activity is destroyed and the search
result lost.
By explicitly saving the query in the instance state bundle, the search
results can be recovered even though the activity is recreated.

Bug: 807306
Change-Id: Ice12994cdeefc7ee293114207b5faa93cebda5a5
Reviewed-on: https://chromium-review.googlesource.com/893187Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Friedrich Horschig <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532998}
parent 85a6ad31
...@@ -70,6 +70,9 @@ public class SavePasswordsPreferences ...@@ -70,6 +70,9 @@ public class SavePasswordsPreferences
// Used to pass the password id into a new activity. // Used to pass the password id into a new activity.
public static final String PASSWORD_LIST_ID = "id"; public static final String PASSWORD_LIST_ID = "id";
// The key for saving |mSearchQuery| to instance bundle.
private static final String SAVED_STATE_SEARCH_QUERY = "saved-state-search-query";
// The key for saving |mExportRequested| to instance bundle. // The key for saving |mExportRequested| to instance bundle.
private static final String SAVED_STATE_EXPORT_REQUESTED = "saved-state-export-requested"; private static final String SAVED_STATE_EXPORT_REQUESTED = "saved-state-export-requested";
...@@ -145,6 +148,9 @@ public class SavePasswordsPreferences ...@@ -145,6 +148,9 @@ public class SavePasswordsPreferences
mExportFileUri = Uri.parse(uriString); mExportFileUri = Uri.parse(uriString);
} }
} }
if (savedInstanceState.containsKey(SAVED_STATE_SEARCH_QUERY)) {
mSearchQuery = savedInstanceState.getString(SAVED_STATE_SEARCH_QUERY);
}
} }
@Override @Override
...@@ -170,6 +176,10 @@ public class SavePasswordsPreferences ...@@ -170,6 +176,10 @@ public class SavePasswordsPreferences
SearchView searchView = (SearchView) searchItem.getActionView(); SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); searchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
searchItem.setIcon(convertToPlainWhite(searchItem.getIcon())); searchItem.setIcon(convertToPlainWhite(searchItem.getIcon()));
if (mSearchQuery != null) { // If a query was recovered, restore the search view.
searchItem.expandActionView();
searchView.setQuery(mSearchQuery, false);
}
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override @Override
public boolean onMenuItemActionExpand(MenuItem menuItem) { public boolean onMenuItemActionExpand(MenuItem menuItem) {
...@@ -568,6 +578,9 @@ public class SavePasswordsPreferences ...@@ -568,6 +578,9 @@ public class SavePasswordsPreferences
if (mExportFileUri != null) { if (mExportFileUri != null) {
outState.putString(SAVED_STATE_EXPORT_FILE_URI, mExportFileUri.toString()); outState.putString(SAVED_STATE_EXPORT_FILE_URI, mExportFileUri.toString());
} }
if (mSearchQuery != null) {
outState.putString(SAVED_STATE_SEARCH_QUERY, mSearchQuery);
}
} }
@Override @Override
......
...@@ -1006,5 +1006,10 @@ public class SavePasswordsPreferencesTest { ...@@ -1006,5 +1006,10 @@ public class SavePasswordsPreferencesTest {
Espresso.onView(withText(ZEUS_ON_EARTH.getUserName())).check(matches(isDisplayed())); Espresso.onView(withText(ZEUS_ON_EARTH.getUserName())).check(matches(isDisplayed()));
Espresso.onView(withText(PHOBOS_AT_OLYMP.getUserName())).check(doesNotExist()); Espresso.onView(withText(PHOBOS_AT_OLYMP.getUserName())).check(doesNotExist());
Espresso.onView(withText(HADES_AT_UNDERWORLD.getUrl())).check(doesNotExist()); Espresso.onView(withText(HADES_AT_UNDERWORLD.getUrl())).check(doesNotExist());
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// The search bar should still be open and still display the search query.
Espresso.onView(withId(R.id.search_src_text)).check(matches(isDisplayed()));
Espresso.onView(withId(R.id.search_src_text)).check(matches(withText("Zeu")));
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment