Search in sources :

Example 6 with RosterContact

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

the class ContactList 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(String user, String text) {
    String bareAddress = Jid.getBareAddress(user);
    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();
    for (RosterContact check : RosterManager.getInstance().getContacts()) {
        if (check.isEnabled() && check.getUser().equals(bareAddress)) {
            entities.add(check);
        }
    }
    if (entities.size() == 1) {
        openChat(entities.get(0), text);
        return;
    }
    Collection<String> accounts = AccountManager.getInstance().getAccounts();
    if (accounts.isEmpty()) {
        return;
    }
    if (accounts.size() == 1) {
        openChat(new BaseEntity(accounts.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) ArrayList(java.util.ArrayList) BaseEntity(com.xabber.android.data.entity.BaseEntity)

Example 7 with RosterContact

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

the class VCardManager method onVCardReceived.

private void onVCardReceived(final String account, final String bareAddress, final VCard vCard) {
    final StructuredName name;
    if (vCard.getType() == Type.error) {
        onVCardFailed(account, bareAddress);
        if (names.containsKey(bareAddress)) {
            return;
        }
        name = EMPTY_STRUCTURED_NAME;
    } else {
        for (OnVCardListener listener : Application.getInstance().getUIListeners(OnVCardListener.class)) {
            listener.onVCardReceived(account, bareAddress, vCard);
        }
        String hash = vCard.getAvatarHash();
        AvatarManager.getInstance().onAvatarReceived(bareAddress, hash, vCard.getAvatar());
        name = new StructuredName(vCard.getNickName(), vCard.getField(VCardProperty.FN.name()), vCard.getFirstName(), vCard.getMiddleName(), vCard.getLastName());
        Application.getInstance().runInBackground(new Runnable() {

            @Override
            public void run() {
                try {
                    if (Jid.getBareAddress(account).equals(bareAddress)) {
                        PresenceManager.getInstance().resendPresence(account);
                    }
                } catch (NetworkException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    names.put(bareAddress, name);
    for (RosterContact rosterContact : RosterManager.getInstance().getContacts()) {
        if (rosterContact.getUser().equals(bareAddress)) {
            for (OnRosterChangedListener listener : Application.getInstance().getManagers(OnRosterChangedListener.class)) {
                listener.onContactStructuredInfoChanged(rosterContact, name);
            }
        }
    }
    Application.getInstance().runInBackground(new Runnable() {

        @Override
        public void run() {
            VCardTable.getInstance().write(bareAddress, name);
        }
    });
    if (vCard.getFrom() == null) {
        // account it self
        AccountManager.getInstance().onAccountChanged(account);
    } else {
        RosterManager.getInstance().onContactChanged(account, bareAddress);
    }
}
Also used : OnRosterChangedListener(com.xabber.android.data.roster.OnRosterChangedListener) RosterContact(com.xabber.android.data.roster.RosterContact) StructuredName(com.xabber.android.data.roster.StructuredName) NetworkException(com.xabber.android.data.NetworkException)

Example 8 with RosterContact

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

the class VCardManager method onRosterReceived.

@Override
public void onRosterReceived(AccountItem accountItem) {
    String account = accountItem.getAccount();
    if (!accountRequested.contains(account) && SettingsManager.connectionLoadVCard()) {
        String bareAddress = Jid.getBareAddress(accountItem.getRealJid());
        if (bareAddress != null && !names.containsKey(bareAddress)) {
            request(account, bareAddress);
            accountRequested.add(account);
        }
    }
    // Request vCards for new contacts.
    for (RosterContact contact : RosterManager.getInstance().getContacts()) {
        if (account.equals(contact.getAccount()) && !names.containsKey(contact.getUser())) {
            request(account, contact.getUser());
        }
    }
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact)

Aggregations

RosterContact (com.xabber.android.data.roster.RosterContact)8 AbstractChat (com.xabber.android.data.message.AbstractChat)3 ArrayList (java.util.ArrayList)3 RoomChat (com.xabber.android.data.extension.muc.RoomChat)2 RoomContact (com.xabber.android.data.extension.muc.RoomContact)2 ChatContact (com.xabber.android.data.message.ChatContact)2 AbstractContact (com.xabber.android.data.roster.AbstractContact)2 AlertDialog (android.app.AlertDialog)1 Fragment (android.app.Fragment)1 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 NetworkException (com.xabber.android.data.NetworkException)1 CommonState (com.xabber.android.data.account.CommonState)1 BaseEntity (com.xabber.android.data.entity.BaseEntity)1 EntityIntentBuilder (com.xabber.android.data.intent.EntityIntentBuilder)1 OnRosterChangedListener (com.xabber.android.data.roster.OnRosterChangedListener)1