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);
}
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;
}
Aggregations