Search in sources :

Example 6 with AbstractChat

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

the class ChatViewerAdapter method isChatsEquals.

private boolean isChatsEquals(ArrayList<AbstractChat> newChats) {
    if (newChats.size() != activeChats.size()) {
        return false;
    }
    for (int i = 0; i < activeChats.size(); i++) {
        AbstractChat oldChat = activeChats.get(i);
        AbstractChat newChat = newChats.get(i);
        if (!oldChat.equals(newChat.getAccount(), newChat.getUser())) {
            return false;
        }
    }
    return true;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 7 with AbstractChat

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

the class ContactItemInflater method setUpContactView.

public View setUpContactView(View convertView, ViewGroup parent, final AbstractContact contact) {
    final View view;
    final ContactListItemViewHolder viewHolder;
    if (convertView == null) {
        view = LayoutInflater.from(context).inflate(R.layout.contact_list_item, parent, false);
        viewHolder = new ContactListItemViewHolder(view);
        view.setTag(viewHolder);
    } else {
        view = convertView;
        viewHolder = (ContactListItemViewHolder) view.getTag();
    }
    if (contact.isConnected()) {
        viewHolder.offlineShadow.setVisibility(View.GONE);
    } else {
        viewHolder.offlineShadow.setVisibility(View.VISIBLE);
    }
    viewHolder.color.setImageDrawable(new ColorDrawable(ColorManager.getInstance().getAccountPainter().getAccountMainColor(contact.getAccount())));
    viewHolder.color.setVisibility(View.VISIBLE);
    if (SettingsManager.contactsShowAvatars()) {
        viewHolder.avatar.setVisibility(View.VISIBLE);
        viewHolder.avatar.setImageDrawable(contact.getAvatarForContactList());
    } else {
        viewHolder.avatar.setVisibility(View.GONE);
    }
    viewHolder.avatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onAvatarClick(contact);
        }
    });
    viewHolder.name.setText(contact.getName());
    MessageManager messageManager = MessageManager.getInstance();
    if (MUCManager.getInstance().isMucPrivateChat(contact.getAccount(), contact.getUser())) {
        viewHolder.name.setTextColor(ColorManager.getInstance().getColorMucPrivateChatText());
    } else if (messageManager.hasActiveChat(contact.getAccount(), contact.getUser())) {
        viewHolder.name.setTextColor(ColorManager.getInstance().getActiveChatTextColor());
    } else {
        viewHolder.name.setTextColor(ColorManager.getInstance().getColorMain());
    }
    if (MUCManager.getInstance().hasRoom(contact.getAccount(), contact.getUser())) {
        viewHolder.mucIndicator.setVisibility(View.VISIBLE);
        viewHolder.mucIndicator.setImageResource(R.drawable.ic_muc_indicator_black_16dp);
    } else if (MUCManager.getInstance().isMucPrivateChat(contact.getAccount(), contact.getUser())) {
        viewHolder.mucIndicator.setVisibility(View.VISIBLE);
        viewHolder.mucIndicator.setImageResource(R.drawable.ic_muc_private_chat_indicator_black_16dp);
    } else {
        viewHolder.mucIndicator.setVisibility(View.GONE);
    }
    String statusText;
    viewHolder.outgoingMessageIndicator.setVisibility(View.GONE);
    viewHolder.smallRightText.setVisibility(View.GONE);
    viewHolder.smallRightIcon.setVisibility(View.GONE);
    ClientSoftware clientSoftware = contact.getClientSoftware();
    if (clientSoftware == ClientSoftware.unknown) {
        viewHolder.largeClientIcon.setVisibility(View.GONE);
    } else {
        viewHolder.largeClientIcon.setVisibility(View.VISIBLE);
        viewHolder.largeClientIcon.setImageLevel(clientSoftware.ordinal());
    }
    if (messageManager.hasActiveChat(contact.getAccount(), contact.getUser())) {
        AbstractChat chat = messageManager.getChat(contact.getAccount(), contact.getUser());
        statusText = chat.getLastText().trim();
        view.setBackgroundColor(ColorManager.getInstance().getActiveChatBackgroundColor());
        viewHolder.separator.setBackgroundColor(ColorManager.getInstance().getActiveChatSeparatorColor());
        viewHolder.largeClientIcon.setColorFilter(ColorManager.getInstance().getActiveChatLargeClientIconColor());
        if (!statusText.isEmpty()) {
            viewHolder.smallRightText.setText(StringUtils.getSmartTimeText(context, chat.getLastTime()));
            viewHolder.smallRightText.setVisibility(View.VISIBLE);
            if (!chat.isLastMessageIncoming()) {
                viewHolder.outgoingMessageIndicator.setText(context.getString(R.string.sender_is_you) + ": ");
                viewHolder.outgoingMessageIndicator.setVisibility(View.VISIBLE);
                viewHolder.outgoingMessageIndicator.setTextColor(ColorManager.getInstance().getAccountPainter().getAccountMainColor(contact.getAccount()));
            }
            viewHolder.smallRightIcon.setImageResource(R.drawable.ic_client_small);
            viewHolder.smallRightIcon.setVisibility(View.VISIBLE);
            viewHolder.smallRightIcon.setImageLevel(clientSoftware.ordinal());
            viewHolder.largeClientIcon.setVisibility(View.GONE);
        }
    } else {
        statusText = contact.getStatusText().trim();
        view.setBackgroundColor(ColorManager.getInstance().getContactBackground());
        viewHolder.separator.setBackgroundColor(ColorManager.getInstance().getContactSeparatorColor());
        viewHolder.largeClientIcon.setColorFilter(ColorManager.getInstance().getContactLargeClientIconColor());
    }
    if (statusText.isEmpty()) {
        viewHolder.secondLineMessage.setVisibility(View.GONE);
    } else {
        viewHolder.secondLineMessage.setVisibility(View.VISIBLE);
        viewHolder.secondLineMessage.setText(Emoticons.getSmiledText(context, statusText, viewHolder.secondLineMessage));
    }
    viewHolder.statusIcon.setImageLevel(contact.getStatusMode().getStatusLevel());
    return view;
}
Also used : MessageManager(com.xabber.android.data.message.MessageManager) ColorDrawable(android.graphics.drawable.ColorDrawable) AbstractChat(com.xabber.android.data.message.AbstractChat) ClientSoftware(com.xabber.android.data.extension.capability.ClientSoftware) View(android.view.View)

