use of com.xabber.android.data.roster.CrowdfundingContact in project xabber-android by redsolution.
the class RecentChatFragment method updateItems.
public void updateItems(List<AbstractContact> items) {
this.items.clear();
for (AbstractContact contact : items) {
if (contact instanceof CrowdfundingContact)
this.items.add(CrowdfundingChatVO.convert((CrowdfundingContact) contact));
else
this.items.add(ChatVO.convert(contact, this, this));
}
adapter.updateDataSet(this.items);
}
use of com.xabber.android.data.roster.CrowdfundingContact 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.roster.CrowdfundingContact in project xabber-android by redsolution.
the class ContactListPresenter method update.
@Override
public void update() {
// listener.hidePlaceholder();
List<IFlexible> items = new ArrayList<>();
final Collection<RosterContact> allRosterContacts = RosterManager.getInstance().getAllContacts();
Map<AccountJid, Collection<UserJid>> blockedContacts = new TreeMap<>();
for (AccountJid account : AccountManager.getInstance().getEnabledAccounts()) {
blockedContacts.put(account, BlockingManager.getInstance().getCachedBlockedContacts(account));
}
final Collection<RosterContact> rosterContacts = new ArrayList<>();
for (RosterContact contact : allRosterContacts) {
if (blockedContacts.containsKey(contact.getAccount())) {
Collection<UserJid> blockedUsers = blockedContacts.get(contact.getAccount());
if (blockedUsers != null) {
if (!blockedUsers.contains(contact.getUser()))
rosterContacts.add(contact);
} else
rosterContacts.add(contact);
} else
rosterContacts.add(contact);
}
final boolean showOffline = SettingsManager.contactsShowOffline();
final boolean showGroups = SettingsManager.contactsShowGroups();
final boolean showEmptyGroups = SettingsManager.contactsShowEmptyGroups();
final boolean showActiveChats = false;
final boolean stayActiveChats = true;
final boolean showAccounts = SettingsManager.contactsShowAccounts();
final Comparator<AbstractContact> comparator = SettingsManager.contactsOrder();
final CommonState commonState = AccountManager.getInstance().getCommonState();
final AccountJid selectedAccount = AccountManager.getInstance().getSelectedAccount();
/**
* Groups.
*/
final Map<String, GroupConfiguration> groups;
/**
* Contacts.
*/
final List<AbstractContact> contacts;
/**
* Chat list on top of contact list.
*/
final GroupConfiguration chatsGroup;
/**
* Whether there is at least one contact.
*/
boolean hasContacts = false;
/**
* Whether there is at least one visible contact.
*/
boolean hasVisibleContacts = false;
final Map<AccountJid, AccountConfiguration> accounts = new TreeMap<>();
for (AccountJid account : AccountManager.getInstance().getEnabledAccounts()) {
accounts.put(account, null);
}
/**
* List of rooms and active chats grouped by users inside accounts.
*/
final Map<AccountJid, Map<UserJid, AbstractChat>> abstractChats = new TreeMap<>();
for (AbstractChat abstractChat : MessageManager.getInstance().getChats()) {
if ((abstractChat instanceof RoomChat || abstractChat.isActive()) && accounts.containsKey(abstractChat.getAccount())) {
final AccountJid account = abstractChat.getAccount();
Map<UserJid, AbstractChat> users = abstractChats.get(account);
if (users == null) {
users = new TreeMap<>();
abstractChats.put(account, users);
}
users.put(abstractChat.getUser(), abstractChat);
}
}
if (filterString == null || filterString.isEmpty()) {
// Create arrays.
if (showAccounts) {
groups = null;
contacts = null;
for (Map.Entry<AccountJid, AccountConfiguration> entry : accounts.entrySet()) {
entry.setValue(new AccountConfiguration(entry.getKey(), GroupManager.IS_ACCOUNT, GroupManager.getInstance()));
}
} else {
if (showGroups) {
groups = new TreeMap<>();
contacts = null;
} else {
groups = null;
contacts = new ArrayList<>();
}
}
// chats on top
Collection<AbstractChat> chats = MessageManager.getInstance().getChatsOfEnabledAccount();
chatsGroup = getChatsGroup(chats, currentChatsState);
if (!chatsGroup.isEmpty())
hasVisibleContacts = true;
// Build structure.
for (RosterContact rosterContact : rosterContacts) {
if (!rosterContact.isEnabled()) {
continue;
}
hasContacts = true;
final boolean online = rosterContact.getStatusMode().isOnline();
final AccountJid account = rosterContact.getAccount();
final Map<UserJid, AbstractChat> users = abstractChats.get(account);
final AbstractChat abstractChat;
if (users == null) {
abstractChat = null;
} else {
abstractChat = users.remove(rosterContact.getUser());
}
if (selectedAccount != null && !selectedAccount.equals(account)) {
continue;
}
if (ContactListGroupUtils.addContact(rosterContact, online, accounts, groups, contacts, showAccounts, showGroups, showOffline)) {
hasVisibleContacts = true;
}
}
for (Map<UserJid, AbstractChat> users : abstractChats.values()) for (AbstractChat abstractChat : users.values()) {
final AbstractContact abstractContact;
if (abstractChat instanceof RoomChat) {
abstractContact = new RoomContact((RoomChat) abstractChat);
} else {
abstractContact = new ChatContact(abstractChat);
}
if (selectedAccount != null && !selectedAccount.equals(abstractChat.getAccount())) {
continue;
}
final String group;
final boolean online;
if (abstractChat instanceof RoomChat) {
group = GroupManager.IS_ROOM;
online = abstractContact.getStatusMode().isOnline();
} else if (MUCManager.getInstance().isMucPrivateChat(abstractChat.getAccount(), abstractChat.getUser())) {
group = GroupManager.IS_ROOM;
online = abstractContact.getStatusMode().isOnline();
} else {
group = GroupManager.NO_GROUP;
online = false;
}
hasVisibleContacts = true;
ContactListGroupUtils.addContact(abstractContact, group, online, accounts, groups, contacts, showAccounts, showGroups);
}
// BUILD STRUCTURE //
// Remove empty groups, sort and apply structure.
items.clear();
items.add(new ToolbarVO(Application.getInstance().getApplicationContext(), this, currentChatsState));
// set hasVisibleContacts as true if have crowdfunding message
CrowdfundingMessage message = CrowdfundingManager.getInstance().getLastNotDelayedMessageFromRealm();
if (message != null)
hasVisibleContacts = true;
if (hasVisibleContacts) {
if (currentChatsState == ChatListState.recent) {
// add recent chats
int i = 0;
for (AbstractContact contact : chatsGroup.getAbstractContacts()) {
if (contact instanceof CrowdfundingContact) {
items.add(CrowdfundingChatVO.convert((CrowdfundingContact) contact));
} else if (i == MAX_RECENT_ITEMS - 1) {
if (getAllChatsSize() > MAX_RECENT_ITEMS)
items.add(ChatWithButtonVO.convert(contact, this));
else
items.add(ChatVO.convert(contact, this, null));
} else
items.add(ChatVO.convert(contact, this, null));
i++;
}
if (showAccounts) {
for (AccountConfiguration rosterAccount : accounts.values()) {
if (rosterAccount.getTotal() != 0) {
if (showGroups) {
createContactListWithAccountsAndGroups(items, rosterAccount, showEmptyGroups, comparator);
} else {
createContactListWithAccounts(items, rosterAccount, comparator);
}
} else {
AccountWithButtonsVO account = AccountWithButtonsVO.convert(rosterAccount, this);
ButtonVO button = ButtonVO.convert(rosterAccount, Application.getInstance().getApplicationContext().getString(R.string.contact_add), ButtonVO.ACTION_ADD_CONTACT);
account.addSubItem(button);
items.add(account);
}
}
} else {
if (showGroups) {
createContactListWithGroups(items, showEmptyGroups, groups, comparator);
} else {
createContactList(items, contacts, comparator);
}
}
} else {
for (AbstractContact contact : chatsGroup.getAbstractContacts()) {
if (contact instanceof CrowdfundingContact)
items.add(CrowdfundingChatVO.convert((CrowdfundingContact) contact));
else
items.add(ChatVO.convert(contact, this, null));
}
}
}
} else {
// Search
final ArrayList<AbstractContact> baseEntities = getSearchResults(rosterContacts, comparator, abstractChats);
items.clear();
items.add(new CategoryVO(Application.getInstance().getApplicationContext().getString(R.string.category_title_contacts)));
items.addAll(SettingsManager.contactsShowMessages() ? ExtContactVO.convert(baseEntities, this) : ContactVO.convert(baseEntities, this));
hasVisibleContacts = baseEntities.size() > 0;
}
if (view != null)
view.onContactListChanged(commonState, hasContacts, hasVisibleContacts, filterString != null);
if (view != null) {
if (items.size() == 1 && (filterString == null || filterString.isEmpty())) {
if (currentChatsState == ChatListState.unread)
view.showPlaceholder(Application.getInstance().getApplicationContext().getString(R.string.placeholder_no_unread));
if (currentChatsState == ChatListState.archived)
view.showPlaceholder(Application.getInstance().getApplicationContext().getString(R.string.placeholder_no_archived));
} else
view.hidePlaceholder();
view.updateItems(items);
}
updateUnreadCount();
}
use of com.xabber.android.data.roster.CrowdfundingContact 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