搜索的数据重新加载

This commit is contained in:
ningwenqiang 2024-09-05 16:55:13 +08:00
parent b56a0bcce4
commit e0c1e9c64f
2 changed files with 29 additions and 9 deletions

View File

@ -132,11 +132,13 @@ public class MainConversationListAdapter extends ConversationListAdapter {
int type = super.getItemViewType(position); int type = super.getItemViewType(position);
if (mDataList.size() > position) { if (mDataList.size() > position) {
String objectName = mDataList.get(position).mCore.getObjectName(); String objectName = mDataList.get(position).mCore.getObjectName();
Log.i("聊天数据源发现","objectName"+objectName);
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.startsWith("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")) {
Log.i("聊天数据源发现 ","getItemViewTypeSEARCH_TITLE");
type = TYPE_SEARCH_TITLE; type = TYPE_SEARCH_TITLE;
} }
} else if (mDataList.isEmpty() || isEmpty() || srcList.isEmpty()) { } else if (mDataList.isEmpty() || isEmpty() || srcList.isEmpty()) {
@ -156,7 +158,9 @@ public class MainConversationListAdapter extends ConversationListAdapter {
} else if (getItemViewType(position) == TYPE_SEARCH_CHAT) { } else if (getItemViewType(position) == TYPE_SEARCH_CHAT) {
bindChat(holder, position); bindChat(holder, position);
} else if (getItemViewType(position) == TYPE_SEARCH_TITLE) { } else if (getItemViewType(position) == TYPE_SEARCH_TITLE) {
Log.i("聊天数据源设置标题头","SEARCH_TITLE::"+position);
bindTitle(holder, position); bindTitle(holder, position);
return;
} else if (getItemViewType(position) != -200) { } else if (getItemViewType(position) != -200) {
bindChatNew(holder, position); bindChatNew(holder, position);
super.onBindViewHolder(holder, position); super.onBindViewHolder(holder, position);
@ -297,7 +301,8 @@ public class MainConversationListAdapter extends ConversationListAdapter {
if (mContext == null) if (mContext == null)
mContext = AppManager.getInstance().getLastActivity(); mContext = AppManager.getInstance().getLastActivity();
for (BaseUiConversation item : data) { for (BaseUiConversation item : data) {
if (urls.contains(item.mCore.getTargetId())) continue; if (urls.contains(item.mCore.getTargetId()) && item.mCore.getTargetId()!=null) continue;
// if ( item.mCore.getConversationTitle()==null || item.mCore.getTargetId()==null) continue;
if (item.mConversationContent != null && item.mConversationContent.toString().contains("_method_")) { if (item.mConversationContent != null && item.mConversationContent.toString().contains("_method_")) {
IMCenter.getInstance().deleteMessages(Conversation.ConversationType.PRIVATE, IMCenter.getInstance().deleteMessages(Conversation.ConversationType.PRIVATE,
item.mCore.getTargetId(), item.mCore.getTargetId(),
@ -316,7 +321,8 @@ public class MainConversationListAdapter extends ConversationListAdapter {
IMCenter.getInstance().clearMessagesUnreadStatus(Conversation.ConversationType.PRIVATE, item.mCore.getTargetId(), null); IMCenter.getInstance().clearMessagesUnreadStatus(Conversation.ConversationType.PRIVATE, item.mCore.getTargetId(), null);
} }
urls.add(item.mCore.getTargetId()); urls.add(item.mCore.getTargetId());
Log.i("聊天数据源", item.mCore.getConversationTitle() + "|" + item.mCore.getPortraitUrl() + "|" + item.mCore.getTargetId()); Log.i("聊天数据源", item.mCore.getConversationTitle() + "|" + item.mCore.getPortraitUrl() + "|" + item.mCore.getTargetId() +"|"+item.mCore.getObjectName());
if (!tmpUids.contains(item.mCore.getTargetId())) { if (!tmpUids.contains(item.mCore.getTargetId())) {
BaseUiConversation cn = new SingleConversation(mContext, item.mCore); BaseUiConversation cn = new SingleConversation(mContext, item.mCore);
srcList.add(cn); srcList.add(cn);
@ -332,21 +338,21 @@ public class MainConversationListAdapter extends ConversationListAdapter {
} }
List<BaseUiConversation> showData = null; List<BaseUiConversation> showData = null;
if (isSearch) { if (isSearch) {
Log.i("聊天数据源", "FilterData isSearch"); // Log.i("聊天数据源", "FilterData isSearch");
showData = UiConversationCodeUtil.FilterData(mFilter, tmp, allDataList); showData = tmp ;//UiConversationCodeUtil.FilterData(mFilter, tmp, allDataList);
} else { } else {
allDataList = tmp; allDataList = tmp;
if (mFilter != FILTER_OFFLINE && mFilter != FILTER_ONLINE ) if (mFilter != FILTER_OFFLINE && mFilter != FILTER_ONLINE )
{ {
Log.i("聊天数据源", "FilterData notSearch"); // Log.i("聊天数据源", "FilterData notSearch");
showData = UiConversationCodeUtil.FilterData(mFilter, allDataList); showData = UiConversationCodeUtil.FilterData(mFilter, allDataList);
} }
} }
if (showData != null && !UiConversationCodeUtil.checkIsSame(showData, mDataList)) { if (showData != null && !UiConversationCodeUtil.checkIsSame(showData, mDataList)) {
Log.i("聊天数据源", "数据源有变化" + showData.size()); // Log.i("聊天数据源", "数据源有变化" + showData.size());
super.setDataCollection(showData); super.setDataCollection(showData);
} else { } else {
Log.i("聊天数据源", "数据源无变化"); // Log.i("聊天数据源", "数据源无变化");
} }
} }

View File

@ -1,6 +1,8 @@
package com.yunbao.common.fragment; package com.yunbao.common.fragment;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -28,6 +30,8 @@ import io.rong.imkit.conversationlist.model.SingleConversation;
import io.rong.imkit.event.Event; import io.rong.imkit.event.Event;
import io.rong.imlib.RongIMClient; import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.MessageContent;
import io.rong.imlib.model.SearchConversationResult; import io.rong.imlib.model.SearchConversationResult;
public class MainMessageChatFragment extends ConversationListFragment { public class MainMessageChatFragment extends ConversationListFragment {
@ -82,6 +86,10 @@ public class MainMessageChatFragment extends ConversationListFragment {
} }
public void search(String search) { public void search(String search) {
if (TextUtils.isEmpty(search)){
mRefreshLayout.autoRefresh();
return;
}
((MainConversationListAdapter) mAdapter).setSearch(); ((MainConversationListAdapter) mAdapter).setSearch();
getContactsList(search); getContactsList(search);
} }
@ -95,10 +103,11 @@ public class MainMessageChatFragment extends ConversationListFragment {
List<String> uidList = new ArrayList<>(); List<String> uidList = new ArrayList<>();
BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation()); BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation());
conversation.mCore.setMessage(new Message());
conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_contacts)); conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_contacts));
Log.i("聊天数据源设置数据", "聊天数据源: " + conversation.mCore.getObjectName());
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<>();
System.err.println(" ----------------------->" + mAdapter.getData().size()); System.err.println(" ----------------------->" + mAdapter.getData().size());
for (BaseUiConversation cn : ((MainConversationListAdapter) mAdapter).getSrcList()) { for (BaseUiConversation cn : ((MainConversationListAdapter) mAdapter).getSrcList()) {
@ -137,7 +146,9 @@ public class MainMessageChatFragment extends ConversationListFragment {
@Override @Override
public void onSuccess(List<SearchConversationResult> searchConversationResults) { public void onSuccess(List<SearchConversationResult> searchConversationResults) {
BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation()); BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation());
conversation.mCore.setMessage(new Message());
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));
Log.i("聊天数据源设置数据", "聊天数据源: " + conversation.mCore.getObjectName());
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<>();
@ -155,6 +166,9 @@ public class MainMessageChatFragment extends ConversationListFragment {
list.remove(list.size() - 1); list.remove(list.size() - 1);
} }
list.addAll(data); list.addAll(data);
for (BaseUiConversation cn : list){
Log.i("聊天数据源搜索前的", cn.mCore.getConversationTitle() + "|" + cn.mCore.getPortraitUrl() + "|" + cn.mCore.getTargetId());
}
((MainConversationListAdapter) mAdapter).setDataCollectionV2(list,true); ((MainConversationListAdapter) mAdapter).setDataCollectionV2(list,true);
} }
@ -172,7 +186,7 @@ public class MainMessageChatFragment extends ConversationListFragment {
((MainConversationListAdapter) mAdapter).clear(); ((MainConversationListAdapter) mAdapter).clear();
System.out.println(">!>!>!>!!>" + mConversationListViewModel); System.out.println(">!>!>!>!!>" + mConversationListViewModel);
subscribeUi(); subscribeUi();
mRefreshLayout.autoRefresh();
} }
@Override @Override