use of com.easemob.chat.EMConversation in project wechat by motianhuo.
the class Fragment_Msg method onItemClick.
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if (adpter.PublicMsg != null && position == 0) {
// 打开订阅号列表页面
Utils.start_Activity(getActivity(), PublishMsgListActivity.class);
} else {
((MainActivity) getActivity()).updateUnreadLabel();
EMConversation conversation = conversationList.get(position);
Intent intent = new Intent(getActivity(), ChatActivity.class);
Hashtable<String, String> ChatRecord = adpter.getChatRecord();
if (ChatRecord != null) {
if (conversation.isGroup()) {
GroupInfo info = GloableParams.GroupInfos.get(conversation.getUserName());
if (info != null) {
intent.putExtra(Constants.TYPE, ChatActivity.CHATTYPE_GROUP);
intent.putExtra(Constants.GROUP_ID, info.getGroup_id());
// 设置标题
intent.putExtra(Constants.NAME, info.getGroup_name());
getActivity().startActivity(intent);
} else {
intent.putExtra(Constants.TYPE, ChatActivity.CHATTYPE_GROUP);
intent.putExtra(Constants.GROUP_ID, info.getGroup_id());
// 设置标题
intent.putExtra(Constants.NAME, R.string.group_chats);
getActivity().startActivity(intent);
}
} else {
User user = GloableParams.Users.get(conversation.getUserName());
if (user != null) {
// 设置昵称
intent.putExtra(Constants.NAME, user.getUserName());
intent.putExtra(Constants.TYPE, ChatActivity.CHATTYPE_SINGLE);
intent.putExtra(Constants.User_ID, conversation.getUserName());
getActivity().startActivity(intent);
} else {
intent.putExtra(Constants.NAME, "好友");
intent.putExtra(Constants.TYPE, ChatActivity.CHATTYPE_SINGLE);
intent.putExtra(Constants.User_ID, conversation.getUserName());
getActivity().startActivity(intent);
}
}
}
}
}
use of com.easemob.chat.EMConversation in project wechat by motianhuo.
the class Fragment_Msg method initViews.
private void initViews() {
conversationList.addAll(loadConversationsWithRecentChat());
if (conversationList != null && conversationList.size() > 0) {
layout.findViewById(R.id.txt_nochat).setVisibility(View.GONE);
adpter = new NewMsgAdpter(getActivity(), conversationList);
// TODO 加载订阅号信息 ,增加一个Item
// if (GloableParams.isHasPulicMsg) {
EMConversation nee = new EMConversation("100000");
conversationList.add(0, nee);
String time = Utils.getValue(getActivity(), "Time");
String content = Utils.getValue(getActivity(), "Content");
time = "下午 02:45";
content = "[腾讯娱乐]《炉石传说》荣列中国区App Store年度精选";
PublicMsgInfo msgInfo = new PublicMsgInfo();
msgInfo.setContent(content);
msgInfo.setMsg_ID("12");
msgInfo.setTime(time);
adpter.setPublicMsg(msgInfo);
// }
lvContact.setAdapter(adpter);
} else {
layout.findViewById(R.id.txt_nochat).setVisibility(View.VISIBLE);
}
}
use of com.easemob.chat.EMConversation in project wechat by motianhuo.
the class Fragment_Msg method loadConversationsWithRecentChat.
/**
* 获取所有会话
*
* @param context
* @return +
*/
private List<EMConversation> loadConversationsWithRecentChat() {
// 获取所有会话,包括陌生人
Hashtable<String, EMConversation> conversations = EMChatManager.getInstance().getAllConversations();
List<EMConversation> list = new ArrayList<EMConversation>();
// 过滤掉messages seize为0的conversation
for (EMConversation conversation : conversations.values()) {
if (conversation.getAllMessages().size() != 0)
list.add(conversation);
}
// 排序
sortConversationByLastChatTime(list);
return list;
}
use of com.easemob.chat.EMConversation in project wechat by motianhuo.
the class NewMsgAdpter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.layout_item_msg, parent, false);
}
ImageView img_avar = ViewHolder.get(convertView, R.id.contactitem_avatar_iv);
TextView txt_name = ViewHolder.get(convertView, R.id.txt_name);
TextView txt_state = ViewHolder.get(convertView, R.id.txt_state);
TextView txt_del = ViewHolder.get(convertView, R.id.txt_del);
TextView txt_content = ViewHolder.get(convertView, R.id.txt_content);
TextView txt_time = ViewHolder.get(convertView, R.id.txt_time);
TextView unreadLabel = ViewHolder.get(convertView, R.id.unread_msg_number);
SwipeLayout swipe = ViewHolder.get(convertView, R.id.swipe);
if (PublicMsg != null && position == 0) {
txt_name.setText("订阅号");
img_avar.setImageResource(R.drawable.icon_public);
txt_time.setText(PublicMsg.getTime());
txt_content.setText(PublicMsg.getContent());
unreadLabel.setText("3");
unreadLabel.setVisibility(View.VISIBLE);
swipe.setSwipeEnabled(false);
} else {
swipe.setSwipeEnabled(true);
// 获取与此用户/群组的会话
final EMConversation conversation = conversationList.get(position);
// 获取用户username或者群组groupid
ChatID = conversation.getUserName();
txt_del.setTag(ChatID);
if (conversation.isGroup()) {
img_avar.setImageResource(R.drawable.defult_group);
GroupInfo info = GloableParams.GroupInfos.get(ChatID);
if (info != null) {
txt_name.setText(info.getGroup_name());
} else {
// initGroupInfo(img_avar, txt_name);// 获取群组信息
}
} else {
User user = GloableParams.Users.get(ChatID);
if (user != null) {
txt_name.setText(user.getUserName());
} else {
txt_name.setText("好友");
// 获取用户信息
UserUtils.initUserInfo(context, ChatID, img_avar, txt_name);
}
}
if (conversation.getUnreadMsgCount() > 0) {
// 显示与此用户的消息未读数
unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount()));
unreadLabel.setVisibility(View.VISIBLE);
} else {
unreadLabel.setVisibility(View.INVISIBLE);
}
if (conversation.getMsgCount() != 0) {
// 把最后一条消息的内容作为item的message内容
EMMessage lastMessage = conversation.getLastMessage();
txt_content.setText(SmileUtils.getSmiledText(context, getMessageDigest(lastMessage, context)), BufferType.SPANNABLE);
txt_time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime())));
if (lastMessage.status == EMMessage.Status.SUCCESS) {
txt_state.setText("送达");
// txt_state.setBackgroundResource(R.drawable.btn_bg_orgen);
} else if (lastMessage.status == EMMessage.Status.FAIL) {
txt_state.setText("失败");
// txt_state.setBackgroundResource(R.drawable.btn_bg_red);
} else if (lastMessage.direct == EMMessage.Direct.RECEIVE) {
txt_state.setText("已读");
txt_state.setBackgroundResource(R.drawable.btn_bg_blue);
}
}
txt_del.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
deleteID = position;
Tipdialog = new WarnTipDialog((Activity) context, "您确定要删除该聊天吗?");
Tipdialog.setBtnOkLinstener(onclick);
Tipdialog.show();
}
});
}
return convertView;
}
Aggregations