use of im.actor.core.entity.PeerSearchEntity in project actor-platform by actorapp.
the class GlobalSearchSource method loadGlobalResults.
private void loadGlobalResults(String query, ArrayList<SearchResult> localResults, Consumer<List<SearchResult>> callback) {
context().getSearchModule().findPeers(query).then(r -> {
ArrayList<SearchResult> results = new ArrayList<>();
outer: for (PeerSearchEntity peerSearch : r) {
for (SearchResult l : localResults) {
if (peerSearch.getPeer().equals(l.getPeer())) {
continue outer;
}
}
if (peerSearch.getPeer().getPeerType() == PeerType.GROUP) {
Group group = context().getGroupsModule().getGroups().getValue(peerSearch.getPeer().getPeerId());
results.add(new SearchResult(peerSearch.getPeer(), group.getAvatar(), group.getTitle(), peerSearch.getOptMatchString()));
} else if (peerSearch.getPeer().getPeerType() == PeerType.PRIVATE) {
UserVM user = context().getUsersModule().getUsers().get(peerSearch.getPeer().getPeerId());
results.add(new SearchResult(peerSearch.getPeer(), user.getAvatar().get(), user.getName().get(), peerSearch.getOptMatchString()));
}
}
if (results.size() > 0) {
ArrayList<SearchResult> combined = new ArrayList<>();
combined.addAll(localResults);
combined.addAll(results);
callback.apply(combined);
}
});
}
use of im.actor.core.entity.PeerSearchEntity in project actor-platform by actorapp.
the class GlobalSearchBaseFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_global_search, menu);
searchMenu = menu.findItem(R.id.search);
if (messenger().getAppState().getIsAppEmpty().get()) {
searchMenu.setVisible(false);
} else {
searchMenu.setVisible(true);
}
searchView = (SearchView) searchMenu.getActionView();
searchView.setIconifiedByDefault(true);
MenuItemCompat.setOnActionExpandListener(searchMenu, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
showSearch();
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
hideSearch();
return true;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
searchQuery = s.trim();
if (isSearchVisible) {
if (s.trim().length() > 0) {
String activeSearchQuery = searchQuery;
searchDisplay.initSearch(s.trim().toLowerCase(), false);
scrolledToEnd = false;
searchAdapter.setQuery(s.trim().toLowerCase());
globalSearchResults.clear();
messenger().findPeers(s).start(new CommandCallback<List<PeerSearchEntity>>() {
@Override
public void onResult(List<PeerSearchEntity> res) {
if (searchQuery.equals(activeSearchQuery)) {
int order = 0;
outer: for (PeerSearchEntity pse : res) {
for (int i = 0; i < searchDisplay.getSize(); i++) {
if (searchDisplay.getItem(i).getPeer().equals(pse.getPeer())) {
continue outer;
}
}
Avatar avatar;
Peer peer = pse.getPeer();
String name;
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM userVM = users().get(peer.getPeerId());
name = userVM.getName().get();
avatar = userVM.getAvatar().get();
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupVM groupVM = groups().get(peer.getPeerId());
name = groupVM.getName().get();
avatar = groupVM.getAvatar().get();
} else {
continue;
}
String optMatchString = pse.getOptMatchString();
globalSearchResults.add(new SearchEntity(pse.getPeer(), order++, avatar, optMatchString == null ? name : optMatchString));
}
if (globalSearchResults.size() > 0) {
globalSearchResults.add(new SearchEntityHeader(order++));
}
checkGlobalSearch();
onSearchChanged();
}
}
@Override
public void onError(Exception e) {
}
});
} else {
searchDisplay.initEmpty();
}
}
return false;
}
});
}
Aggregations