use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ContactListPresenter method buildStructure.
/**
* Do not call directly. Only from Structure Builder
*/
void buildStructure() {
// 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())) {
if (!blockedContacts.get(contact.getAccount()).contains(contact.getUser())) {
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);
// 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(context, this));
if (hasVisibleContacts) {
if (currentChatsState == ChatListState.recent) {
// add recent chats
int i = 0;
for (AbstractContact contact : chatsGroup.getAbstractContacts()) {
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) {
// boolean isFirst = items.isEmpty();
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, context.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
items.addAll(ChatVO.convert(chatsGroup.getAbstractContacts(), this, null));
}
} else {
// Search
final ArrayList<AbstractContact> baseEntities = getSearchResults(rosterContacts, comparator, abstractChats);
items.clear();
items.add(new CategoryVO(context.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(context.getString(R.string.placeholder_no_unread));
if (currentChatsState == ChatListState.archived)
view.showPlaceholder(context.getString(R.string.placeholder_no_archived));
} else
view.hidePlaceholder();
view.updateItems(items);
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ChatContactSettingsFragment method getValues.
@Override
protected Map<String, Object> getValues() {
Map<String, Object> map = new HashMap<>();
AccountJid account = mListener.getAccount();
UserJid user = mListener.getUser();
boolean isMUC = false;
if (MUCManager.getInstance().hasRoom(account, user.getJid().asEntityBareJidIfPossible())) {
isMUC = true;
}
// custom notification
AbstractChat chat = MessageManager.getInstance().getChat(account, user);
if (chat != null) {
putValue(map, R.string.chat_notification_settings_key, chat.notifyAboutMessage());
}
putValue(map, R.string.chat_save_history_key, ChatManager.getInstance().isSaveMessages(account, user));
putValue(map, R.string.chat_events_visible_chat_key, ChatManager.getInstance().isNotifyVisible(account, user));
putValue(map, R.string.chat_events_show_text_key, ChatManager.getInstance().getShowText(account, user).ordinal());
putValue(map, R.string.chat_events_vibro_key, ChatManager.getInstance().isMakeVibro(account, user));
putValue(map, R.string.chat_events_sound_key, ChatManager.getInstance().getSound(account, user, isMUC));
putValue(map, R.string.chat_events_suppress_100_key, ChatManager.getInstance().isSuppress100(account, user));
return map;
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ChatContactSettingsFragment method setValues.
@Override
protected boolean setValues(Map<String, Object> source, Map<String, Object> result) {
AccountJid account = mListener.getAccount();
UserJid user = mListener.getUser();
// custom notification
if (hasChanges(source, result, R.string.chat_notification_settings_key)) {
AbstractChat chat = MessageManager.getInstance().getChat(account, user);
if (chat != null) {
boolean newValue = getBoolean(result, R.string.chat_notification_settings_key);
if (chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.bydefault)) {
NotificationState.NotificationMode mode = newValue ? NotificationState.NotificationMode.enabled : NotificationState.NotificationMode.disabled;
chat.setNotificationState(new NotificationState(mode, 0), true);
} else {
boolean defValue;
if (MUCManager.getInstance().hasRoom(account, user.getJid().asEntityBareJidIfPossible()))
defValue = SettingsManager.eventsOnMuc();
else
defValue = SettingsManager.eventsOnChat();
if (!defValue && chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.disabled)) {
chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.enabled, 0), true);
} else if (defValue && chat.getNotificationState().getMode().equals(NotificationState.NotificationMode.enabled)) {
chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.disabled, 0), true);
} else
chat.setNotificationState(new NotificationState(NotificationState.NotificationMode.bydefault, 0), true);
}
}
}
if (hasChanges(source, result, R.string.chat_save_history_key))
ChatManager.getInstance().setSaveMessages(account, user, getBoolean(result, R.string.chat_save_history_key));
if (hasChanges(source, result, R.string.chat_events_visible_chat_key))
ChatManager.getInstance().setNotifyVisible(account, user, getBoolean(result, R.string.chat_events_visible_chat_key));
if (hasChanges(source, result, R.string.chat_events_show_text_key)) {
ChatManager.getInstance().setShowText(account, user, ShowMessageTextInNotification.fromInteger(getInt(result, R.string.chat_events_show_text_key)));
}
if (hasChanges(source, result, R.string.chat_events_vibro_key))
ChatManager.getInstance().setMakeVibro(account, user, getBoolean(result, R.string.chat_events_vibro_key));
if (hasChanges(source, result, R.string.chat_events_sound_key))
ChatManager.getInstance().setSound(account, user, getUri(result, R.string.chat_events_sound_key));
if (hasChanges(source, result, R.string.chat_events_suppress_100_key))
ChatManager.getInstance().setSuppress100(account, user, getBoolean(result, R.string.chat_events_suppress_100_key));
return true;
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class ChatMessageAdapter method setUpAvatar.
private void setUpAvatar(MessageItem messageItem, IncomingMessage message) {
if (SettingsManager.chatsShowAvatars()) {
final AccountJid account = messageItem.getAccount();
final UserJid user = messageItem.getUser();
final Resourcepart resource = messageItem.getResource();
message.avatar.setVisibility(View.VISIBLE);
message.avatarBackground.setVisibility(View.VISIBLE);
if ((isMUC && MUCManager.getInstance().getNickname(account, user.getJid().asEntityBareJidIfPossible()).equals(resource))) {
message.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
} else {
if (isMUC) {
if (resource.equals(Resourcepart.EMPTY)) {
message.avatar.setImageDrawable(AvatarManager.getInstance().getRoomAvatar(user));
} else {
try {
message.avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatar(UserJid.from(JidCreate.domainFullFrom(user.getJid().asDomainBareJid(), resource))));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
} else {
message.avatar.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user));
}
}
} else {
message.avatar.setVisibility(View.GONE);
message.avatarBackground.setVisibility(View.GONE);
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class HttpFileUploadManager method retrySendFileMessage.
public void retrySendFileMessage(final MessageItem messageItem, Context context) {
List<String> notUploadedFilesPaths = new ArrayList<>();
for (Attachment attachment : messageItem.getAttachments()) {
if (attachment.getFileUrl() == null || attachment.getFileUrl().isEmpty())
notUploadedFilesPaths.add(attachment.getFilePath());
}
// if all attachments have url that they was uploaded. just resend existing message
if (notUploadedFilesPaths.size() == 0) {
final AccountJid accountJid = messageItem.getAccount();
final UserJid userJid = messageItem.getUser();
final String messageId = messageItem.getUniqueId();
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
MessageManager.getInstance().removeErrorAndResendMessage(accountJid, userJid, messageId);
}
});
} else
// else, upload files that haven't urls. Then write they in existing message and send
uploadFile(messageItem.getAccount(), messageItem.getUser(), notUploadedFilesPaths, null, messageItem.getUniqueId(), context);
}
Aggregations