update消息页面接入融云搜索历史记录

This commit is contained in:
z583819556 2024-03-07 16:30:39 +08:00
parent a22e600b52
commit e2e7ce8183
3 changed files with 46 additions and 27 deletions

View File

@ -51,7 +51,7 @@ public class MainConversationListAdapter extends ConversationListAdapter {
String objectName = mDataList.get(position).mCore.getObjectName(); String objectName = mDataList.get(position).mCore.getObjectName();
if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_USER")) { if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_USER")) {
type = TYPE_SEARCH_USER; type = TYPE_SEARCH_USER;
} else if (!StringUtil.isEmpty(objectName) && objectName.equals("SEARCH_CHAT")) { } else if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_CHAT")) {
type = TYPE_SEARCH_CHAT; type = TYPE_SEARCH_CHAT;
} else if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_TITLE")) { } else if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_TITLE")) {
type = TYPE_SEARCH_TITLE; type = TYPE_SEARCH_TITLE;
@ -103,7 +103,10 @@ public class MainConversationListAdapter extends ConversationListAdapter {
private void bindChat(ViewHolder holder, int position) { private void bindChat(ViewHolder holder, int position) {
ImgLoader.display(holder.getContext(), mDataList.get(position).mCore.getPortraitUrl(), holder.getView(R.id.rc_conversation_portrait)); ImgLoader.display(holder.getContext(), mDataList.get(position).mCore.getPortraitUrl(), holder.getView(R.id.rc_conversation_portrait));
holder.setText(R.id.rc_conversation_title, mDataList.get(position).mCore.getConversationTitle()); holder.setText(R.id.rc_conversation_title, mDataList.get(position).mCore.getConversationTitle());
Spanned spanned = Html.fromHtml(WordUtil.getNewString(R.string.activity_msg_list_include) + "<font color='#FF4874'>" + mDataList.get(position).mConversationContent + "</font>"); String title = mDataList.get(position).mConversationContent.toString();
String key = mDataList.get(position).mCore.getObjectName().replace("SEARCH_CHAT", "");
title = title.replace(key, "<font color='#FF4874'>" + key + "</font>");
Spanned spanned = Html.fromHtml(WordUtil.getNewString(R.string.activity_msg_list_include) +title);
((TextView) holder.getView(R.id.rc_conversation_content)).setText(spanned); ((TextView) holder.getView(R.id.rc_conversation_content)).setText(spanned);
int type = mDataList.get(position).mCore.getMentionedCount(); int type = mDataList.get(position).mCore.getMentionedCount();
holder.getView(R.id.itemDecorationTop).setVisibility(View.GONE); holder.getView(R.id.itemDecorationTop).setVisibility(View.GONE);

View File

@ -23,7 +23,9 @@ import io.rong.imkit.conversationlist.ConversationListAdapter;
import io.rong.imkit.conversationlist.ConversationListFragment; import io.rong.imkit.conversationlist.ConversationListFragment;
import io.rong.imkit.conversationlist.model.BaseUiConversation; import io.rong.imkit.conversationlist.model.BaseUiConversation;
import io.rong.imkit.conversationlist.model.SingleConversation; import io.rong.imkit.conversationlist.model.SingleConversation;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.SearchConversationResult;
public class MainMessageChatFragment extends ConversationListFragment { public class MainMessageChatFragment extends ConversationListFragment {
@ -70,31 +72,44 @@ public class MainMessageChatFragment extends ConversationListFragment {
} }
private void getChatRecordList(List<BaseUiConversation> list, String search) { private void getChatRecordList(List<BaseUiConversation> list, String search) {
BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation()); Conversation.ConversationType[] conversationTypes = {Conversation.ConversationType.PRIVATE};
conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_chat_records)); String[] messageTypeObjectNames = {"RC:TxtMsg"};
conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE);
list.add(conversation); RongIMClient.getInstance().searchConversations(search, conversationTypes, messageTypeObjectNames, new RongIMClient.ResultCallback<List<SearchConversationResult>>() {
List<BaseUiConversation> data = new ArrayList<>(); @Override
for (int i = 0; i < 3; i++) { public void onSuccess(List<SearchConversationResult> searchConversationResults) {
conversation = new SingleConversation(getContext(), new Conversation()); BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation());
conversation.mCore.setObjectName("SEARCH_CHAT"); conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_chat_records));
conversation.mCore.setConversationTitle(search + "|" + i); conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE);
conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE); list.add(conversation);
conversation.mConversationContent = new SpannableString(search); List<BaseUiConversation> data = new ArrayList<>();
conversation.mCore.setPortraitUrl("https://downs.yaoulive.com/defaultpink.png"); for (SearchConversationResult result : searchConversationResults) {
data.add(conversation); BaseUiConversation cn = new SingleConversation(getContext(), result.getConversation());
} cn.mCore.setObjectName("SEARCH_CHAT"+search);
if (data.size() == 1) { data.add(cn);
data.get(0).mCore.setMentionedCount(3); }
} else if (data.size() != 0) { if (data.size() == 1) {
data.get(0).mCore.setMentionedCount(1); data.get(0).mCore.setMentionedCount(3);
data.get(data.size() - 1).mCore.setMentionedCount(2); } else if (data.size() != 0) {
} else { data.get(0).mCore.setMentionedCount(1);
list.remove(list.size() - 1); data.get(data.size() - 1).mCore.setMentionedCount(2);
} } else {
list.addAll(data); list.remove(list.size() - 1);
mAdapter.setDataCollection(list); }
mAdapter.notifyDataSetChanged(); list.addAll(data);
mAdapter.setDataCollection(list);
mAdapter.notifyDataSetChanged();
}
@Override
public void onError(RongIMClient.ErrorCode e) {
ToastUtil.show("搜索出错了:"+e.getMessage());
mAdapter.setDataCollection(list);
mAdapter.notifyDataSetChanged();
}
});
} }
public void onChatList() { public void onChatList() {

View File

@ -261,6 +261,7 @@
<!-- 此容器用于动态放置 fragment--> <!-- 此容器用于动态放置 fragment-->
<FrameLayout <FrameLayout
android:id="@+id/container" android:id="@+id/container"
android:layout_marginBottom="50dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />