Reset query string when search is collapsed

Closes #2041
This commit is contained in:
Lukas Barth 2014-10-26 23:24:55 +01:00 committed by Moxie Marlinspike
parent 6980a32628
commit 715b1ea10d

View File

@ -116,8 +116,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
if (this.masterSecret != null) { if (this.masterSecret != null) {
inflater.inflate(R.menu.conversation_list, menu); inflater.inflate(R.menu.conversation_list, menu);
MenuItem menuItem = menu.findItem(R.id.menu_search); MenuItem menuItem = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem); initializeSearch(menuItem);
initializeSearch(searchView);
} else { } else {
inflater.inflate(R.menu.conversation_list_empty, menu); inflater.inflate(R.menu.conversation_list_empty, menu);
} }
@ -126,23 +125,40 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
return true; return true;
} }
private void initializeSearch(SearchView searchView) { private void initializeSearch(MenuItem searchViewItem) {
SearchView searchView = (SearchView)MenuItemCompat.getActionView(searchViewItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
ConversationListFragment fragment = (ConversationListFragment)getSupportFragmentManager()
.findFragmentById(R.id.fragment_content);
if (fragment != null) { if (fragment != null) {
fragment.setQueryFilter(query); fragment.setQueryFilter(query);
return true; return true;
} }
return false; return false;
} }
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
return onQueryTextSubmit(newText); return onQueryTextSubmit(newText);
} }
}); });
MenuItemCompat.setOnActionExpandListener(searchViewItem, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
if (fragment != null) {
fragment.resetQueryFilter();
}
return true;
}
});
} }
@Override @Override