Fixed search interaction (2)

This commit is contained in:
M66B
2022-05-16 13:49:15 +02:00
parent 43dc9b9ff9
commit 434e755dce
4 changed files with 118 additions and 33 deletions

View File

@@ -77,6 +77,7 @@ import ezvcard.property.FormattedName;
import ezvcard.property.RawProperty;
public class FragmentContacts extends FragmentBase {
private View view;
private RecyclerView rvContacts;
private ContentLoadingProgressBar pbWait;
private Group grpReady;
@@ -116,7 +117,7 @@ public class FragmentContacts extends FragmentBase {
setSubtitle(junk ? R.string.title_blocked_senders : R.string.menu_contacts);
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_contacts, container, false);
view = inflater.inflate(R.layout.fragment_contacts, container, false);
// Get controls
rvContacts = view.findViewById(R.id.rvContacts);
@@ -206,15 +207,34 @@ public class FragmentContacts extends FragmentBase {
SearchView searchView = (SearchView) menuSearch.getActionView();
searchView.setQueryHint(getString(R.string.title_search));
if (!TextUtils.isEmpty(searching)) {
menuSearch.expandActionView();
searchView.setQuery(searching, true);
}
final String search = searching;
view.post(new RunnableEx("contacts:search") {
@Override
public void delegate() {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
if (TextUtils.isEmpty(search))
menuSearch.collapseActionView();
else {
menuSearch.expandActionView();
searchView.setQuery(search, true);
}
}
});
getViewLifecycleOwner().getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
menuSearch.collapseActionView();
getViewLifecycleOwner().getLifecycle().removeObserver(this);
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
if (getView() != null && menuSearch.isActionViewExpanded()) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
searching = newText;
adapter.search(newText);
}
@@ -223,8 +243,10 @@ public class FragmentContacts extends FragmentBase {
@Override
public boolean onQueryTextSubmit(String query) {
searching = query;
adapter.search(query);
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
searching = query;
adapter.search(query);
}
return true;
}
});