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 c534795..987c1b9 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 4c7cefa..dacc061 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 f8c2a83..5f1755b 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 @@