Search in sources :

Example 1 with CrowdfundingChat

use of com.xabber.android.data.message.CrowdfundingChat in project xabber-android by redsolution.

the class RecentChatFragment method updateChats.

public void updateChats() {
    Collection<AbstractChat> chats = MessageManager.getInstance().getChats();
    List<AbstractChat> recentChats = new ArrayList<>();
    for (AbstractChat abstractChat : chats) {
        MessageItem lastMessage = abstractChat.getLastMessage();
        if (lastMessage != null) {
            AccountItem accountItem = AccountManager.getInstance().getAccount(abstractChat.getAccount());
            if (accountItem != null && accountItem.isEnabled()) {
                recentChats.add(abstractChat);
            }
        }
    }
    // crowdfunding chat
    int unreadCount = CrowdfundingManager.getInstance().getUnreadMessageCount();
    CrowdfundingMessage message = CrowdfundingManager.getInstance().getLastNotDelayedMessageFromRealm();
    if (message != null)
        recentChats.add(CrowdfundingChat.createCrowdfundingChat(unreadCount, message));
    Collections.sort(recentChats, ChatComparator.CHAT_COMPARATOR);
    final List<AbstractContact> newContacts = new ArrayList<>();
    for (AbstractChat chat : recentChats) {
        if (chat instanceof CrowdfundingChat)
            newContacts.add(new CrowdfundingContact((CrowdfundingChat) chat));
        else if (!chat.isArchived() || ((ChatActivity) getActivity()).isShowArchived())
            newContacts.add(RosterManager.getInstance().getBestContact(chat.getAccount(), chat.getUser()));
    }
    updateItems(newContacts);
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) CrowdfundingContact(com.xabber.android.data.roster.CrowdfundingContact) ChatActivity(com.xabber.android.ui.activity.ChatActivity) AccountItem(com.xabber.android.data.account.AccountItem) AbstractChat(com.xabber.android.data.message.AbstractChat) ArrayList(java.util.ArrayList) AbstractContact(com.xabber.android.data.roster.AbstractContact) CrowdfundingChat(com.xabber.android.data.message.CrowdfundingChat) CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Example 2 with CrowdfundingChat

use of com.xabber.android.data.message.CrowdfundingChat in project xabber-android by redsolution.

the class ContactListPresenter method getChatsGroup.

/**
 * @param chats which must be filtered
 * @param state for which you want to filter
 * @return GroupConfiguration that may contains recent, unread or archived chats.
 */
private GroupConfiguration getChatsGroup(Collection<AbstractChat> chats, ChatListState state) {
    GroupConfiguration chatsGroup = new GroupConfiguration(GroupManager.NO_ACCOUNT, GroupVO.RECENT_CHATS_TITLE, GroupManager.getInstance());
    List<AbstractChat> newChats = new ArrayList<>();
    for (AbstractChat abstractChat : chats) {
        MessageItem lastMessage = abstractChat.getLastMessage();
        if (lastMessage != null) {
            switch(state) {
                case unread:
                    if (!abstractChat.isArchived() && abstractChat.getUnreadMessageCount() > 0)
                        newChats.add(abstractChat);
                    break;
                case archived:
                    if (abstractChat.isArchived())
                        newChats.add(abstractChat);
                    break;
                default:
                    // recent
                    if (!abstractChat.isArchived())
                        newChats.add(abstractChat);
                    break;
            }
        }
    }
    // crowdfunding chat
    int unreadCount = CrowdfundingManager.getInstance().getUnreadMessageCount();
    CrowdfundingMessage message = CrowdfundingManager.getInstance().getLastNotDelayedMessageFromRealm();
    if (message != null) {
        switch(state) {
            case unread:
                if (unreadCount > 0)
                    newChats.add(CrowdfundingChat.createCrowdfundingChat(unreadCount, message));
                break;
            case archived:
                break;
            default:
                // recent
                newChats.add(CrowdfundingChat.createCrowdfundingChat(unreadCount, message));
                break;
        }
    }
    Collections.sort(newChats, ChatComparator.CHAT_COMPARATOR);
    chatsGroup.setNotEmpty();
    int itemsCount = 0;
    for (AbstractChat chat : newChats) {
        if (itemsCount < MAX_RECENT_ITEMS || state != ChatListState.recent) {
            if (chat instanceof CrowdfundingChat)
                chatsGroup.addAbstractContact(new CrowdfundingContact((CrowdfundingChat) chat));
            else
                chatsGroup.addAbstractContact(RosterManager.getInstance().getBestContact(chat.getAccount(), chat.getUser()));
            chatsGroup.increment(true);
            itemsCount++;
        } else
            break;
    }
    ShortcutBuilder.updateShortcuts(Application.getInstance(), new ArrayList<>(chatsGroup.getAbstractContacts()));
    return chatsGroup;
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) CrowdfundingContact(com.xabber.android.data.roster.CrowdfundingContact) AbstractChat(com.xabber.android.data.message.AbstractChat) ArrayList(java.util.ArrayList) GroupConfiguration(com.xabber.android.ui.adapter.contactlist.GroupConfiguration) CrowdfundingChat(com.xabber.android.data.message.CrowdfundingChat) CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Aggregations

MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 CrowdfundingMessage (com.xabber.android.data.database.realm.CrowdfundingMessage)2 AbstractChat (com.xabber.android.data.message.AbstractChat)2 CrowdfundingChat (com.xabber.android.data.message.CrowdfundingChat)2 CrowdfundingContact (com.xabber.android.data.roster.CrowdfundingContact)2 ArrayList (java.util.ArrayList)2 AccountItem (com.xabber.android.data.account.AccountItem)1 AbstractContact (com.xabber.android.data.roster.AbstractContact)1 ChatActivity (com.xabber.android.ui.activity.ChatActivity)1 GroupConfiguration (com.xabber.android.ui.adapter.contactlist.GroupConfiguration)1