最后一段,一些注意事项
写到这基本功能已经实现了,但是还是有些细节问题要处理
1.输入框调起成员列表,在聊天页面写入这个方法(我的聊天页面是ChatActivity)
InputProvider.MainInputProvider provider = RongContext.getInstance().getPrimaryInputProvider();
if (provider instanceof RongTextInputProvider) {
RongTextInputProvider textInputProvider = (RongTextInputProvider) provider;
textInputProvider.setEditTextContent("");
textInputProvider.setEditTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(count==0){
//键盘回删操作,不调起列表
return;
}
if (mConversationType.equals(Conversation.ConversationType.GROUP)) {
if (s.length() > 0) {
String str = s.toString().substring(s.toString().length() - 1, s.toString().length());
if (str.equals("@")) {
Intent intent = new Intent(ChatActivity.this, ChatGroupUserListActivity.class);
intent.putExtra(ChatGroupUserListActivity.IS_AT, true);
intent.putExtra(ChatGroupUserListActivity.ARGUMENT_GID, mUserId);
startActivityForResult(intent, 29);
mEditText = s.toString();
}
}
}
}
@Override
public void afterTextChanged(Editable s) {;
}
});
}
2.如果当前app停留的页面就是这个会话页面,则不用在列表中显示有人@了我
,具体实现我是在每次进入群聊就保存当前会话的id,关闭聊天页面时,remove掉。
3.如果聊天草稿最后一个字符是@
,则进入聊天页面会默认调起成员列表,这样体验不好,想解决这个问题,最后”曲线救国“”了。
具体方法:如果草稿最后一个字符是@则将这个字符删,循环处理,直至最后一个字符不是@符号.
SaveDraftRunnable(Conversation conversation, String content) {
this.conversation = conversation;
if(content!=null&&content.toString().length()>0){
int size=content.length();
for(int i=0;i<size;i++){
if(content.endsWith("@")){
content = content.toString().substring(0,content.toString().length()-1);
}else{
break;
}
}
}
this.content = content;
}
为了解决这个问题,还重写了融云的TextInputProvider,只是修改了上面那一段。