@Override
 public int getItemViewType(int position) {
   EMMessage message = mConversation.getAllMessages().get(position);
   MessageViewType type = MessageViewType.parse(message);
   if (type != null) {
     return type.ordinal();
   }
   return 0;
 }
Exemplo n.º 2
0
 protected void onConversationInit() {
   conversation =
       EMClient.getInstance()
           .chatManager()
           .getConversation(toChatUsername, EaseCommonUtils.getConversationType(chatType), true);
   conversation.markAllMessagesAsRead();
   // the number of messages loaded into conversation is getChatOptions().getNumberOfMessagesLoaded
   // you can change this number
   final List<EMMessage> msgs = conversation.getAllMessages();
   int msgCount = msgs != null ? msgs.size() : 0;
   if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
     String msgId = null;
     if (msgs != null && msgs.size() > 0) {
       msgId = msgs.get(0).getMsgId();
     }
     conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
   }
 }
  protected void onConversationInit() {
    // 获取当前conversation对象

    conversation =
        EMClient.getInstance()
            .chatManager()
            .getConversation(toChatUsername, EaseCommonUtils.getConversationType(chatType), true);
    // 把此会话的未读数置为0
    conversation.markAllMessagesAsRead();
    // 初始化db时,每个conversation加载数目是getChatOptions().getNumberOfMessagesLoaded
    // 这个数目如果比用户期望进入会话界面时显示的个数不一样,就多加载一些
    final List<EMMessage> msgs = conversation.getAllMessages();
    int msgCount = msgs != null ? msgs.size() : 0;
    if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
      String msgId = null;
      if (msgs != null && msgs.size() > 0) {
        msgId = msgs.get(0).getMsgId();
      }
      conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
    }
  }
 @Override
 public Object getItem(int position) {
   return mConversation.getAllMessages().get(position);
 }
 @Override
 public int getCount() {
   return mConversation.getAllMessages().size();
 }
 /**
  * 获取所有消息
  *
  * @return 所有消息
  */
 public List<EMMessage> getAllMessages() {
   return mConversation.getAllMessages();
 }