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