Search in sources :

Example 1 with AVIMException

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

the class ChatActivity method getConservation.

public void getConservation(final String menberId) {
    final AVIMClient client = AVImClientManager.getInstance().getClient();
    AVIMConversationQuery conversationQuery = client.getQuery();
    conversationQuery.withMembers(Arrays.asList(menberId), true);
    conversationQuery.whereEqualTo("customConversationType", 1);
    conversationQuery.findInBackground(new AVIMConversationQueryCallback() {

        @Override
        public void done(List<AVIMConversation> list, AVIMException e) {
            if (filterException(e)) {
                //注意:此处仍有漏洞,如果获取了多个 conversation,默认取第一个
                if (null != list && list.size() > 0) {
                    imConversation = list.get(0);
                } else {
                    HashMap<String, Object> attributes = new HashMap<String, Object>();
                    attributes.put("customConversationType", 1);
                    client.createConversation(Arrays.asList(menberId), null, attributes, false, new AVIMConversationCreatedCallback() {

                        @Override
                        public void done(AVIMConversation avimConversation, AVIMException e) {
                            imConversation = avimConversation;
                        }
                    });
                }
            }
        }
    });
}
Also used : AVIMConversationCreatedCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback) AVIMConversation(com.avos.avoscloud.im.v2.AVIMConversation) AVIMClient(com.avos.avoscloud.im.v2.AVIMClient) AVIMException(com.avos.avoscloud.im.v2.AVIMException) HashMap(java.util.HashMap) AVIMConversationQueryCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback) AVIMConversationQuery(com.avos.avoscloud.im.v2.AVIMConversationQuery)

Example 2 with AVIMException

use of com.avos.avoscloud.im.v2.AVIMException 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 AVIMException

use of com.avos.avoscloud.im.v2.AVIMException 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 4 with AVIMException

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

the class ChatSingleActivity method sendMsg.

private void sendMsg() {
    String msg = mEdtChatInput.getText().toString();
    AVIMTextMessage message = new AVIMTextMessage();
    if (!TextUtils.isEmpty(msg)) {
        message.setText(msg);
        mMsgAdapter.addMessage(message);
        mMsgAdapter.notifyDataSetChanged();
        scrollToBottom();
        mEdtChatInput.setText("");
        mImConversation.sendMessage(message, new AVIMConversationCallback() {

            @Override
            public void done(AVIMException e) {
                mMsgAdapter.notifyDataSetChanged();
                MsgUtils.addMsgInfo(mUser, msg, System.currentTimeMillis());
            }
        });
    }
}
Also used : AVIMConversationCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCallback) AVIMException(com.avos.avoscloud.im.v2.AVIMException) AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage)

Example 5 with AVIMException

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

the class ChatSingleActivity method getConversation.

private void getConversation(final String memberId) {
    final AVIMClient client = AVImClientManager.getInstance().getClient();
    if (null == client)
        return;
    AVIMConversationQuery conversationQuery = client.getQuery();
    conversationQuery.withMembers(Arrays.asList(memberId), true);
    conversationQuery.whereEqualTo("customConversationType", 1);
    conversationQuery.findInBackground(new AVIMConversationQueryCallback() {

        @Override
        public void done(List<AVIMConversation> list, AVIMException e) {
            if (filterException(e)) {
                //注意:此处仍有漏洞,如果获取了多个 conversation,默认取第一个
                if (null != list && list.size() > 0) {
                    setConversation(list.get(0));
                } else {
                    HashMap<String, Object> attributes = new HashMap<String, Object>();
                    attributes.put("customConversationType", 1);
                    client.createConversation(Arrays.asList(memberId), null, attributes, false, new AVIMConversationCreatedCallback() {

                        @Override
                        public void done(AVIMConversation avimConversation, AVIMException e) {
                            setConversation(avimConversation);
                        }
                    });
                }
            }
        }
    });
}
Also used : AVIMConversationCreatedCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback) AVIMConversation(com.avos.avoscloud.im.v2.AVIMConversation) AVIMClient(com.avos.avoscloud.im.v2.AVIMClient) AVIMException(com.avos.avoscloud.im.v2.AVIMException) HashMap(java.util.HashMap) AVIMConversationQueryCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback) AVIMConversationQuery(com.avos.avoscloud.im.v2.AVIMConversationQuery)

Aggregations

AVIMException (com.avos.avoscloud.im.v2.AVIMException)6 AVIMConversationCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationCallback)4 AVIMClient (com.avos.avoscloud.im.v2.AVIMClient)3 AVIMConversation (com.avos.avoscloud.im.v2.AVIMConversation)3 AVIMConversationQuery (com.avos.avoscloud.im.v2.AVIMConversationQuery)3 AVIMConversationCreatedCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback)3 AVIMConversationQueryCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback)3 AVIMTextMessage (com.avos.avoscloud.im.v2.messages.AVIMTextMessage)3 HashMap (java.util.HashMap)3 Subscribe (org.greenrobot.eventbus.Subscribe)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 AVIMMessage (com.avos.avoscloud.im.v2.AVIMMessage)1 AVIMMessagesQueryCallback (com.avos.avoscloud.im.v2.callback.AVIMMessagesQueryCallback)1