Example 8 with AbstractChat

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

the class ChatListAdapter method getView.

@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);
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) AbstractContact(com.xabber.android.data.roster.AbstractContact)

Example 9 with AbstractChat

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

the class RosterManager method getBestContact.

/**
     * Gets {@link RoomContact}, {@link RosterContact}, {@link ChatContact} or
     * creates new {@link ChatContact}.
     *
     * @param account
     * @param user
     * @return
     */
public AbstractContact getBestContact(String account, String user) {
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
    if (abstractChat != null && abstractChat instanceof RoomChat) {
        return new RoomContact((RoomChat) abstractChat);
    }
    RosterContact rosterContact = getRosterContact(account, user);
    if (rosterContact != null) {
        return rosterContact;
    }
    if (abstractChat != null) {
        return new ChatContact(abstractChat);
    }
    return new ChatContact(account, user);
}
Also used : RoomContact(com.xabber.android.data.extension.muc.RoomContact) AbstractChat(com.xabber.android.data.message.AbstractChat) RoomChat(com.xabber.android.data.extension.muc.RoomChat) ChatContact(com.xabber.android.data.message.ChatContact)

Example 10 with AbstractChat

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

the class RosterManager method getBestContact.

/**
 * Gets {@link RoomContact}, {@link RosterContact}, {@link ChatContact} or
 * creates new {@link ChatContact}.
 *
 * @param account
 * @param user
 * @return
 */
public AbstractContact getBestContact(AccountJid account, UserJid user) {
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
    if (abstractChat != null && abstractChat instanceof RoomChat) {
        return new RoomContact((RoomChat) abstractChat);
    }
    RosterContact rosterContact = getRosterContact(account, user);
    if (rosterContact != null) {
        return rosterContact;
    }
    if (abstractChat != null) {
        return new ChatContact(abstractChat);
    }
    return new ChatContact(account, user);
}
Also used : RoomContact(com.xabber.android.data.extension.muc.RoomContact) AbstractChat(com.xabber.android.data.message.AbstractChat) RoomChat(com.xabber.android.data.extension.muc.RoomChat) ChatContact(com.xabber.android.data.message.ChatContact)

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