搜索的数据重新加载

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

View File

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