private void initData() { Intent intent = mContext.getIntent(); mTargetID = intent.getStringExtra("targetID"); Log.i("ChatController", "mTargetID " + mTargetID); mGroupID = intent.getLongExtra("groupID", 0); mIsGroup = intent.getBooleanExtra("isGroup", false); boolean fromGroup = intent.getBooleanExtra("fromGroup", false); // 如果是群组,特别处理 if (mIsGroup) { Log.i("Tag", "mGroupID is " + mGroupID); // 判断是否从创建群组跳转过来 if (fromGroup) { String groupName = intent.getStringExtra("groupName"); mChatView.setChatTitle(groupName); mConv = JMessageClient.getGroupConversation(mGroupID); } else { if (mTargetID != null) mGroupID = Long.parseLong(mTargetID); mConv = JMessageClient.getGroupConversation(mGroupID); // 判断自己如果不在群聊中,隐藏群聊详情按钮 JMessageClient.getGroupMembers( mGroupID, new GetGroupMembersCallback(false) { @Override public void gotResult( final int status, final String desc, final List<String> memberList) { mContext.runOnUiThread( new Runnable() { @Override public void run() { if (status == 0) { // 群主解散后,返回memberList为空 if (memberList.isEmpty()) { mChatView.dismissRightBtn(); // 判断自己如果不在memberList中,则隐藏聊天详情按钮 } else if (!memberList.contains(JMessageClient.getMyInfo().getUserName())) mChatView.dismissRightBtn(); else mChatView.showRightBtn(); } else { if (memberList.isEmpty()) { mChatView.dismissRightBtn(); } HandleResponseCode.onHandle(mContext, status); } } }); } }); } // 聊天信息标志改变 mChatView.setGroupIcon(); } else { // 用targetID得到会话 Log.i("Tag", "targetID is " + mTargetID); mConv = JMessageClient.getSingleConversation(mTargetID); } // 如果之前沒有会话记录并且是群聊 if (mConv == null && mIsGroup) { mConv = Conversation.createConversation(ConversationType.group, mGroupID); Log.i("ChatController", "create group success"); // 是单聊 } else if (mConv == null && !mIsGroup) { mConv = Conversation.createConversation(ConversationType.single, mTargetID); } if (mConv != null) { mChatView.setChatTitle(mConv.getDisplayName()); mConv.resetUnreadCount(); } mChatAdapter = new MsgListAdapter(mContext, mIsGroup, mTargetID, mGroupID); mChatView.setChatListAdapter(mChatAdapter); // 滑动到底部 mChatView.setToBottom(); }
public void refresh() { mChatView.setChatTitle(mConv.getDisplayName()); mChatAdapter.refresh(); }