Search in sources :

Example 1 with RosterManager

use of com.xabber.android.data.roster.RosterManager in project xabber-android by redsolution.

the class ContactListActivity method openChat.

/**
 * Open chat with specified contact.
 * <p/>
 * Show dialog to choose account if necessary.
 *
 * @param user
 * @param text can be <code>null</code>.
 */
private void openChat(UserJid user, String text) {
    UserJid bareAddress = user.getBareUserJid();
    ArrayList<BaseEntity> entities = new ArrayList<>();
    for (AbstractChat check : MessageManager.getInstance().getChats()) {
        if (check.isActive() && check.getUser().equals(bareAddress)) {
            entities.add(check);
        }
    }
    if (entities.size() == 1) {
        openChat(entities.get(0), text);
        return;
    }
    entities.clear();
    Collection<AccountJid> enabledAccounts = AccountManager.getInstance().getEnabledAccounts();
    RosterManager rosterManager = RosterManager.getInstance();
    for (AccountJid accountJid : enabledAccounts) {
        RosterContact rosterContact = rosterManager.getRosterContact(accountJid, user);
        if (rosterContact != null && rosterContact.isEnabled()) {
            entities.add(rosterContact);
        }
    }
    if (entities.size() == 1) {
        openChat(entities.get(0), text);
        return;
    }
    if (enabledAccounts.isEmpty()) {
        return;
    }
    if (enabledAccounts.size() == 1) {
        openChat(rosterManager.getBestContact(enabledAccounts.iterator().next(), bareAddress), text);
        return;
    }
    AccountChooseDialogFragment.newInstance(bareAddress, text).show(getFragmentManager(), "OPEN_WITH_ACCOUNT");
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) BaseEntity(com.xabber.android.data.entity.BaseEntity) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) RosterManager(com.xabber.android.data.roster.RosterManager)

Aggregations

AccountJid (com.xabber.android.data.entity.AccountJid)1 BaseEntity (com.xabber.android.data.entity.BaseEntity)1 UserJid (com.xabber.android.data.entity.UserJid)1 AbstractChat (com.xabber.android.data.message.AbstractChat)1 RosterContact (com.xabber.android.data.roster.RosterContact)1 RosterManager (com.xabber.android.data.roster.RosterManager)1 ArrayList (java.util.ArrayList)1