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) {
inflater.inflate(R.menu.conversation_list, menu);
MenuItem menuItem = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
initializeSearch(searchView);
initializeSearch(menuItem);
} else {
inflater.inflate(R.menu.conversation_list_empty, menu);
}
@ -126,23 +125,40 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
return true;
}
private void initializeSearch(SearchView searchView) {
private void initializeSearch(MenuItem searchViewItem) {
SearchView searchView = (SearchView)MenuItemCompat.getActionView(searchViewItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
ConversationListFragment fragment = (ConversationListFragment)getSupportFragmentManager()
.findFragmentById(R.id.fragment_content);
if (fragment != null) {
fragment.setQueryFilter(query);
return true;
}
return false;
}
@Override
public boolean onQueryTextChange(String 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