MsgViewHolderAVChat.java 2.71 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package com.yidianling.im.session.viewholder;

import android.graphics.Color;
import android.widget.ImageView;
import android.widget.TextView;

import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;
import com.netease.nimlib.sdk.avchat.constant.AVChatType;
import com.netease.nimlib.sdk.avchat.model.AVChatAttachment;
import com.yidianling.im.R;
import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.yidianling.nimbase.common.util.sys.TimeUtil;

/**
 * Created by zhoujianghua on 2015/8/6.
 */
public class MsgViewHolderAVChat extends MsgViewHolderBase {

    private ImageView typeImage;
    private TextView statusLabel;

    public MsgViewHolderAVChat(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }

    @Override
    protected int getContentResId() {
konghaorui committed
28
        return R.layout.im_nim_message_item_avchat;
konghaorui committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    }

    @Override
    protected void inflateContentView() {
        typeImage = findViewById(R.id.message_item_avchat_type_img);
        statusLabel = findViewById(R.id.message_item_avchat_state);
    }

    @Override
    protected void bindContentView() {
        if (message.getAttachment() == null) {
            return;
        }

        layoutByDirection();

        refreshContent();
    }

    private void layoutByDirection() {
        AVChatAttachment attachment = (AVChatAttachment) message.getAttachment();

        if (isReceivedMessage()) {
            if (attachment.getType() == AVChatType.AUDIO) {
konghaorui committed
53
                typeImage.setImageResource(R.drawable.im_avchat_left_type_audio);
konghaorui committed
54
            } else {
konghaorui committed
55
                typeImage.setImageResource(R.drawable.im_avchat_left_type_video);
konghaorui committed
56 57 58 59
            }
            statusLabel.setTextColor(context.getResources().getColor(R.color.platform_color_grey_999999));
        } else {
            if (attachment.getType() == AVChatType.AUDIO) {
konghaorui committed
60
                typeImage.setImageResource(R.drawable.im_avchat_right_type_audio);
konghaorui committed
61
            } else {
konghaorui committed
62
                typeImage.setImageResource(R.drawable.im_avchat_right_type_video);
konghaorui committed
63 64 65 66 67 68 69 70 71 72 73
            }
            statusLabel.setTextColor(Color.WHITE);
        }
    }

    private void refreshContent() {
        AVChatAttachment attachment = (AVChatAttachment) message.getAttachment();

        String textString = "";
        switch (attachment.getState()) {
        case Success: //成功接听
74
            textString = "通话接听时长 " + TimeUtil.secToTime(attachment.getDuration());
konghaorui committed
75 76 77
            break;
        case Missed: //未接听
        case Rejected: //主动拒绝
konghaorui committed
78
            textString = context.getString(R.string.im_avchat_no_pick_up);
konghaorui committed
79 80 81 82 83 84 85 86
            break;
        default:
            break;
        }

        statusLabel.setText(textString);
    }
}