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");
}
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);
}
}
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());
}
}
}
Aggregations