Search in sources :

Example 1 with SearchEntity

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<>());
        }
    }
}
Also used : ListEngineDisplayExt(im.actor.runtime.storage.ListEngineDisplayExt) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) SearchEntity(im.actor.core.entity.SearchEntity) ArrayList(java.util.ArrayList) SearchResult(im.actor.core.entity.SearchResult)

Example 2 with SearchEntity

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);
}
Also used : User(im.actor.core.entity.User) SearchEntity(im.actor.core.entity.SearchEntity) ArrayList(java.util.ArrayList)

Example 3 with SearchEntity

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();
    }
}
Also used : SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) SearchView(android.support.v7.widget.SearchView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) BaseFragment(im.actor.sdk.controllers.BaseFragment) Fragment(android.support.v4.app.Fragment) BindedDisplayList(im.actor.runtime.generic.mvvm.BindedDisplayList) HeaderViewRecyclerAdapter(im.actor.sdk.view.adapters.HeaderViewRecyclerAdapter) SearchEntity(im.actor.core.entity.SearchEntity) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) OnItemClickedListener(im.actor.sdk.view.adapters.OnItemClickedListener) FrameLayout(android.widget.FrameLayout) RecyclerView(android.support.v7.widget.RecyclerView)

Example 4 with SearchEntity

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;
        }
    });
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) GroupVM(im.actor.core.viewmodel.GroupVM) Peer(im.actor.core.entity.Peer) MenuItem(android.view.MenuItem) Avatar(im.actor.core.entity.Avatar) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) UserVM(im.actor.core.viewmodel.UserVM) SearchView(android.support.v7.widget.SearchView) SearchEntity(im.actor.core.entity.SearchEntity) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) ArrayList(java.util.ArrayList) BindedDisplayList(im.actor.runtime.generic.mvvm.BindedDisplayList) List(java.util.List) DisplayList(im.actor.runtime.generic.mvvm.DisplayList) CommandCallback(im.actor.core.viewmodel.CommandCallback)

Example 5 with SearchEntity

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);
}
Also used : SearchEntity(im.actor.core.entity.SearchEntity) Dialog(im.actor.core.entity.Dialog) ArrayList(java.util.ArrayList)

Aggregations

SearchEntity (im.actor.core.entity.SearchEntity)5 ArrayList (java.util.ArrayList)4 PeerSearchEntity (im.actor.core.entity.PeerSearchEntity)3 SearchView (android.support.v7.widget.SearchView)2 BindedDisplayList (im.actor.runtime.generic.mvvm.BindedDisplayList)2 Fragment (android.support.v4.app.Fragment)1 MenuItemCompat (android.support.v4.view.MenuItemCompat)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 Avatar (im.actor.core.entity.Avatar)1 Dialog (im.actor.core.entity.Dialog)1 Peer (im.actor.core.entity.Peer)1 SearchResult (im.actor.core.entity.SearchResult)1 User (im.actor.core.entity.User)1 CommandCallback (im.actor.core.viewmodel.CommandCallback)1 GroupVM (im.actor.core.viewmodel.GroupVM)1