package com.sogouchat.ui;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.os.Environment;
import com.sogouchat.bean.MsgNode;
import com.sogouchat.os.ChatAppConstant;
import com.sogouchat.ui.ChatMsgViewAdapter.IMsgContentType;
import com.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);
mName = name;
if (node.mType == 1){
mCome = IMsgViewType.MSG_COME;
}
else if (node.mType == 2)
{
mCome = IMsgViewType.MSG_TO;
}
else if (node.mType == 3){
}
}
public ChatMsgEntity(ChatMsgViewAdapter chatMsgViewAdapter,
MsgNode node, String name) {
// TODO Auto-generated constructor stub
mLoad = false;
mDate = node.mDate;
setContent(node);
mName = name;
if (node.mType == 1){
mCome = IMsgViewType.MSG_COME;
}
else if (node.mType == 2)
{
mCome = IMsgViewType.MSG_TO;
}
else if (node.mType == 3){
chatMsgViewAdapter.mCtx.setDraft(node.mBody);
}
}
public void setContent(MsgNode node){
// mms
if (node.mProtocol == 1) {
mContent = "彩信";
return;
}
mContent = node.mBody;
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;
}
}
}