From e2e7ce8183d1c616b3cc76ece57c20a20e0c8669 Mon Sep 17 00:00:00 2001 From: z583819556 Date: Thu, 7 Mar 2024 16:30:39 +0800 Subject: [PATCH] =?UTF-8?q?update=E6=B6=88=E6=81=AF=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=E8=9E=8D=E4=BA=91=E6=90=9C=E7=B4=A2=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/MainConversationListAdapter.java | 7 +- .../fragment/MainMessageChatFragment.java | 65 ++++++++++++------- .../src/main/res/layout/view_main_message.xml | 1 + 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java b/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java index c53479502..987c1b972 100644 --- a/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java @@ -51,7 +51,7 @@ public class MainConversationListAdapter extends ConversationListAdapter { String objectName = mDataList.get(position).mCore.getObjectName(); if (!StringUtil.isEmpty(objectName) && objectName.startsWith("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; } else if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_TITLE")) { type = TYPE_SEARCH_TITLE; @@ -103,7 +103,10 @@ public class MainConversationListAdapter extends ConversationListAdapter { private void bindChat(ViewHolder holder, int position) { 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()); - Spanned spanned = Html.fromHtml(WordUtil.getNewString(R.string.activity_msg_list_include) + "" + mDataList.get(position).mConversationContent + ""); + String title = mDataList.get(position).mConversationContent.toString(); + String key = mDataList.get(position).mCore.getObjectName().replace("SEARCH_CHAT", ""); + title = title.replace(key, "" + key + ""); + Spanned spanned = Html.fromHtml(WordUtil.getNewString(R.string.activity_msg_list_include) +title); ((TextView) holder.getView(R.id.rc_conversation_content)).setText(spanned); int type = mDataList.get(position).mCore.getMentionedCount(); holder.getView(R.id.itemDecorationTop).setVisibility(View.GONE); diff --git a/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java b/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java index 4c7cefa7f..dacc061cc 100644 --- a/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java @@ -23,7 +23,9 @@ import io.rong.imkit.conversationlist.ConversationListAdapter; import io.rong.imkit.conversationlist.ConversationListFragment; import io.rong.imkit.conversationlist.model.BaseUiConversation; import io.rong.imkit.conversationlist.model.SingleConversation; +import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.SearchConversationResult; public class MainMessageChatFragment extends ConversationListFragment { @@ -70,31 +72,44 @@ public class MainMessageChatFragment extends ConversationListFragment { } private void getChatRecordList(List list, String search) { - BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation()); - conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_chat_records)); - conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE); - list.add(conversation); - List data = new ArrayList<>(); - for (int i = 0; i < 3; i++) { - conversation = new SingleConversation(getContext(), new Conversation()); - conversation.mCore.setObjectName("SEARCH_CHAT"); - conversation.mCore.setConversationTitle(search + "|" + i); - 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) { - data.get(0).mCore.setMentionedCount(3); - } else if (data.size() != 0) { - data.get(0).mCore.setMentionedCount(1); - data.get(data.size() - 1).mCore.setMentionedCount(2); - } else { - list.remove(list.size() - 1); - } - list.addAll(data); - mAdapter.setDataCollection(list); - mAdapter.notifyDataSetChanged(); + Conversation.ConversationType[] conversationTypes = {Conversation.ConversationType.PRIVATE}; + String[] messageTypeObjectNames = {"RC:TxtMsg"}; + + RongIMClient.getInstance().searchConversations(search, conversationTypes, messageTypeObjectNames, new RongIMClient.ResultCallback>() { + @Override + public void onSuccess(List searchConversationResults) { + BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation()); + conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_chat_records)); + conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE); + list.add(conversation); + List data = new ArrayList<>(); + for (SearchConversationResult result : searchConversationResults) { + BaseUiConversation cn = new SingleConversation(getContext(), result.getConversation()); + cn.mCore.setObjectName("SEARCH_CHAT"+search); + data.add(cn); + } + if (data.size() == 1) { + data.get(0).mCore.setMentionedCount(3); + } else if (data.size() != 0) { + data.get(0).mCore.setMentionedCount(1); + data.get(data.size() - 1).mCore.setMentionedCount(2); + } else { + list.remove(list.size() - 1); + } + 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() { diff --git a/main/src/main/res/layout/view_main_message.xml b/main/src/main/res/layout/view_main_message.xml index f8c2a8358..5f1755b1d 100644 --- a/main/src/main/res/layout/view_main_message.xml +++ b/main/src/main/res/layout/view_main_message.xml @@ -261,6 +261,7 @@