Search in sources :

Example 1 with AVIMMessage

use of com.avos.avoscloud.im.v2.AVIMMessage in project ride-read-android by Ride-Read.

the class LeftMsgHolder method bindData.

@Override
public void bindData(Object o) {
    AVIMMessage message = (AVIMMessage) o;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
    String time = dateFormat.format(message.getTimestamp());
    String content = getContext().getString(R.string.unsupport_message_type);
    if (message instanceof AVIMTextMessage) {
        content = ((AVIMTextMessage) message).getText();
    }
    mTvChatTxtLeft.setText(content);
    mTvChatTime.setText(time);
//        nameView.setText(message.getFrom());
}
Also used : AVIMMessage(com.avos.avoscloud.im.v2.AVIMMessage) AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with AVIMMessage

use of com.avos.avoscloud.im.v2.AVIMMessage in project ride-read-android by Ride-Read.

the class ChatSingleActivity method initView.

@Override
public void initView() {
    mUser = (UserBaseInfo) getIntent().getSerializableExtra(CHAT_USER);
    mUserName = getIntent().getStringExtra(CHAT_USER_NAME);
    if (TextUtils.isEmpty(mUserName))
        mUserName = "消息";
    new TitleBuilder(this).setTitleText(mUserName).IsBack(true).setLeftOnClickListener(v -> finish()).build();
    mSwipeRefreshLayout.setEnabled(false);
    layoutManager = new LinearLayoutManager(this);
    mRecycleView.setLayoutManager(layoutManager);
    mMsgAdapter = new ChatMsgAdapter();
    mRecycleView.setAdapter(mMsgAdapter);
    getConversation(mUser.getUid() + "");
    mSwipeRefreshLayout.setOnRefreshListener(() -> {
        AVIMMessage message = mMsgAdapter.getFirstMessage();
        if (null != mImConversation) {
            mImConversation.queryMessages(message.getMessageId(), message.getTimestamp(), 20, new AVIMMessagesQueryCallback() {

                @Override
                public void done(List<AVIMMessage> list, AVIMException e) {
                    mSwipeRefreshLayout.setRefreshing(false);
                    if (filterException(e)) {
                        if (null != list && list.size() > 0) {
                            mMsgAdapter.addMessageList(list);
                            mMsgAdapter.notifyDataSetChanged();
                            layoutManager.scrollToPositionWithOffset(list.size() - 1, 0);
                        }
                    }
                }
            });
        } else {
            mSwipeRefreshLayout.setRefreshing(false);
        }
    });
}
Also used : UserUtils(com.rideread.rideread.common.util.UserUtils) Arrays(java.util.Arrays) TitleBuilder(com.rideread.rideread.common.util.TitleBuilder) HashMap(java.util.HashMap) R(com.rideread.rideread.R) OnClick(butterknife.OnClick) BindView(butterknife.BindView) AVIMConversationCreatedCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback) UserBaseInfo(com.rideread.rideread.data.result.UserBaseInfo) AVIMMessage(com.avos.avoscloud.im.v2.AVIMMessage) AVIMConversationCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCallback) AVIMConversation(com.avos.avoscloud.im.v2.AVIMConversation) AVImClientManager(com.rideread.rideread.function.net.im.AVImClientManager) View(android.view.View) AVIMClient(com.avos.avoscloud.im.v2.AVIMClient) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AVIMMessagesQueryCallback(com.avos.avoscloud.im.v2.callback.AVIMMessagesQueryCallback) AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage) ChatMsgAdapter(com.rideread.rideread.common.adapter.ChatMsgAdapter) AVIMConversationQuery(com.avos.avoscloud.im.v2.AVIMConversationQuery) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) BaseActivity(com.rideread.rideread.common.base.BaseActivity) NotificationUtils(com.rideread.rideread.function.net.im.NotificationUtils) AVIMException(com.avos.avoscloud.im.v2.AVIMException) RecyclerView(android.support.v7.widget.RecyclerView) ImTypeMsgEvent(com.rideread.rideread.common.event.ImTypeMsgEvent) List(java.util.List) Subscribe(org.greenrobot.eventbus.Subscribe) MAIN(org.greenrobot.eventbus.ThreadMode.MAIN) AVIMConversationQueryCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback) ImTypeMsgResendEvent(com.rideread.rideread.common.event.ImTypeMsgResendEvent) MsgUtils(com.rideread.rideread.common.util.MsgUtils) EditText(android.widget.EditText) AVIMMessagesQueryCallback(com.avos.avoscloud.im.v2.callback.AVIMMessagesQueryCallback) AVIMMessage(com.avos.avoscloud.im.v2.AVIMMessage) TitleBuilder(com.rideread.rideread.common.util.TitleBuilder) AVIMException(com.avos.avoscloud.im.v2.AVIMException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ChatMsgAdapter(com.rideread.rideread.common.adapter.ChatMsgAdapter)

Example 3 with AVIMMessage

use of com.avos.avoscloud.im.v2.AVIMMessage in project ride-read-android by Ride-Read.

the class RightMsgHolder method bindData.

@Override
public void bindData(Object msg) {
    message = (AVIMMessage) msg;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    String time = dateFormat.format(message.getTimestamp());
    String content = getContext().getString(R.string.unsupport_message_type);
    ;
    if (message instanceof AVIMTextMessage) {
        content = ((AVIMTextMessage) message).getText();
    }
    mTvChatTxtRight.setText(content);
    mTvChatTime.setText(time);
    if (AVIMMessage.AVIMMessageStatus.AVIMMessageStatusFailed == message.getMessageStatus()) {
        mImgChatStatusRight.setVisibility(View.VISIBLE);
        mPbChatProgressbarRight.setVisibility(View.GONE);
        mFlChatStatusRight.setVisibility(View.VISIBLE);
    } else if (AVIMMessage.AVIMMessageStatus.AVIMMessageStatusSending == message.getMessageStatus()) {
        mImgChatStatusRight.setVisibility(View.GONE);
        mPbChatProgressbarRight.setVisibility(View.VISIBLE);
        mFlChatStatusRight.setVisibility(View.VISIBLE);
    } else {
        mFlChatStatusRight.setVisibility(View.GONE);
    }
}
Also used : AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

AVIMTextMessage (com.avos.avoscloud.im.v2.messages.AVIMTextMessage)3 AVIMMessage (com.avos.avoscloud.im.v2.AVIMMessage)2 SimpleDateFormat (java.text.SimpleDateFormat)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 TextUtils (android.text.TextUtils)1 View (android.view.View)1 EditText (android.widget.EditText)1 BindView (butterknife.BindView)1 OnClick (butterknife.OnClick)1 AVIMClient (com.avos.avoscloud.im.v2.AVIMClient)1 AVIMConversation (com.avos.avoscloud.im.v2.AVIMConversation)1 AVIMConversationQuery (com.avos.avoscloud.im.v2.AVIMConversationQuery)1 AVIMException (com.avos.avoscloud.im.v2.AVIMException)1 AVIMConversationCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationCallback)1 AVIMConversationCreatedCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback)1 AVIMConversationQueryCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback)1 AVIMMessagesQueryCallback (com.avos.avoscloud.im.v2.callback.AVIMMessagesQueryCallback)1 R (com.rideread.rideread.R)1