private SearchView mSearchView;
private MenuItem mSearchMenuItem;
private boolean mSearchMenuItemExpanded = false;
- private boolean mIsShowingSearchResults = false;
private SearchResultsSummary mSearchResultsFragment;
private String mSearchQuery;
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
if (item.getItemId() == mSearchMenuItem.getItemId()) {
- if (mSearchResultsFragment == null) {
- switchToSearchResultsFragmentIfNeeded();
- }
+ switchToSearchResultsFragmentIfNeeded();
}
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
if (item.getItemId() == mSearchMenuItem.getItemId()) {
- if (mIsShowingSearchResults) {
+ if (mSearchMenuItemExpanded) {
revertToInitialFragment();
}
}
}
private void switchToSearchResultsFragmentIfNeeded() {
- if (!mIsShowingSearchResults) {
- Fragment current = getFragmentManager().findFragmentById(R.id.prefs);
- if (current != null && current instanceof SearchResultsSummary) {
- mSearchResultsFragment = (SearchResultsSummary) current;
- } else {
- String title = getString(R.string.search_results_title);
- mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
- SearchResultsSummary.class.getName(), null, false, true, title, true);
- }
- mIsShowingSearchResults = true;
+ if (mSearchResultsFragment != null) {
+ return;
}
+ Fragment current = getFragmentManager().findFragmentById(R.id.prefs);
+ if (current != null && current instanceof SearchResultsSummary) {
+ mSearchResultsFragment = (SearchResultsSummary) current;
+ } else {
+ String title = getString(R.string.search_results_title);
+ mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
+ SearchResultsSummary.class.getName(), null, false, true, title, true);
+ }
+ mSearchMenuItemExpanded = true;
}
public void needToRevertToInitialFragment() {
private void revertToInitialFragment() {
mNeedToRevertToInitialFragment = false;
- getFragmentManager().popBackStack(SettingsActivity.BACK_STACK_PREFS,
- FragmentManager.POP_BACK_STACK_INCLUSIVE);
mSearchResultsFragment = null;
- mIsShowingSearchResults = false;
+ mSearchMenuItemExpanded = false;
+ getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
+ FragmentManager.POP_BACK_STACK_INCLUSIVE);
mSearchMenuItem.collapseActionView();
}
}