com.easemob.chat.EMConversation Java Examples
The following examples show how to use
com.easemob.chat.EMConversation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { abortBroadcast(); String msgid = intent.getStringExtra("msgid"); String from = intent.getStringExtra("from"); EMConversation conversation = EMChatManager.getInstance() .getConversation(from); if (conversation != null) { // 把message设为已读 EMMessage msg = conversation.getMessage(msgid); if (msg != null) { msg.isAcked = true; } } adapter.notifyDataSetChanged(); }
Example #2
Source File: ChatAllHistoryActivity.java From school_shop with MIT License | 6 votes |
/** * 根据最后一条消息的时间排序 * * @param usernames */ private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) { Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() { @Override public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) { if (con1.first == con2.first) { return 0; } else if (con2.first > con1.first) { return 1; } else { return -1; } } }); }
Example #3
Source File: ChatAllHistoryActivity.java From school_shop with MIT License | 6 votes |
@Override public boolean onContextItemSelected(MenuItem item) { boolean handled = false; boolean deleteMessage = false; if (item.getItemId() == R.id.delete_message) { deleteMessage = true; handled = true; } else if (item.getItemId() == R.id.delete_conversation) { deleteMessage = false; handled = true; } EMConversation tobeDeleteCons = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position); // 删除此会话 EMChatManager.getInstance().deleteConversation(tobeDeleteCons.getUserName(), tobeDeleteCons.isGroup(), deleteMessage); InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(this); inviteMessgeDao.deleteMessage(tobeDeleteCons.getUserName()); adapter.remove(tobeDeleteCons); adapter.notifyDataSetChanged(); // 更新消息未读数 // updateUnreadLabel(); return handled ? true : super.onContextItemSelected(item); }
Example #4
Source File: FragmentCoversation.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
/** * 根据最后一条消息的时间排序 * * @param usernames */ private void sortConversationByLastChatTime( List<EMConversation> conversationList) { Collections.sort(conversationList, new Comparator<EMConversation>() { @Override public int compare(final EMConversation con1, final EMConversation con2) { EMMessage con2LastMessage = con2.getLastMessage(); EMMessage con1LastMessage = con1.getLastMessage(); if (con2LastMessage.getMsgTime() == con1LastMessage .getMsgTime()) { return 0; } else if (con2LastMessage.getMsgTime() > con1LastMessage .getMsgTime()) { return 1; } else { return -1; } } }); }
Example #5
Source File: ChatActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { abortBroadcast(); String msgid = intent.getStringExtra("msgid"); String from = intent.getStringExtra("from"); EMConversation conversation = EMChatManager.getInstance() .getConversation(from); if (conversation != null) { // 把message设为已读 EMMessage msg = conversation.getMessage(msgid); if (msg != null) { msg.isDelivered = true; } } adapter.notifyDataSetChanged(); }
Example #6
Source File: ChatListActivity.java From monolog-android with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat_list); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("私信"); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(true); registerEaseMobEventListener(); //easemob chat EaseUI.getInstance().pushActivity(this); conversationListFragment = new EaseConversationListFragment(); conversationListFragment.setConversationListItemClickListener(new EaseConversationListFragment.EaseConversationListItemClickListener() { @Override public void onListItemClicked(EMConversation conversation) { startActivity(new Intent(ChatListActivity.this, ChatActivity.class).putExtra(EaseConstant.EXTRA_USER_ID, conversation.getUserName())); } }); getSupportFragmentManager().beginTransaction().add(R.id.container, conversationListFragment).show(conversationListFragment).commit(); }
Example #7
Source File: EaseConversationList.java From monolog-android with MIT License | 6 votes |
/** * 根据最后一条消息的时间排序 * * @param usernames */ private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) { Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() { @Override public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) { if (con1.first == con2.first) { return 0; } else if (con2.first > con1.first) { return 1; } else { return -1; } } }); }
Example #8
Source File: EaseConversationListFragment.java From monolog-android with MIT License | 6 votes |
/** * 根据最后一条消息的时间排序 * */ private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) { Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() { @Override public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) { if (con1.first == con2.first) { return 0; } else if (con2.first > con1.first) { return 1; } else { return -1; } } }); }
Example #9
Source File: ConversationAdapter.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
@SuppressLint("SdCardPath") public ConversationAdapter(Context context, List<EMConversation> normal_list, List<EMConversation> top_list, Map<String, TopUser> topMap) { this.context = context; this.topMap = topMap; this.normal_list = normal_list; this.top_list = top_list; inflater = LayoutInflater.from(context); avatarLoader = new LoadUserAvatar(context, "/sdcard/fanxin/"); }
Example #10
Source File: EaseConversationAdapater.java From monolog-android with MIT License | 5 votes |
@Override public EMConversation getItem(int arg0) { if (arg0 < conversationList.size()) { return conversationList.get(arg0); } return null; }
Example #11
Source File: ChatAllHistoryActivity.java From school_shop with MIT License | 5 votes |
/** * 获取所有会话 * * @param context * @return + */ private List<EMConversation> loadConversationsWithRecentChat() { // 获取所有会话,包括陌生人 Hashtable<String, EMConversation> conversations = EMChatManager.getInstance().getAllConversations(); // 过滤掉messages size为0的conversation /** * 如果在排序过程中有新消息收到,lastMsgTime会发生变化 * 影响排序过程,Collection.sort会产生异常 * 保证Conversation在Sort过程中最后一条消息的时间不变 * 避免并发问题 */ List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>(); synchronized (conversations) { for (EMConversation conversation : conversations.values()) { if (conversation.getAllMessages().size() != 0) { sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation)); } } } try { // Internal is TimSort algorithm, has bug sortConversationByLastChatTime(sortList); } catch (Exception e) { e.printStackTrace(); } List<EMConversation> list = new ArrayList<EMConversation>(); for (Pair<Long, EMConversation> sortItem : sortList) { list.add(sortItem.second); } return list; }
Example #12
Source File: ChatAllHistoryAdapter.java From school_shop with MIT License | 5 votes |
@Override protected void publishResults(CharSequence constraint, FilterResults results) { conversationList.clear(); conversationList.addAll((List<EMConversation>) results.values); if (results.count > 0) { notiyfyByFilter = true; notifyDataSetChanged(); } else { notifyDataSetInvalidated(); } }
Example #13
Source File: ChatAllHistoryAdapter.java From school_shop with MIT License | 5 votes |
public ChatAllHistoryAdapter(Context context, int textViewResourceId, List<EMConversation> objects) { super(context, textViewResourceId, objects); this.conversationList = objects; copyConversationList = new ArrayList<EMConversation>(); copyConversationList.addAll(objects); inflater = LayoutInflater.from(context); }
Example #14
Source File: ConversationAdapter.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
@Override public EMConversation getItem(int position) { if (position < top_list.size()) { return top_list.get(position); } else { return normal_list.get(position - top_list.size()); } }
Example #15
Source File: MainActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { abortBroadcast(); String msgid = intent.getStringExtra("msgid"); String from = intent.getStringExtra("from"); EMConversation conversation = EMChatManager.getInstance() .getConversation(from); if (conversation != null) { // 把message设为已读 EMMessage msg = conversation.getMessage(msgid); if (msg != null) { // 2014-11-5 修复在某些机器上,在聊天页面对方发送已读回执时不立即显示已读的bug if (ChatActivity.activityInstance != null) { if (msg.getChatType() == ChatType.Chat) { if (from.equals(ChatActivity.activityInstance .getToChatUsername())) return; } } msg.isAcked = true; } } }
Example #16
Source File: EaseConversationAdapater.java From monolog-android with MIT License | 5 votes |
@Override protected void publishResults(CharSequence constraint, FilterResults results) { conversationList.clear(); conversationList.addAll((List<EMConversation>) results.values); if (results.count > 0) { notiyfyByFilter = true; notifyDataSetChanged(); } else { notifyDataSetInvalidated(); } }
Example #17
Source File: EaseConversationAdapater.java From monolog-android with MIT License | 5 votes |
public EaseConversationAdapater(Context context, int resource, List<EMConversation> objects) { super(context, resource, objects); conversationList = objects; copyConversationList = new ArrayList<EMConversation>(); copyConversationList.addAll(objects); }
Example #18
Source File: EaseConversationListFragment.java From monolog-android with MIT License | 5 votes |
@Override protected void setUpView() { conversationList.addAll(loadConversationList()); conversationListView.init(conversationList); if(listItemClickListener != null){ conversationListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMConversation conversation = conversationListView.getItem(position); listItemClickListener.onListItemClicked(conversation); } }); } EMChatManager.getInstance().addConnectionListener(connectionListener); conversationListView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { hideSoftKeyboard(); return false; } }); }
Example #19
Source File: EaseConversationListFragment.java From monolog-android with MIT License | 5 votes |
/** * 获取会话列表 * * @return + */ protected List<EMConversation> loadConversationList(){ // 获取所有会话,包括陌生人 Hashtable<String, EMConversation> conversations = EMChatManager.getInstance().getAllConversations(); // 过滤掉messages size为0的conversation /** * 如果在排序过程中有新消息收到,lastMsgTime会发生变化 * 影响排序过程,Collection.sort会产生异常 * 保证Conversation在Sort过程中最后一条消息的时间不变 * 避免并发问题 */ List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>(); synchronized (conversations) { for (EMConversation conversation : conversations.values()) { if (conversation.getAllMessages().size() != 0) { //if(conversation.getType() != EMConversationType.ChatRoom){ sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation)); //} } } } try { // Internal is TimSort algorithm, has bug sortConversationByLastChatTime(sortList); } catch (Exception e) { e.printStackTrace(); } List<EMConversation> list = new ArrayList<EMConversation>(); for (Pair<Long, EMConversation> sortItem : sortList) { list.add(sortItem.second); } return list; }
Example #20
Source File: EaseConversationList.java From monolog-android with MIT License | 5 votes |
/** * 获取所有会话 * * @param context * @return + */ private List<EMConversation> loadConversationsWithRecentChat() { // 获取所有会话,包括陌生人 Map<String, EMConversation> conversations = EMChatManager.getInstance().getAllConversations(); // 过滤掉messages size为0的conversation /** * 如果在排序过程中有新消息收到,lastMsgTime会发生变化 * 影响排序过程,Collection.sort会产生异常 * 保证Conversation在Sort过程中最后一条消息的时间不变 * 避免并发问题 */ List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>(); synchronized (conversations) { for (EMConversation conversation : conversations.values()) { if (conversation.getAllMessages().size() != 0) { sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation)); } } } try { // Internal is TimSort algorithm, has bug sortConversationByLastChatTime(sortList); } catch (Exception e) { e.printStackTrace(); } List<EMConversation> list = new ArrayList<EMConversation>(); for (Pair<Long, EMConversation> sortItem : sortList) { list.add(sortItem.second); } return list; }
Example #21
Source File: EaseConversationList.java From monolog-android with MIT License | 5 votes |
public void init(List<EMConversation> conversationList){ this.conversationList = conversationList; adapter = new EaseConversationAdapater(context, 0, conversationList); adapter.setPrimaryColor(primaryColor); adapter.setPrimarySize(primarySize); adapter.setSecondaryColor(secondaryColor); adapter.setSecondarySize(secondarySize); adapter.setTimeColor(timeColor); adapter.setTimeSize(timeSize); setAdapter(adapter); }
Example #22
Source File: EaseConversationList.java From monolog-android with MIT License | 4 votes |
public EMConversation getItem(int position) { return (EMConversation)adapter.getItem(position); }
Example #23
Source File: FragmentCoversation.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
/** * 获取所有会话 * * @param context * @return + */ private List<EMConversation> loadConversationsWithRecentChat() { // 获取所有会话,包括陌生人 Hashtable<String, EMConversation> conversations = EMChatManager .getInstance().getAllConversations(); List<EMConversation> list = new ArrayList<EMConversation>(); List<EMConversation> topList1 = new ArrayList<EMConversation>(); // 置顶列表再刷新一次 // 过滤掉messages seize为0的conversation for (EMConversation conversation : conversations.values()) { if (conversation.getAllMessages().size() != 0) { // 不在置顶列表里面 if (!topMap.containsKey(conversation.getUserName())) { list.add(conversation); } else { // 在置顶列表里面 topList1.add(conversation); } // // for(EMMessage msg:conversation.getAllMessages()){ // if(msg.getFrom().equals("admin")){ // try { // Log.e("type--->>",msg.getStringAttribute("type")); // Log.e("groupid--->>",msg.getStringAttribute("groupid")); // } catch (EaseMobException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } // // } } } top_list.clear(); top_list.addAll(topList1); // 排序 sortConversationByLastChatTime(list); sortConversationByLastChatTime(top_list); return list; }
Example #24
Source File: EaseConversationAdapater.java From monolog-android with MIT License | 4 votes |
public ConversationFilter(List<EMConversation> mList) { mOriginalValues = mList; }
Example #25
Source File: ChatAllHistoryAdapter.java From school_shop with MIT License | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.row_chat_history, parent, false); } ViewHolder holder = (ViewHolder) convertView.getTag(); if (holder == null) { holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.name); holder.unreadLabel = (TextView) convertView.findViewById(R.id.unread_msg_number); holder.message = (TextView) convertView.findViewById(R.id.message); holder.time = (TextView) convertView.findViewById(R.id.time); holder.avatar = (CircleImageView) convertView.findViewById(R.id.avatar); holder.msgState = convertView.findViewById(R.id.msg_state); holder.list_item_layout = (RelativeLayout) convertView.findViewById(R.id.list_item_layout); convertView.setTag(holder); } if (position % 2 == 0) { holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem); } else { holder.list_item_layout.setBackgroundResource(R.drawable.mm_listitem_grey); } // 获取与此用户/群组的会话 EMConversation conversation = getItem(position); // 获取用户username或者群组groupid String username = conversation.getUserName(); Log.i("tag", "username=="+username); List<EMGroup> groups = EMGroupManager.getInstance().getAllGroups(); EMContact contact = null; boolean isGroup = false; for (EMGroup group : groups) { if (group.getGroupId().equals(username)) { isGroup = true; contact = group; break; } } if (isGroup) { // 群聊消息,显示群聊头像 holder.avatar.setImageResource(R.drawable.group_icon); holder.name.setText(contact.getNick() != null ? contact.getNick() : username); } else { // UserUtils.setUserAvatar(getContext(), username, holder.avatar); // if (username.equals(Constants.GROUP_USERNAME)) { // holder.name.setText("群聊"); // // } else if (username.equals(Constants.NEW_FRIENDS_USERNAME)) { // holder.name.setText("申请与通知"); // } // holder.name.setText(username); } if (conversation.getUnreadMsgCount() > 0) { // 显示与此用户的消息未读数 holder.unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount())); holder.unreadLabel.setVisibility(View.VISIBLE); } else { holder.unreadLabel.setVisibility(View.INVISIBLE); } if (conversation.getMsgCount() != 0) { // 把最后一条消息的内容作为item的message内容 EMMessage lastMessage = conversation.getLastMessage(); holder.message.setText(SmileUtils.getSmiledText(getContext(), getMessageDigest(lastMessage, (this.getContext()))), BufferType.SPANNABLE); holder.time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime()))); if (lastMessage.direct == EMMessage.Direct.SEND && lastMessage.status == EMMessage.Status.FAIL) { holder.msgState.setVisibility(View.VISIBLE); } else { holder.msgState.setVisibility(View.GONE); } } return convertView; }
Example #26
Source File: ChatAllHistoryAdapter.java From school_shop with MIT License | 4 votes |
public ConversationFilter(List<EMConversation> mList) { mOriginalValues = mList; }
Example #27
Source File: EaseConversationAdapater.java From monolog-android with MIT License | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.ease_row_chat_history, parent, false); } ViewHolder holder = (ViewHolder) convertView.getTag(); if (holder == null) { holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.name); holder.unreadLabel = (TextView) convertView.findViewById(R.id.unread_msg_number); holder.message = (TextView) convertView.findViewById(R.id.message); holder.time = (TextView) convertView.findViewById(R.id.time); holder.avatar = (ImageView) convertView.findViewById(R.id.avatar); holder.msgState = convertView.findViewById(R.id.msg_state); holder.list_itease_layout = (RelativeLayout) convertView.findViewById(R.id.list_itease_layout); convertView.setTag(holder); } holder.list_itease_layout.setBackgroundResource(R.drawable.ease_mm_listitem); // 获取与此用户/群组的会话 EMConversation conversation = getItem(position); // 获取用户username或者群组groupid String username = conversation.getUserName(); if (conversation.getType() == EMConversationType.GroupChat) { // 群聊消息,显示群聊头像 holder.avatar.setImageResource(R.drawable.ease_group_icon); EMGroup group = EMGroupManager.getInstance().getGroup(username); holder.name.setText(group != null ? group.getGroupName() : username); } else if(conversation.getType() == EMConversationType.ChatRoom){ holder.avatar.setImageResource(R.drawable.ease_group_icon); EMChatRoom room = EMChatManager.getInstance().getChatRoom(username); holder.name.setText(room != null && !TextUtils.isEmpty(room.getName()) ? room.getName() : username); }else { EaseUserUtils.setUserAvatar(getContext(), username, holder.avatar); EaseUserUtils.setUserNick(username, holder.name); } if (conversation.getUnreadMsgCount() > 0) { // 显示与此用户的消息未读数 holder.unreadLabel.setText(String.valueOf(conversation.getUnreadMsgCount())); holder.unreadLabel.setVisibility(View.VISIBLE); } else { holder.unreadLabel.setVisibility(View.INVISIBLE); } if (conversation.getMsgCount() != 0) { // 把最后一条消息的内容作为item的message内容 EMMessage lastMessage = conversation.getLastMessage(); holder.message.setText(EaseSmileUtils.getSmiledText(getContext(), EaseCommonUtils.getMessageDigest(lastMessage, (this.getContext()))), BufferType.SPANNABLE); holder.time.setText(DateUtils.getTimestampString(new Date(lastMessage.getMsgTime()))); if (lastMessage.direct == EMMessage.Direct.SEND && lastMessage.status == EMMessage.Status.FAIL) { holder.msgState.setVisibility(View.VISIBLE); } else { holder.msgState.setVisibility(View.GONE); } } //设置自定义属性 holder.name.setTextColor(primaryColor); holder.message.setTextColor(secondaryColor); holder.time.setTextColor(timeColor); if(primarySize != 0) holder.name.setTextSize(TypedValue.COMPLEX_UNIT_PX, primarySize); if(secondarySize != 0) holder.message.setTextSize(TypedValue.COMPLEX_UNIT_PX, secondarySize); if(timeSize != 0) holder.time.setTextSize(TypedValue.COMPLEX_UNIT_PX, timeSize); return convertView; }
Example #28
Source File: EaseConversationListFragment.java From monolog-android with MIT License | 2 votes |
/** * 会话listview item点击事件 * @param conversation 被点击item所对应的会话 */ void onListItemClicked(EMConversation conversation);