Search in sources :

Example 11 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class MessageNotificationCreator method addEffects.

private void addEffects(NotificationCompat.Builder notificationBuilder, String text, MessageNotificationManager.Chat notifChat, Context context) {
    AccountJid account = notifChat.getAccountJid();
    UserJid user = notifChat.getUserJid();
    boolean isMUC = notifChat.isGroupChat();
    AbstractChat chat = MessageManager.getInstance().getChat(account, user);
    if (chat != null && (chat.getFirstNotification() || !SettingsManager.eventsFirstOnly())) {
        Uri sound = getSound(notifChat, text, isMUC);
        boolean makeVibration = ChatManager.getInstance().isMakeVibro(account, user);
        boolean led = isMUC ? SettingsManager.eventsLightningForMuc() : SettingsManager.eventsLightning();
        com.xabber.android.data.notification.NotificationManager.getInstance().setNotificationDefaults(notificationBuilder, led, sound, AudioManager.STREAM_NOTIFICATION);
        // vibration
        if (makeVibration)
            setVibration(notifChat, isMUC, context, notificationBuilder);
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Uri(android.net.Uri)

Example 12 with UserJid

use of com.xabber.android.data.entity.UserJid 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();
}
Also used : CommonState(com.xabber.android.data.account.CommonState) RosterContact(com.xabber.android.data.roster.RosterContact) CrowdfundingContact(com.xabber.android.data.roster.CrowdfundingContact) ChatWithButtonVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ChatWithButtonVO) ButtonVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ButtonVO) ArrayList(java.util.ArrayList) RoomChat(com.xabber.android.data.extension.muc.RoomChat) CategoryVO(com.xabber.android.presentation.ui.contactlist.viewobjects.CategoryVO) AccountJid(com.xabber.android.data.entity.AccountJid) ToolbarVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ToolbarVO) ChatContact(com.xabber.android.data.message.ChatContact) AbstractChat(com.xabber.android.data.message.AbstractChat) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) UserJid(com.xabber.android.data.entity.UserJid) GroupConfiguration(com.xabber.android.ui.adapter.contactlist.GroupConfiguration) TreeMap(java.util.TreeMap) AbstractContact(com.xabber.android.data.roster.AbstractContact) RoomContact(com.xabber.android.data.extension.muc.RoomContact) Collection(java.util.Collection) AccountConfiguration(com.xabber.android.ui.adapter.contactlist.AccountConfiguration) AccountWithButtonsVO(com.xabber.android.presentation.ui.contactlist.viewobjects.AccountWithButtonsVO) Map(java.util.Map) TreeMap(java.util.TreeMap) CrowdfundingMessage(com.xabber.android.data.database.realm.CrowdfundingMessage)

Example 13 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ContactListPresenter method onItemClick.

public void onItemClick(IFlexible item) {
    if (item instanceof ContactVO) {
        AccountJid accountJid = ((ContactVO) item).getAccountJid();
        UserJid userJid = ((ContactVO) item).getUserJid();
        if (view != null)
            view.onContactClick(RosterManager.getInstance().getAbstractContact(accountJid, userJid));
    } else if (item instanceof ButtonVO) {
        ButtonVO button = (ButtonVO) item;
        if (view != null)
            view.onButtonItemClick(button);
    } else if (item instanceof CrowdfundingChatVO) {
        if (view != null) {
            AccountJid accountJid = CrowdfundingChat.getDefaultAccount();
            UserJid userJid = CrowdfundingChat.getDefaultUser();
            if (accountJid != null && userJid != null)
                view.onContactClick(RosterManager.getInstance().getAbstractContact(accountJid, userJid));
        }
    }
}
Also used : ChatWithButtonVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ChatWithButtonVO) ButtonVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ButtonVO) AccountJid(com.xabber.android.data.entity.AccountJid) ExtContactVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ExtContactVO) ContactVO(com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO) UserJid(com.xabber.android.data.entity.UserJid) CrowdfundingChatVO(com.xabber.android.presentation.ui.contactlist.viewobjects.CrowdfundingChatVO)

Example 14 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ContactListPresenter method getSearchResults.

private ArrayList<AbstractContact> getSearchResults(Collection<RosterContact> rosterContacts, Comparator<AbstractContact> comparator, Map<AccountJid, Map<UserJid, AbstractChat>> abstractChats) {
    final ArrayList<AbstractContact> baseEntities = new ArrayList<>();
    // Build structure.
    for (RosterContact rosterContact : rosterContacts) {
        if (!rosterContact.isEnabled()) {
            continue;
        }
        final AccountJid account = rosterContact.getAccount();
        final Map<UserJid, AbstractChat> users = abstractChats.get(account);
        if (users != null) {
            users.remove(rosterContact.getUser());
        }
        if (rosterContact.getName().toLowerCase(locale).contains(filterString)) {
            baseEntities.add(rosterContact);
        }
    }
    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 (abstractContact.getName().toLowerCase(locale).contains(filterString)) {
                baseEntities.add(abstractContact);
            }
        }
    }
    Collections.sort(baseEntities, comparator);
    return baseEntities;
}
Also used : RoomContact(com.xabber.android.data.extension.muc.RoomContact) RosterContact(com.xabber.android.data.roster.RosterContact) AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) AbstractContact(com.xabber.android.data.roster.AbstractContact) RoomChat(com.xabber.android.data.extension.muc.RoomChat) ChatContact(com.xabber.android.data.message.ChatContact)

Example 15 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class UploadService method onHandleIntent.

@Override
protected void onHandleIntent(@Nullable Intent intent) {
    if (intent == null)
        return;
    this.receiver = intent.getParcelableExtra(KEY_RECEIVER);
    AccountJid account = intent.getParcelableExtra(KEY_ACCOUNT_JID);
    UserJid user = intent.getParcelableExtra(KEY_USER_JID);
    List<String> filePaths = intent.getStringArrayListExtra(KEY_FILE_PATHS);
    List<Uri> fileUris = intent.getParcelableArrayListExtra(KEY_FILE_URIS);
    CharSequence uploadServerUrl = intent.getCharSequenceExtra(KEY_UPLOAD_SERVER_URL);
    String existMessageId = intent.getStringExtra(KEY_MESSAGE_ID);
    if (filePaths != null)
        startWork(account, user, filePaths, uploadServerUrl, existMessageId);
    else if (fileUris != null)
        startWorkWithUris(account, user, fileUris, uploadServerUrl);
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Uri(android.net.Uri)

Aggregations

UserJid (com.xabber.android.data.entity.UserJid)67 AccountJid (com.xabber.android.data.entity.AccountJid)43 AbstractChat (com.xabber.android.data.message.AbstractChat)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)9 Jid (org.jxmpp.jid.Jid)9 Presence (org.jivesoftware.smack.packet.Presence)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 AccountItem (com.xabber.android.data.account.AccountItem)7 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 Message (org.jivesoftware.smack.packet.Message)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 NetworkException (com.xabber.android.data.NetworkException)5 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)5 SmackException (org.jivesoftware.smack.SmackException)5 Uri (android.net.Uri)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 DomainBareJid (org.jxmpp.jid.DomainBareJid)4 TextView (android.widget.TextView)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)3