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,19 +72,21 @@ public class MainMessageChatFragment extends ConversationListFragment {
} }
private void getChatRecordList(List<BaseUiConversation> list, String search) { private void getChatRecordList(List<BaseUiConversation> list, String search) {
Conversation.ConversationType[] conversationTypes = {Conversation.ConversationType.PRIVATE};
String[] messageTypeObjectNames = {"RC:TxtMsg"};
RongIMClient.getInstance().searchConversations(search, conversationTypes, messageTypeObjectNames, new RongIMClient.ResultCallback<List<SearchConversationResult>>() {
@Override
public void onSuccess(List<SearchConversationResult> searchConversationResults) {
BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation()); BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation());
conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_chat_records)); conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_chat_records));
conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE); conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE);
list.add(conversation); list.add(conversation);
List<BaseUiConversation> data = new ArrayList<>(); List<BaseUiConversation> data = new ArrayList<>();
for (int i = 0; i < 3; i++) { for (SearchConversationResult result : searchConversationResults) {
conversation = new SingleConversation(getContext(), new Conversation()); BaseUiConversation cn = new SingleConversation(getContext(), result.getConversation());
conversation.mCore.setObjectName("SEARCH_CHAT"); cn.mCore.setObjectName("SEARCH_CHAT"+search);
conversation.mCore.setConversationTitle(search + "|" + i); data.add(cn);
conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE);
conversation.mConversationContent = new SpannableString(search);
conversation.mCore.setPortraitUrl("https://downs.yaoulive.com/defaultpink.png");
data.add(conversation);
} }
if (data.size() == 1) { if (data.size() == 1) {
data.get(0).mCore.setMentionedCount(3); data.get(0).mCore.setMentionedCount(3);
@ -97,6 +101,17 @@ public class MainMessageChatFragment extends ConversationListFragment {
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
} }
@Override
public void onError(RongIMClient.ErrorCode e) {
ToastUtil.show("搜索出错了:"+e.getMessage());
mAdapter.setDataCollection(list);
mAdapter.notifyDataSetChanged();
}
});
}
public void onChatList() { public void onChatList() {
mAdapter.getData().clear(); mAdapter.getData().clear();
subscribeUi(); subscribeUi();

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" />