Search in sources :

Example 1 with EaseMessageAdapter

use of com.hyphenate.easeui.adapter.EaseMessageAdapter in project SmartCampus by Vegen.

the class EaseChatMessageList method init.

/**
 * init widget
 * @param toChatUsername
 * @param chatType
 * @param customChatRowProvider
 */
public void init(String toChatUsername, int chatType, EaseCustomChatRowProvider customChatRowProvider) {
    this.chatType = chatType;
    this.toChatUsername = toChatUsername;
    conversation = EMClient.getInstance().chatManager().getConversation(toChatUsername, EaseCommonUtils.getConversationType(chatType), true);
    messageAdapter = new EaseMessageAdapter(context, toChatUsername, chatType, listView);
    messageAdapter.setItemStyle(itemStyle);
    messageAdapter.setCustomChatRowProvider(customChatRowProvider);
    // set message adapter
    listView.setAdapter(messageAdapter);
    refreshSelectLast();
}
Also used : EaseMessageAdapter(com.hyphenate.easeui.adapter.EaseMessageAdapter)

Example 2 with EaseMessageAdapter

use of com.hyphenate.easeui.adapter.EaseMessageAdapter in project SmartCampus by Vegen.

the class EaseChatRow method setUpBaseView.

private void setUpBaseView() {
    // set nickname, avatar and background of bubble
    TextView timestamp = (TextView) findViewById(R.id.timestamp);
    if (timestamp != null) {
        if (position == 0) {
            timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
            timestamp.setVisibility(View.VISIBLE);
        } else {
            // show time stamp if interval with last message is > 30 seconds
            EMMessage prevMessage = (EMMessage) adapter.getItem(position - 1);
            if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) {
                timestamp.setVisibility(View.GONE);
            } else {
                timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
                timestamp.setVisibility(View.VISIBLE);
            }
        }
    }
    if (userAvatarView != null) {
        // set nickname and avatar
        if (message.direct() == Direct.SEND) {
            EaseUserUtils.setUserAvatar(context, EMClient.getInstance().getCurrentUser(), userAvatarView);
        } else {
            EaseUserUtils.setUserAvatar(context, message.getFrom(), userAvatarView);
            EaseUserUtils.setUserNick(message.getFrom(), usernickView);
        }
    }
    if (EMClient.getInstance().getOptions().getRequireDeliveryAck()) {
        if (deliveredView != null) {
            if (message.isDelivered()) {
                deliveredView.setVisibility(View.VISIBLE);
            } else {
                deliveredView.setVisibility(View.INVISIBLE);
            }
        }
    }
    if (EMClient.getInstance().getOptions().getRequireAck()) {
        if (ackedView != null) {
            if (message.isAcked()) {
                if (deliveredView != null) {
                    deliveredView.setVisibility(View.INVISIBLE);
                }
                ackedView.setVisibility(View.VISIBLE);
            } else {
                ackedView.setVisibility(View.INVISIBLE);
            }
        }
    }
    if (itemStyle != null) {
        if (userAvatarView != null) {
            if (itemStyle.isShowAvatar()) {
                userAvatarView.setVisibility(View.VISIBLE);
                EaseAvatarOptions avatarOptions = EaseUI.getInstance().getAvatarOptions();
                if (avatarOptions != null && userAvatarView instanceof EaseImageView) {
                    EaseImageView avatarView = ((EaseImageView) userAvatarView);
                    if (avatarOptions.getAvatarShape() != 0)
                        avatarView.setShapeType(avatarOptions.getAvatarShape());
                    if (avatarOptions.getAvatarBorderWidth() != 0)
                        avatarView.setBorderWidth(avatarOptions.getAvatarBorderWidth());
                    if (avatarOptions.getAvatarBorderColor() != 0)
                        avatarView.setBorderColor(avatarOptions.getAvatarBorderColor());
                    if (avatarOptions.getAvatarRadius() != 0)
                        avatarView.setRadius(avatarOptions.getAvatarRadius());
                }
            } else {
                userAvatarView.setVisibility(View.GONE);
            }
        }
        if (usernickView != null) {
            if (itemStyle.isShowUserNick())
                usernickView.setVisibility(View.VISIBLE);
            else
                usernickView.setVisibility(View.GONE);
        }
        if (bubbleLayout != null) {
            if (message.direct() == Direct.SEND) {
                if (itemStyle.getMyBubbleBg() != null) {
                    bubbleLayout.setBackgroundDrawable(((EaseMessageAdapter) adapter).getMyBubbleBg());
                }
            } else if (message.direct() == Direct.RECEIVE) {
                if (itemStyle.getOtherBubbleBg() != null) {
                    bubbleLayout.setBackgroundDrawable(((EaseMessageAdapter) adapter).getOtherBubbleBg());
                }
            }
        }
    }
}
Also used : EaseImageView(com.hyphenate.easeui.widget.EaseImageView) EaseMessageAdapter(com.hyphenate.easeui.adapter.EaseMessageAdapter) TextView(android.widget.TextView) Date(java.util.Date) EMMessage(com.hyphenate.chat.EMMessage) EaseAvatarOptions(com.hyphenate.easeui.domain.EaseAvatarOptions)

Aggregations

EaseMessageAdapter (com.hyphenate.easeui.adapter.EaseMessageAdapter)2 TextView (android.widget.TextView)1 EMMessage (com.hyphenate.chat.EMMessage)1 EaseAvatarOptions (com.hyphenate.easeui.domain.EaseAvatarOptions)1 EaseImageView (com.hyphenate.easeui.widget.EaseImageView)1 Date (java.util.Date)1