package com.sogou.sogouchat.ui; import java.io.File; import java.util.regex.Matcher; import java.util.regex.Pattern; import android.os.Environment; import com.sogou.sogouchat.bean.MsgNode; import com.sogou.sogouchat.os.ChatAppConstant; import com.sogou.sogouchat.ui.ChatMsgViewAdapter.IMsgContentType; import com.sogou.sogouchat.ui.ChatMsgViewAdapter.IMsgViewType; public class ChatMsgEntity { public String mName; public long mDate; public String mContent; public int mCome; public int mType; public String mShortUrl; public String mLongUrl; public boolean mLoad; public ChatMsgEntity(){ } public ChatMsgEntity(MsgNode node, String name){ mLoad = false; mDate = node.mDate; setContent(node.mBody); mName = name; if (node.mType == 1){ mCome = IMsgViewType.MSG_COME; } else if (node.mType == 2) { mCome = IMsgViewType.MSG_TO; } } public void setContent(String body){ mContent = body; if (mContent.indexOf("点击[http://pinyin") != -1) { String ext=""; if (mContent.indexOf("图片") != -1) { mType = IMsgContentType.MSG_IMAGE; ext = ".png"; } else if (mContent.indexOf("录音") != -1 || mContent.indexOf("语音") != -1) { mType = IMsgContentType.MSG_AUDIO; ext = ".mp3"; } String filePath = Environment.getExternalStorageDirectory() + ChatAppConstant.SAVE_PATH + mDate+ ext; File file = new File(filePath); if (file.exists()){ mLoad = true; } else{ mLoad = false; Pattern pattern = Pattern .compile("(http://|https://){1}[\\w\\.\\-/:]+"); Matcher matcher = pattern.matcher(mContent); if (matcher.find()) { mShortUrl = matcher.group(); } } } else { mType = IMsgContentType.MSG_TEXT; } } }