Search in sources :

Example 1 with AddressBookContactViewHolder

use of com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookContactViewHolder in project wire-android by wireapp.

the class SearchResultAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, @ItemType int viewType) {
    View view;
    switch(viewType) {
        case ITEM_TYPE_TOP_USER:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.startui_top_users, parent, false);
            TopUserAdapter topUserAdapter = new TopUserAdapter(new TopUserAdapter.Callback() {

                @Override
                public Set<User> getSelectedUsers() {
                    return callback.getSelectedUsers();
                }
            });
            return new TopUsersViewHolder(view, topUserAdapter, parent.getContext());
        case ITEM_TYPE_OTHER_USER:
        case ITEM_TYPE_CONNECTED_USER:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.startui_user, parent, false);
            return new UserViewHolder(view, darkTheme, true);
        case ITEM_TYPE_CONVERSATION:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.startui_conversation, parent, false);
            return new ConversationViewHolder(view);
        case ITEM_TYPE_SECTION_HEADER:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.startui_section_header, parent, false);
            return new SectionHeaderViewHolder(view);
        case ITEM_TYPE_INITIAL:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.startui_section_header, parent, false);
            return new AddressBookSectionHeaderViewHolder(view, darkTheme);
        case ITEM_TYPE_CONTACT:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.contactlist_user, parent, false);
            return new AddressBookContactViewHolder(view, darkTheme);
        case ITEM_TYPE_EXPAND_BUTTON:
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.startui_section_expander, parent, false);
            return new SectionExpanderViewHolder(view);
    }
    return null;
}
Also used : Set(java.util.Set) ConversationViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.ConversationViewHolder) AddressBookSectionHeaderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookSectionHeaderViewHolder) TopUsersViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.TopUsersViewHolder) SectionHeaderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.SectionHeaderViewHolder) AddressBookSectionHeaderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookSectionHeaderViewHolder) View(android.view.View) ContactRowView(com.waz.zclient.pages.main.pickuser.views.ContactRowView) RecyclerView(android.support.v7.widget.RecyclerView) SectionExpanderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.SectionExpanderViewHolder) UserViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.UserViewHolder) AddressBookContactViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookContactViewHolder)

Example 2 with AddressBookContactViewHolder

use of com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookContactViewHolder in project wire-android by wireapp.

the class SearchResultAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    @ItemType int itemType = getItemViewType(position);
    switch(itemType) {
        case ITEM_TYPE_TOP_USER:
            ((TopUsersViewHolder) holder).bind(topUsers);
            ((TopUsersViewHolder) holder).bindOnItemTouchListener(topUsersOnItemTouchListener);
            break;
        case ITEM_TYPE_CONVERSATION:
            IConversation conversation = conversations[getConversationInternalPosition(position) - ROW_COUNT_SECTION_HEADER];
            ((ConversationViewHolder) holder).bind(conversation);
            break;
        case ITEM_TYPE_OTHER_USER:
            User otherUser = otherUsers[getOtherUserInternalPosition(position) - ROW_COUNT_SECTION_HEADER];
            boolean otherIsSelected = callback.getSelectedUsers().contains(otherUser);
            ((UserViewHolder) holder).bind(otherUser, otherIsSelected);
            break;
        case ITEM_TYPE_CONNECTED_USER:
            int index = mergedContacts.get(position - ROW_COUNT_SECTION_HEADER).index;
            User connectedUser = connectedUsers[index];
            boolean contactIsSelected = callback.getSelectedUsers().contains(connectedUser);
            ((UserViewHolder) holder).bind(connectedUser, contactIsSelected);
            break;
        case ITEM_TYPE_SECTION_HEADER:
            int type = getSectionItemType(position);
            ((SectionHeaderViewHolder) holder).bind(type);
            break;
        case ITEM_TYPE_INITIAL:
            if (contacts == null || contacts.getInitials() == null || contacts.getInitials().isEmpty()) {
                break;
            }
            position = showSearch ? position - ROW_COUNT_SECTION_HEADER : position;
            String initial = getContactInitial(position);
            ((AddressBookSectionHeaderViewHolder) holder).bind(initial);
            break;
        case ITEM_TYPE_CONTACT:
            if (contacts == null || contacts.getInitials() == null || contacts.getInitials().isEmpty()) {
                break;
            }
            if (showSearch) {
                position = mergedContacts.get(position - ROW_COUNT_SECTION_HEADER).index;
                Contact contact = contacts.get(position);
                ((AddressBookContactViewHolder) holder).bind(contact, contactsCallback, accentColor);
            } else {
                int[] contactMapping = getContactMapping(position);
                String contactInitial = getContactInitial(position);
                int contactInternalPosition = contactMapping[2];
                Contact contact = contacts.getContactForInitial(contactInitial, contactInternalPosition);
                ((AddressBookContactViewHolder) holder).bind(contact, contactsCallback, accentColor);
            }
            break;
        case ITEM_TYPE_EXPAND_BUTTON:
            if (getSectionForPosition(position) == ITEM_TYPE_CONNECTED_USER) {
                ((SectionExpanderViewHolder) holder).bind(mergedContacts.size(), new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        setContactsCollapsed(false);
                    }
                });
            } else {
                ((SectionExpanderViewHolder) holder).bind(conversations.length, new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        setGroupsCollapsed(false);
                    }
                });
            }
            break;
    }
}
Also used : User(com.waz.api.User) ConversationViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.ConversationViewHolder) TopUsersViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.TopUsersViewHolder) IConversation(com.waz.api.IConversation) View(android.view.View) ContactRowView(com.waz.zclient.pages.main.pickuser.views.ContactRowView) RecyclerView(android.support.v7.widget.RecyclerView) UserViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.UserViewHolder) Contact(com.waz.api.Contact) AddressBookSectionHeaderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookSectionHeaderViewHolder) SectionHeaderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.SectionHeaderViewHolder) AddressBookSectionHeaderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookSectionHeaderViewHolder) SectionExpanderViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.SectionExpanderViewHolder) AddressBookContactViewHolder(com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookContactViewHolder)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ContactRowView (com.waz.zclient.pages.main.pickuser.views.ContactRowView)2 AddressBookContactViewHolder (com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookContactViewHolder)2 AddressBookSectionHeaderViewHolder (com.waz.zclient.pages.main.pickuser.views.viewholders.AddressBookSectionHeaderViewHolder)2 ConversationViewHolder (com.waz.zclient.pages.main.pickuser.views.viewholders.ConversationViewHolder)2 SectionExpanderViewHolder (com.waz.zclient.pages.main.pickuser.views.viewholders.SectionExpanderViewHolder)2 SectionHeaderViewHolder (com.waz.zclient.pages.main.pickuser.views.viewholders.SectionHeaderViewHolder)2 TopUsersViewHolder (com.waz.zclient.pages.main.pickuser.views.viewholders.TopUsersViewHolder)2 UserViewHolder (com.waz.zclient.pages.main.pickuser.views.viewholders.UserViewHolder)2 Contact (com.waz.api.Contact)1 IConversation (com.waz.api.IConversation)1 User (com.waz.api.User)1 Set (java.util.Set)1