Search in sources :

Example 41 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatActivity method createSpecificChatIntent.

public static Intent createSpecificChatIntent(Context context, AccountJid account, UserJid user) {
    Intent intent = new EntityIntentBuilder(context, ChatActivity.class).setAccount(account).setUser(user).build();
    intent.setAction(ACTION_SPECIFIC_CHAT);
    AbstractChat chat = MessageManager.getInstance().getChat(account, user);
    intent.putExtra(KEY_SHOW_ARCHIVED, chat != null && chat.isArchived());
    return intent;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) Intent(android.content.Intent) EntityIntentBuilder(com.xabber.android.data.intent.EntityIntentBuilder)

Example 42 with AbstractChat

use of com.xabber.android.data.message.AbstractChat 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 43 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class OccupantListActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    com.xabber.android.data.extension.muc.Occupant occupant = (com.xabber.android.data.extension.muc.Occupant) listAdapter.getItem(position);
    LogManager.i(this, occupant.getNickname().toString());
    UserJid occupantFullJid = null;
    try {
        occupantFullJid = UserJid.from(JidCreate.entityFullFrom(room, occupant.getNickname()));
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
        return;
    }
    final AbstractChat mucPrivateChat;
    try {
        mucPrivateChat = MessageManager.getInstance().getOrCreatePrivateMucChat(account, occupantFullJid.getJid().asFullJidIfPossible());
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
        return;
    }
    mucPrivateChat.setIsPrivateMucChatAccepted(true);
    startActivity(ChatActivity.createSpecificChatIntent(this, account, occupantFullJid));
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) UserJid(com.xabber.android.data.entity.UserJid)

Example 44 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ContactListPresenter method getAllChatsSize.

public int getAllChatsSize() {
    Collection<AbstractChat> chats = MessageManager.getInstance().getChatsOfEnabledAccount();
    GroupConfiguration chatsGroup = getChatsGroup(chats, ChatListState.all);
    return chatsGroup.getTotal();
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) GroupConfiguration(com.xabber.android.ui.adapter.contactlist.GroupConfiguration)

Example 45 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ContactListPresenter method getTwoNextRecentChat.

public ArrayList<IFlexible> getTwoNextRecentChat() {
    Collection<AbstractChat> chats = MessageManager.getInstance().getChatsOfEnabledAccount();
    GroupConfiguration chatsGroup = getChatsGroup(chats, currentChatsState);
    ArrayList<AbstractContact> contacts = (ArrayList<AbstractContact>) chatsGroup.getAbstractContacts();
    ArrayList<IFlexible> items = new ArrayList<>();
    if (contacts != null && contacts.size() >= MAX_RECENT_ITEMS) {
        items.add(ChatVO.convert(contacts.get(MAX_RECENT_ITEMS - 2), this, null));
        if (getAllChatsSize() > MAX_RECENT_ITEMS)
            items.add(ChatWithButtonVO.convert(contacts.get(MAX_RECENT_ITEMS - 1), this));
        else
            items.add(ChatVO.convert(contacts.get(MAX_RECENT_ITEMS - 1), this));
    }
    return items;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) ArrayList(java.util.ArrayList) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) GroupConfiguration(com.xabber.android.ui.adapter.contactlist.GroupConfiguration) AbstractContact(com.xabber.android.data.roster.AbstractContact)

Aggregations

AbstractChat (com.xabber.android.data.message.AbstractChat)55 UserJid (com.xabber.android.data.entity.UserJid)10 RoomChat (com.xabber.android.data.extension.muc.RoomChat)10 NetworkException (com.xabber.android.data.NetworkException)9 RegularChat (com.xabber.android.data.message.RegularChat)9 ArrayList (java.util.ArrayList)8 AccountJid (com.xabber.android.data.entity.AccountJid)7 RoomContact (com.xabber.android.data.extension.muc.RoomContact)6 ChatContact (com.xabber.android.data.message.ChatContact)6 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 RosterContact (com.xabber.android.data.roster.RosterContact)6 NotificationState (com.xabber.android.data.message.NotificationState)5 Message (org.jivesoftware.smack.packet.Message)5 GroupConfiguration (com.xabber.android.ui.adapter.contactlist.GroupConfiguration)4 View (android.view.View)3 MessageManager (com.xabber.android.data.message.MessageManager)3 Map (java.util.Map)3 Intent (android.content.Intent)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2