Search in sources :

Example 1 with ChatMessage

use of com.rideread.rideread.bean.ChatMessage in project ride-read-android by Ride-Read.

the class ChatMessageAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ChatMessage msg = (ChatMessage) getItem(position);
    ViewHolder viewHolder = null;
    if (convertView == null) {
        viewHolder = new ViewHolder();
        if (getItemViewType(position) == 0) {
            convertView = inflater.inflate(R.layout.im_chat_to_listitem, null);
        } else {
            convertView = inflater.inflate(R.layout.im_chat_from_listitem, null);
        }
        viewHolder.chatPortait = (ImageView) convertView.findViewById(R.id.im_chat_portait);
        viewHolder.chatContent = (TextView) convertView.findViewById(R.id.im_chat_content);
        viewHolder.chatTime = (TextView) convertView.findViewById(R.id.im_chat_time);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    if (!TextUtils.isEmpty(msg.getPubDate())) {
        viewHolder.chatTime.setText(msg.getPubDate());
    }
    if (!TextUtils.isEmpty(msg.getContent())) {
        viewHolder.chatContent.setText(msg.getContent());
    }
    viewHolder.chatPortait.setImageResource(msg.getPortait());
    return convertView;
}
Also used : ChatMessage(com.rideread.rideread.bean.ChatMessage)

Example 2 with ChatMessage

use of com.rideread.rideread.bean.ChatMessage in project ride-read-android by Ride-Read.

the class ChatActivity method sendTextMessage.

private void sendTextMessage(String text) {
    final AVIMTextMessage message = new AVIMTextMessage();
    message.setText(text);
    datas.add(new ChatMessage(1, R.mipmap.me, null, text, null));
    adapter.notifyDataSetChanged();
    chatlist.smoothScrollToPosition(adapter.getCount() - 1);
    editor.setText("");
    imConversation.sendMessage(message, new AVIMConversationCallback() {

        @Override
        public void done(AVIMException e) {
            if (filterException(e)) {
                Log.e("信息发送", "信息发送成功");
            } else {
                Log.e("信息发送", "信息发送失败");
            }
        }
    });
}
Also used : AVIMConversationCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCallback) AVIMException(com.avos.avoscloud.im.v2.AVIMException) ChatMessage(com.rideread.rideread.bean.ChatMessage) AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage)

Example 3 with ChatMessage

use of com.rideread.rideread.bean.ChatMessage in project ride-read-android by Ride-Read.

the class ChatActivity method onEvent.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(ImTypeMessageEvent event) {
    if (null != imConversation && null != event && imConversation.getConversationId().equals(event.conversation.getConversationId())) {
        if (event.message instanceof AVIMTextMessage) {
            String msg = ((AVIMTextMessage) event.message).getText();
            ChatMessage chatMessage = new ChatMessage(0, R.mipmap.me, menberId, msg, null);
            adapter.addMessage(chatMessage);
            adapter.notifyDataSetChanged();
            chatlist.smoothScrollToPosition(adapter.getCount() - 1);
        }
    }
}
Also used : ChatMessage(com.rideread.rideread.bean.ChatMessage) AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 4 with ChatMessage

use of com.rideread.rideread.bean.ChatMessage in project ride-read-android by Ride-Read.

the class ChatActivity method initDatas.

private void initDatas() {
    if (mDaoSession == null) {
        mDaoSession = RideReadDBHelper.getInstance().getmDaoSession();
    }
    menberId = getIntent().getStringExtra("menberid");
    //模拟本地数据,此处应该是查询本地聊天记录.
    //datas=new ArrayList<ChatMessage>();
    mDaoSession.insert(new ChatMessage(1, R.mipmap.me, menberId, "消息内容", null));
    mDaoSession.insert(new ChatMessage(0, R.mipmap.me, "me", "消息内容消息内容消息内容", null));
    //        datas.add();
    //        datas.add();
    //        datas.add(new ChatMessage(0,R.mipmap.me,"me","消息内容消息内容消息内容消息内容消息内容",null));
    datas = mDaoSession.loadAll(ChatMessage.class);
    initView(datas);
}
Also used : ChatMessage(com.rideread.rideread.bean.ChatMessage)

Aggregations

ChatMessage (com.rideread.rideread.bean.ChatMessage)4 AVIMTextMessage (com.avos.avoscloud.im.v2.messages.AVIMTextMessage)2 AVIMException (com.avos.avoscloud.im.v2.AVIMException)1 AVIMConversationCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationCallback)1 Subscribe (org.greenrobot.eventbus.Subscribe)1