/**
* 解析历史记录
*
* @param messages
*/
private void parsingListMessage(List messages) {
//倒序
Collections.reverse(messages);
//遍历
for (int i = 0; i < messages.size(); i++) {
Message m = messages.get(i);
String objectName = m.getObjectName();
if (objectName.equals(CloudManager.MSG_TEXT_NAME)) {
TextMessage textMessage = (TextMessage) m.getContent();
String msg = textMessage.getContent();
LogUtils.i(“msg:” + msg);
try {
TextBean textBean = new Gson().fromJson(msg, TextBean.class);
if (textBean.getType().equals(CloudManager.TYPE_TEXT)) {
//添加到UI 判断是你 还是 我
if (m.getSenderUserId().equals(yourUserId)) {
addText(0, textBean.getMsg());
} else {
addText(1, textBean.getMsg());
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (objectName.equals(CloudManager.MSG_IMAGE_NAME)) {
ImageMessage imageMessage = (ImageMessage) m.getContent();
String url = imageMessage.getRemoteUri().toString();
if (!TextUtils.isEmpty(url)) {
LogUtils.i(“url:” + url);
if (m.getSenderUserId().equals(yourUserId)) {
addImage(0, url);
} else {
addImage(1, url);
}
}
} else if (objectName.equals(CloudManager.MSG_LOCATION_NAME)) {
LocationMessage locationMessage = (LocationMessage) m.getContent();
if (m.getSenderUserId().equals(yourUserId)) {
addLocation(0, locationMessage.getLat(),
locationMessage.getLng(), locationMessage.getPoi());
} else {
addLocation(1, locationMessage.getLat(),
locationMessage.getLng(), locationMessage.getPoi());
}
}
}
}
老师,这个解析历史记录有什么用?
比如我发送了图片给另外一个人,然后图片会通过适配器弄到列表上
//发送图片消息
CloudManager.getInstance().sendImageMessage(yourUserId, uploadFile);
//更新列表
addImage(1, uploadFile);
这里怎么又去读取这个历史记录?那不会添加两次吗?有点理不清这里的关系。。。