Search in sources :

Example 1 with Draft

use of cn.wildfire.chat.kit.conversation.Draft in project android-chat by wildfirechat.

the class ConversationViewHolder method onBind.

public void onBind(ConversationInfo conversationInfo) {
    secretChatIndicator.setVisibility(View.GONE);
    onBindConversationInfo(conversationInfo);
    timeTextView.setText(TimeUtils.getMsgFormatTime(conversationInfo.timestamp));
    silentImageView.setVisibility(conversationInfo.isSilent ? View.VISIBLE : View.GONE);
    statusImageView.setVisibility(View.GONE);
    itemView.setBackgroundResource(conversationInfo.isTop ? R.drawable.selector_stick_top_item : R.drawable.selector_common_item);
    redDotView.setVisibility(View.GONE);
    if (conversationInfo.isSilent) {
        if (conversationInfo.unreadCount.unread > 0) {
            // 显示红点
            unreadCountTextView.setText("");
            unreadCountTextView.setVisibility(View.GONE);
            redDotView.setVisibility(View.VISIBLE);
        } else {
            unreadCountTextView.setVisibility(View.GONE);
        }
    } else {
        if (conversationInfo.unreadCount.unread > 0) {
            unreadCountTextView.setVisibility(View.VISIBLE);
            unreadCountTextView.setText(conversationInfo.unreadCount.unread > 99 ? "99+" : conversationInfo.unreadCount.unread + "");
        } else {
            unreadCountTextView.setVisibility(View.GONE);
        }
    }
    Draft draft = Draft.fromDraftJson(conversationInfo.draft);
    if (draft != null) {
        String draftString = draft.getContent() != null ? draft.getContent() : "[草稿]";
        MoonUtils.identifyFaceExpression(fragment.getActivity(), contentTextView, draft.getContent(), ImageSpan.ALIGN_BOTTOM);
        setViewVisibility(R.id.promptTextView, View.VISIBLE);
        setViewVisibility(R.id.contentTextView, View.VISIBLE);
    } else {
        if (conversationInfo.unreadCount.unreadMentionAll > 0 || conversationInfo.unreadCount.unreadMention > 0) {
            promptTextView.setText("[有人@我]");
            promptTextView.setVisibility(View.VISIBLE);
        } else {
            promptTextView.setVisibility(View.GONE);
        }
        setViewVisibility(R.id.contentTextView, View.VISIBLE);
        if (conversationInfo.lastMessage != null && conversationInfo.lastMessage.content != null) {
            String content = "";
            Message lastMessage = conversationInfo.lastMessage;
            // the message maybe invalid
            try {
                if (conversationInfo.conversation.type == Conversation.ConversationType.Group && lastMessage.direction == MessageDirection.Receive && !(lastMessage.content instanceof NotificationMessageContent)) {
                    GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class);
                    String senderDisplayName = groupViewModel.getGroupMemberDisplayName(conversationInfo.conversation.target, conversationInfo.lastMessage.sender);
                    content = senderDisplayName + ":" + lastMessage.digest();
                } else {
                    content = lastMessage.digest();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            content = WfcTextUtils.htmlToText(content);
            MoonUtils.identifyFaceExpression(fragment.getActivity(), contentTextView, content, ImageSpan.ALIGN_BOTTOM);
            switch(lastMessage.status) {
                case Sending:
                    statusImageView.setVisibility(View.VISIBLE);
                    // TODO update sending image resource
                    statusImageView.setImageResource(R.mipmap.ic_sending);
                    break;
                case Send_Failure:
                    statusImageView.setVisibility(View.VISIBLE);
                    statusImageView.setImageResource(R.mipmap.img_error);
                    break;
                default:
                    statusImageView.setVisibility(View.GONE);
                    break;
            }
        } else {
            contentTextView.setText("");
        }
    }
}
Also used : Draft(cn.wildfire.chat.kit.conversation.Draft) Message(cn.wildfirechat.message.Message) GroupViewModel(cn.wildfire.chat.kit.group.GroupViewModel) NotificationMessageContent(cn.wildfirechat.message.notification.NotificationMessageContent)

Aggregations

Draft (cn.wildfire.chat.kit.conversation.Draft)1 GroupViewModel (cn.wildfire.chat.kit.group.GroupViewModel)1 Message (cn.wildfirechat.message.Message)1 NotificationMessageContent (cn.wildfirechat.message.notification.NotificationMessageContent)1