/**
  * 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");
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   final AbstractChat abstractChat = (AbstractChat) getItem(position);
   final AbstractContact abstractContact =
       RosterManager.getInstance()
           .getBestContact(abstractChat.getAccount(), abstractChat.getUser());
   return contactItemInflater.setUpContactView(convertView, parent, abstractContact);
 }
 private void closeAllChats() {
   for (AbstractChat chat : MessageManager.getInstance().getActiveChats()) {
     MessageManager.getInstance().closeChat(chat.getAccount(), chat.getUser());
     NotificationManager.getInstance()
         .removeMessageNotification(chat.getAccount(), chat.getUser());
   }
   getContactListFragment().getAdapter().onChange();
 }