Search in sources :

Example 1 with CharAvatarView

use of com.lingtuan.firefly.custom.CharAvatarView in project SmartMesh_Android by SmartMeshFoundation.

the class ChatAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Holder h;
    final ChatMsg msg = mList.get(position);
    final int type = getItemViewType(position);
    if (convertView == null) {
        h = new Holder();
        switch(type) {
            case // The other side of the text information
            LEFT_TEXT:
                convertView = View.inflate(mContext, R.layout.item_chatting_left_text, null);
                break;
            case // The other side of the picture information
            LEFT_IMAGE:
                convertView = View.inflate(mContext, R.layout.item_chatting_left_image, null);
                break;
            case // Each other's voice messages
            LEFT_AUDIO:
                convertView = View.inflate(mContext, R.layout.item_chatting_left_audio, null);
                break;
            case // The other side of the business card information
            LEFT_CARD:
                convertView = View.inflate(mContext, R.layout.item_chatting_left_card, null);
                break;
            case // Share information
            LEFT_SHARE:
                convertView = View.inflate(mContext, R.layout.item_chatting_left_share, null);
                break;
            /**
             *----------------------------------------------------
             */
            case // His text message
            RIGHT_TEXT:
                convertView = View.inflate(mContext, R.layout.item_chatting_right_text, null);
                break;
            case // His picture information
            RIGHT_IMAGE:
                convertView = View.inflate(mContext, R.layout.item_chatting_right_image, null);
                break;
            case // His voice messages
            RIGHT_AUDIO:
                convertView = View.inflate(mContext, R.layout.item_chatting_right_audio, null);
                break;
            case // Your business card information
            RIGHT_CARD:
                convertView = View.inflate(mContext, R.layout.item_chatting_right_card, null);
                break;
            case // Share information
            RIGHT_SHARE:
                convertView = View.inflate(mContext, R.layout.item_chatting_right_share, null);
                break;
            case // The system informs the information
            NOTIF:
                convertView = View.inflate(mContext, R.layout.item_chatting_notif, null);
                break;
            case // Received the documents
            LEFT_SEND_FILE:
                convertView = View.inflate(mContext, R.layout.item_chatting_left_file, null);
                break;
            case // From the file
            RIGHT_SEND_FILE:
                convertView = View.inflate(mContext, R.layout.item_chatting_right_file, null);
                break;
        }
        h.leftLinear = (LinearLayout) convertView.findViewById(R.id.item_chatting_body_linear);
        h.imageUploadLinear = (LinearLayout) convertView.findViewById(R.id.item_chatting_image_upload_linear);
        h.avatar = (CharAvatarView) convertView.findViewById(R.id.item_chatting_avatar);
        h.mNickname = (TextView) convertView.findViewById(R.id.item_chatting_nickname);
        h.content = (TextView) convertView.findViewById(R.id.item_chatting_text);
        h.time = (TextView) convertView.findViewById(R.id.item_chatting_time);
        h.icon = (ImageView) convertView.findViewById(R.id.item_chatting_icon);
        h.msgWarnning = (ImageView) convertView.findViewById(R.id.item_chatting_warnning);
        h.msgImage = (ImageView) convertView.findViewById(R.id.item_chatting_image);
        h.mNotifBar = (ProgressBar) convertView.findViewById(R.id.item_chatting_notif);
        h.shopAddress = (TextView) convertView.findViewById(R.id.item_chatting_third_address);
        h.shopName = (TextView) convertView.findViewById(R.id.item_chatting_third_name);
        h.shopImage = (CharAvatarView) convertView.findViewById(R.id.item_chatting_third_avatar);
        h.audioTimes = (TextView) convertView.findViewById(R.id.item_chatting_audio_times);
        h.audioIcon = (ImageView) convertView.findViewById(R.id.item_chatting_audio_icon);
        h.selectBox = (ImageView) convertView.findViewById(R.id.item_chatting_select_iv);
        h.relativeLayout = (RelativeLayout) convertView.findViewById(R.id.relativelayout);
        /**
         ************************Documents related to****************************************
         */
        h.imgFileLogo = (ImageView) convertView.findViewById(R.id.img_file_logo);
        h.txtFileName = (TextView) convertView.findViewById(R.id.txt_file_name);
        h.txtFileSize = (TextView) convertView.findViewById(R.id.txt_file_size);
        h.txtFileSendState = (TextView) convertView.findViewById(R.id.txt_file_sent_state);
        h.progressbarFile = (ProgressBar) convertView.findViewById(R.id.file_send_progress);
        convertView.setTag(h);
    } else {
        h = (Holder) convertView.getTag();
    }
    if (h.selectBox != null) {
        if (delete || forwarding || isUpload) {
            h.selectBox.setVisibility(View.VISIBLE);
            int resId = selectedList.get(msg.getMessageId()) == null ? R.drawable.checkbox_unselected : R.drawable.checkbox_selected;
            h.selectBox.setImageResource(resId);
            if (h.relativeLayout != null) {
                h.relativeLayout.setVisibility(View.VISIBLE);
                h.relativeLayout.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (forwarding && (type == LEFT_SEND_FILE || type == RIGHT_SEND_FILE)) {
                            if (msg.getCreateTime() > 0) {
                                // One to one message file
                                long time = msg.getCreateTime() + 7 * 24 * 3600 - System.currentTimeMillis() / 1000;
                                if (time <= 0) {
                                    // Has the failure
                                    return;
                                }
                            }
                        }
                        // Voice is selected //Except upload chat logs
                        if (isUpload || !(forwarding && (type == LEFT_AUDIO || type == RIGHT_AUDIO || type == LEFT_DATIONG_SOS))) {
                            selectedItem(msg);
                        }
                    }
                });
            }
        } else {
            if (h.relativeLayout != null) {
                h.relativeLayout.setVisibility(View.GONE);
            }
            h.selectBox.setVisibility(View.GONE);
        }
    }
    switch(type) {
        // The other side of the text information
        case LEFT_TEXT:
        case // His text message
        RIGHT_TEXT:
            showTextMsg(h, msg, type);
            break;
        // The other side of the picture information
        case LEFT_IMAGE:
        case // His picture information
        RIGHT_IMAGE:
            showImgMsg(h, msg);
            break;
        // Each other's voice messages
        case LEFT_AUDIO:
        case // His voice messages
        RIGHT_AUDIO:
            setAudioContent(h, position, type);
            break;
        // The other side of the business card information
        case LEFT_CARD:
        case // Your business card information
        RIGHT_CARD:
            showCardMsg(h, msg);
            break;
        case // Send the file
        RIGHT_SEND_FILE:
            showFileInfo(h, msg, true);
            break;
        case // Received the documents
        LEFT_SEND_FILE:
            showFileInfo(h, msg, true);
            break;
        // Share information
        case LEFT_SHARE:
        case RIGHT_SHARE:
            showShareMsg(h, msg);
            break;
        case // The system informs the information
        NOTIF:
            showSystemMsg(h, msg);
            return convertView;
    }
    h.avatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            UserBaseVo vo = new UserBaseVo();
            vo.setUsername(msg.getUsername());
            vo.setLocalId(msg.getUserId());
            vo.setThumb(msg.getUserImage());
            vo.setFriendLog(msg.getFriendLog());
            intentPeopleDetailUI(vo);
        }
    });
    h.avatar.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if ((isGroup || TextUtils.equals(Constants.APP_EVERYONE, msg.getChatId()) || TextUtils.equals(Constants.APP_MESH, msg.getChatId())) && !msg.isMe() && mInputContent != null && mChattingManager != null) {
                // Long press head @ function
                int selectIndex = mInputContent.getSelectionStart();
                Editable mEditable = mInputContent.getEditableText();
                mEditable.insert(selectIndex, "@" + msg.getRealname() + " ");
                mChattingManager.sbAtGroupSelectIds.add(msg.getUserId());
                Utils.showKeyBoard(mInputContent);
                if (AtGroupParser.getInstance() == null) {
                    AtGroupParser.init(new String[] { msg.getRealname() + " " }, new String[] { msg.getUserId() });
                } else {
                    AtGroupParser.getInstance().addParse(msg.getRealname() + " ", msg.getUserId());
                }
            }
            return true;
        }
    });
    if (h.leftLinear != null) {
        h.leftLinear.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                // Long chat content according to the event
                return onLongClickLogic(msg);
            }
        });
    }
    String url = "";
    if (msg.isMe()) {
        url = NextApplication.myInfo.getThumb();
    } else {
        url = msg.getUserImage();
        if (!TextUtils.isEmpty(tempAvatar.get(msg.getUserId()))) {
            url = tempAvatar.get(msg.getUserId());
        }
    }
    h.avatar.setText(msg.getUsername(), h.avatar, url);
    h.time.setVisibility(msg.isShowTime() ? View.VISIBLE : View.GONE);
    Utils.setLoginTime(mContext, h.time, msg.getMsgTime());
    if (h.mNickname != null) {
        if (!isGroup && !TextUtils.equals(Constants.APP_EVERYONE, msg.getChatId()) && !TextUtils.equals(Constants.APP_MESH, msg.getChatId())) {
            h.mNickname.setVisibility(View.GONE);
        } else {
            // group
            h.mNickname.setVisibility(View.VISIBLE);
            String name = msg.getUsername();
            if (!TextUtils.isEmpty(tempAvatar.get(msg.getUserId()))) {
                name = tempName.get(msg.getUserId());
            }
            h.mNickname.setText(name);
        }
    }
    return convertView;
}
Also used : OnLongClickListener(android.view.View.OnLongClickListener) Editable(android.text.Editable) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) CharAvatarView(com.lingtuan.firefly.custom.CharAvatarView) OnLongClickListener(android.view.View.OnLongClickListener) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo)

Aggregations

Editable (android.text.Editable)1 View (android.view.View)1 OnLongClickListener (android.view.View.OnLongClickListener)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 CharAvatarView (com.lingtuan.firefly.custom.CharAvatarView)1 ChatMsg (com.lingtuan.firefly.vo.ChatMsg)1 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)1