Search in sources :

Example 16 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 17 with RosterContact

use of com.xabber.android.data.roster.RosterContact 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)

Example 18 with RosterContact

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

the class ChatActivity method editAlias.

private void editAlias() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.edit_alias);
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, user);
    if (rosterContact != null)
        input.setText(rosterContact.getName());
    builder.setView(input);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            RosterManager.getInstance().setName(account, user, input.getText().toString());
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    builder.show();
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) RosterContact(com.xabber.android.data.roster.RosterContact) DialogInterface(android.content.DialogInterface) EntityIntentBuilder(com.xabber.android.data.intent.EntityIntentBuilder)

Example 19 with RosterContact

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

the class ContactEditActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Toolbar toolbar = getToolbar();
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(getAccount(), getUser());
    if (rosterContact != null) {
        toolbar.inflateMenu(R.menu.toolbar_contact);
        toolbar.setOnMenuItemClickListener(this);
        toolbar.setOverflowIcon(getResources().getDrawable(R.drawable.ic_overflow_menu_white_24dp));
        onCreateOptionsMenu(toolbar.getMenu());
    }
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) Toolbar(androidx.appcompat.widget.Toolbar)

Example 20 with RosterContact

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

the class ContactEditActivity method sendContact.

private void sendContact() {
    RosterContact rosterContact = RosterManager.getInstance().getRosterContact(getAccount(), getUser());
    String text = rosterContact != null ? rosterContact.getName() + "\nxmpp:" + getUser().toString() : "xmpp:" + getUser().toString();
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, text);
    sendIntent.setType("text/plain");
    startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) Intent(android.content.Intent)

Aggregations

RosterContact (com.xabber.android.data.roster.RosterContact)24 AbstractChat (com.xabber.android.data.message.AbstractChat)11 ArrayList (java.util.ArrayList)8 RoomChat (com.xabber.android.data.extension.muc.RoomChat)6 AccountJid (com.xabber.android.data.entity.AccountJid)5 UserJid (com.xabber.android.data.entity.UserJid)5 RoomContact (com.xabber.android.data.extension.muc.RoomContact)5 ChatContact (com.xabber.android.data.message.ChatContact)5 AbstractContact (com.xabber.android.data.roster.AbstractContact)5 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 EditText (android.widget.EditText)3 CommonState (com.xabber.android.data.account.CommonState)3 EntityIntentBuilder (com.xabber.android.data.intent.EntityIntentBuilder)3 Collection (java.util.Collection)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 Intent (android.content.Intent)2 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 BaseEntity (com.xabber.android.data.entity.BaseEntity)2