use of im.actor.core.entity.SearchEntity in project actor-platform by actorapp.
the class GlobalSearchSource method loadResults.
@Override
public void loadResults(String query, Consumer<List<SearchResult>> callback) {
ListEngine<SearchEntity> searchList = context().getSearchModule().getSearchList();
if (searchList instanceof ListEngineDisplayExt) {
((ListEngineDisplayExt<SearchEntity>) searchList).loadBackward(query, 20, (items, topSortKey, bottomSortKey) -> {
ArrayList<SearchResult> localResults = new ArrayList<>();
for (SearchEntity e : items) {
localResults.add(new SearchResult(e.getPeer(), e.getAvatar(), e.getTitle(), null));
}
callback.apply(new ArrayList<>(localResults));
if (query.length() > 3) {
loadGlobalResults(query, localResults, callback);
}
});
} else {
if (query.length() > 3) {
loadGlobalResults(query, new ArrayList<>(), callback);
} else {
callback.apply(new ArrayList<>());
}
}
}
use of im.actor.core.entity.SearchEntity in project actor-platform by actorapp.
the class SearchActor method onContactsUpdated.
private void onContactsUpdated(int[] contactsList) {
List<SearchEntity> updated = new ArrayList<>();
for (int i = 0; i < contactsList.length; i++) {
User user = users().getValue(contactsList[i]);
updated.add(new SearchEntity(Peer.user(user.getUid()), CONTACTS_PREFIX + i, user.getAvatar(), user.getName()));
}
listEngine.addOrUpdateItems(updated);
}
use of im.actor.core.entity.SearchEntity in project actor-platform by actorapp.
the class GlobalSearchBaseFragment method showSearch.
private void showSearch() {
if (isSearchVisible) {
return;
}
isSearchVisible = true;
searchDisplay = messenger().buildSearchDisplayList();
searchDisplay.setBindHook(new BindedDisplayList.BindHook<SearchEntity>() {
@Override
public void onScrolledToEnd() {
scrolledToEnd = true;
checkGlobalSearch();
}
@Override
public void onItemTouched(SearchEntity item) {
}
});
searchAdapter = new SearchAdapter(getActivity(), searchDisplay, new OnItemClickedListener<SearchEntity>() {
@Override
public void onClicked(SearchEntity item) {
onPeerPicked(item.getPeer());
searchMenu.collapseActionView();
}
@Override
public boolean onLongClicked(SearchEntity item) {
return false;
}
});
HeaderViewRecyclerAdapter recyclerAdapter = new HeaderViewRecyclerAdapter(searchAdapter);
View header = new View(getActivity());
header.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(0)));
header.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
recyclerAdapter.addHeaderView(header);
searchList.setAdapter(recyclerAdapter);
RecyclerView.ItemAnimator animator = searchList.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
searchDisplay.addListener(searchListener);
showView(searchHintView, false);
goneView(searchEmptyView, false);
showView(searchContainer, false);
Fragment parent = getParentFragment();
if (parent != null && parent instanceof GlobalSearchStateDelegate) {
((GlobalSearchStateDelegate) parent).onGlobalSearchStarted();
}
}
use of im.actor.core.entity.SearchEntity 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;
}
});
}
use of im.actor.core.entity.SearchEntity in project actor-platform by actorapp.
the class SearchActor method onDialogsUpdated.
private void onDialogsUpdated(List<Dialog> dialogs) {
List<SearchEntity> updated = new ArrayList<>();
for (Dialog d : dialogs) {
updated.add(new SearchEntity(d.getPeer(), d.getSortDate(), d.getDialogAvatar(), d.getDialogTitle()));
}
listEngine.addOrUpdateItems(updated);
}
Aggregations