Fixed search interaction (2)

pull/207/head
M66B 3 years ago
parent 43dc9b9ff9
commit 434e755dce

@ -57,6 +57,7 @@ import java.util.Objects;
public class FragmentAnswers extends FragmentBase { public class FragmentAnswers extends FragmentBase {
private boolean cards; private boolean cards;
private View view;
private RecyclerView rvAnswer; private RecyclerView rvAnswer;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpReady; private Group grpReady;
@ -79,7 +80,7 @@ public class FragmentAnswers extends FragmentBase {
setSubtitle(R.string.menu_answers); setSubtitle(R.string.menu_answers);
setHasOptionsMenu(true); setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_answers, container, false); view = inflater.inflate(R.layout.fragment_answers, container, false);
// Get controls // Get controls
rvAnswer = view.findViewById(R.id.rvAnswer); rvAnswer = view.findViewById(R.id.rvAnswer);
@ -228,15 +229,34 @@ public class FragmentAnswers extends FragmentBase {
SearchView searchView = (SearchView) menuSearch.getActionView(); SearchView searchView = (SearchView) menuSearch.getActionView();
searchView.setQueryHint(getString(R.string.title_rules_search_hint)); searchView.setQueryHint(getString(R.string.title_rules_search_hint));
if (!TextUtils.isEmpty(searching)) { final String search = searching;
menuSearch.expandActionView(); view.post(new RunnableEx("answers:search") {
searchView.setQuery(searching, true); @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() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (getView() != null && menuSearch.isActionViewExpanded()) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
searching = newText; searching = newText;
adapter.search(newText); adapter.search(newText);
} }
@ -245,8 +265,10 @@ public class FragmentAnswers extends FragmentBase {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
searching = query; if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
adapter.search(query); searching = query;
adapter.search(query);
}
return true; return true;
} }
}); });

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

@ -604,17 +604,34 @@ public class FragmentFolders extends FragmentBase {
SearchView searchView = (SearchView) menuSearch.getActionView(); SearchView searchView = (SearchView) menuSearch.getActionView();
searchView.setQueryHint(getString(R.string.title_search)); searchView.setQueryHint(getString(R.string.title_search));
if (TextUtils.isEmpty(searching)) final String search = searching;
menuSearch.collapseActionView(); view.post(new RunnableEx("folders:search") {
else { @Override
menuSearch.expandActionView(); public void delegate() {
searchView.setQuery(searching, true); 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() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (getView() != null && menuSearch.isActionViewExpanded()) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
searching = newText; searching = newText;
adapter.search(newText); adapter.search(newText);
} }
@ -623,8 +640,10 @@ public class FragmentFolders extends FragmentBase {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
searching = query; if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
adapter.search(query); searching = query;
adapter.search(query);
}
return true; return true;
} }
}); });

@ -75,6 +75,7 @@ public class FragmentRules extends FragmentBase {
private boolean cards; private boolean cards;
private View view;
private RecyclerView rvRule; private RecyclerView rvRule;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpReady; private Group grpReady;
@ -109,7 +110,7 @@ public class FragmentRules extends FragmentBase {
setSubtitle(R.string.title_edit_rules); setSubtitle(R.string.title_edit_rules);
setHasOptionsMenu(true); setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_rules, container, false); view = inflater.inflate(R.layout.fragment_rules, container, false);
// Get controls // Get controls
rvRule = view.findViewById(R.id.rvRule); rvRule = view.findViewById(R.id.rvRule);
@ -223,15 +224,34 @@ public class FragmentRules extends FragmentBase {
SearchView searchView = (SearchView) menuSearch.getActionView(); SearchView searchView = (SearchView) menuSearch.getActionView();
searchView.setQueryHint(getString(R.string.title_rules_search_hint)); searchView.setQueryHint(getString(R.string.title_rules_search_hint));
if (!TextUtils.isEmpty(searching)) { final String search = searching;
menuSearch.expandActionView(); view.post(new RunnableEx("rules:search") {
searchView.setQuery(searching, true); @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() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (getView() != null && menuSearch.isActionViewExpanded()) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
searching = newText; searching = newText;
adapter.search(newText); adapter.search(newText);
} }
@ -240,8 +260,10 @@ public class FragmentRules extends FragmentBase {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
searching = query; if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
adapter.search(query); searching = query;
adapter.search(query);
}
return true; return true;
} }
}); });

Loading…
Cancel
Save