消息分类后的搜索进行优化

This commit is contained in:
ningwenqiang 2024-08-30 17:37:05 +08:00
parent 08480af796
commit b4574f730d
7 changed files with 117 additions and 27 deletions

View File

@ -674,6 +674,8 @@ rx.internal.util.atomic.LinkedQueueNode* consumerNode;
-keep class androidx.constraintlayout.widget.ConstraintLayout { <init>(android.content.Context, android.util.AttributeSet); } -keep class androidx.constraintlayout.widget.ConstraintLayout { <init>(android.content.Context, android.util.AttributeSet); }
-keep class androidx.constraintlayout.widget.Group { <init>(android.content.Context, android.util.AttributeSet); }
-keep class androidx.constraintlayout.widget.Guideline { <init>(android.content.Context, android.util.AttributeSet); } -keep class androidx.constraintlayout.widget.Guideline { <init>(android.content.Context, android.util.AttributeSet); }
-keep class androidx.coordinatorlayout.widget.CoordinatorLayout { <init>(android.content.Context, android.util.AttributeSet); } -keep class androidx.coordinatorlayout.widget.CoordinatorLayout { <init>(android.content.Context, android.util.AttributeSet); }

View File

@ -81,9 +81,7 @@ public class MainConversationListAdapter extends ConversationListAdapter {
if (this.mFilter == mFilter) if (this.mFilter == mFilter)
return; return;
this.mFilter = mFilter; this.mFilter = mFilter;
// if (allDataList !=null && !allDataList.isEmpty()){
// super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList));
// }
} }
@ -93,8 +91,11 @@ public class MainConversationListAdapter extends ConversationListAdapter {
public void setSrcList(List<BaseUiConversation> srcList) { public void setSrcList(List<BaseUiConversation> srcList) {
this.srcList = srcList; this.srcList = srcList;
if (mFilter== FILTER_OFFLINE || mFilter == FILTER_ONLINE) {
super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList)); super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList));
// notifyDataSetChanged(); }else {
notifyDataSetChanged();
}
} }
public void setOnRefreshListener(OnRecyclerListRefreshListener<List<BaseUiConversation>> onRefreshListener) { public void setOnRefreshListener(OnRecyclerListRefreshListener<List<BaseUiConversation>> onRefreshListener) {
@ -285,7 +286,8 @@ public class MainConversationListAdapter extends ConversationListAdapter {
if (data.hashCode() == listHashCode) return; if (data.hashCode() == listHashCode) return;
listHashCode = data.hashCode(); listHashCode = data.hashCode();
List<BaseUiConversation> tmp = new ArrayList<>(); List<BaseUiConversation> tmp = new ArrayList<>();
Log.i("聊天数据源", "setDataCollection: " + data.hashCode()); Log.i("聊天数据源", "size()" + data.size() + " setDataCollection: " + data.hashCode());
List<String> urls = new ArrayList<>(); List<String> urls = new ArrayList<>();
if (srcList == null) { if (srcList == null) {
srcList = new ArrayList<>(); srcList = new ArrayList<>();
@ -327,13 +329,24 @@ public class MainConversationListAdapter extends ConversationListAdapter {
} }
tmp.add(item); tmp.add(item);
} }
List<BaseUiConversation> showData = null;
if (isSearch) {
Log.i("聊天数据源", "FilterData isSearch");
showData = UiConversationCodeUtil.FilterData(mFilter, tmp, allDataList);
} else {
allDataList = tmp; allDataList = tmp;
if (mFilter != FILTER_OFFLINE || isSearch == true) { if (mFilter != FILTER_OFFLINE)
List<BaseUiConversation> showData = UiConversationCodeUtil.FilterData(mFilter, tmp); {
if (!UiConversationCodeUtil.checkIsSame(showData, mDataList)) { Log.i("聊天数据源", "FilterData notSearch");
super.setDataCollection(showData); showData = UiConversationCodeUtil.FilterData(mFilter, allDataList);
} }
} }
if (showData != null && !UiConversationCodeUtil.checkIsSame(showData, mDataList)) {
Log.i("聊天数据源", "数据源有变化" + showData.size());
super.setDataCollection(showData);
} else {
Log.i("聊天数据源", "数据源无变化");
}
} }
@ -346,6 +359,7 @@ public class MainConversationListAdapter extends ConversationListAdapter {
private List<String> tmpUids = new ArrayList<>(); private List<String> tmpUids = new ArrayList<>();
public void clear() { public void clear() {
Log.i("聊天数据源", "clear: " + mDataList.size());
mDataList.clear(); mDataList.clear();
if (srcList != null) { if (srcList != null) {
srcList.clear(); srcList.clear();

View File

@ -1295,7 +1295,7 @@ public interface PDLiveApi {
@Query("open_off") int status @Query("open_off") int status
); );
@GET("/api/public/?service=Pdlmsg.sendBefore") @GET("/api/public/?service=Pdlmsg.sendBefore&new_pop=1")
Observable<ResponseModel<MessageSayHiBean>> getMessageSayHiTimer( Observable<ResponseModel<MessageSayHiBean>> getMessageSayHiTimer(
); );

View File

@ -71,6 +71,77 @@ public class UiConversationCodeUtil {
} }
private static boolean isContains(List<BaseUiConversation> list, BaseUiConversation item) {
// 根据 item.mCore.getChannelId() 判断 list 是否包含
if (list == null || list.isEmpty() || item == null || item.mCore == null) {
return false;
}
for (BaseUiConversation conversation : list) {
// 增加空值检查
if (conversation != null && conversation.mCore != null
&& conversation.mCore.getTargetId() != null
&& conversation.mCore.getTargetId().equals(item.mCore.getTargetId())) {
return true;
}
}
return false;
}
public static List<BaseUiConversation> FilterData(int filterType, List<BaseUiConversation> keyList,List<BaseUiConversation> srcList) {
List<BaseUiConversation> showData = new ArrayList<>();
if (keyList == null || keyList.isEmpty())
return showData;
Log.i("MainConversationListAdapter", "FilterData: 源" + keyList.size());
switch (filterType) {
case FILTER_ALL:
showData = keyList;
break;
case FILTER_ONLINE:
for (BaseUiConversation conversation : srcList) {
if ("0".equals(conversation.mCore.getDraft()) && isContains(keyList, conversation)) {
showData.add(conversation);
}
}
break;
case FILTER_OFFLINE:
for (BaseUiConversation conversation : keyList) {
if (!"0".equals(conversation.mCore.getDraft())) {
showData.add(conversation);
}
}
break;
case FILTER_READ:
for (BaseUiConversation conversation : keyList)
if (conversation.mCore.getMessage() != null && conversation.mCore.getMessage().getMessageDirection() != null) {
if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) {
if (conversation.mCore.getSentStatus() == Message.SentStatus.READ) {
showData.add(conversation);
}
}
}
break;
case FILTER_UNREAD:
for (BaseUiConversation conversation : keyList) {
boolean isRead;
if (conversation.mCore.getMessage() != null && conversation.mCore.getMessage().getMessageDirection() != null) {
if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) {
if (conversation.mCore.getSentStatus() != Message.SentStatus.READ) {
showData.add(conversation);
}
}
}
}
break;
}
Log.i("MainConversationListAdapter", "FilterData: 结果" + showData.size());
return showData;
}
public static List<BaseUiConversation> FilterData(int filterType, List<BaseUiConversation> data) { public static List<BaseUiConversation> FilterData(int filterType, List<BaseUiConversation> data) {
List<BaseUiConversation> showData = new ArrayList<>(); List<BaseUiConversation> showData = new ArrayList<>();
if (data == null || data.isEmpty()) if (data == null || data.isEmpty())
@ -106,7 +177,6 @@ public class UiConversationCodeUtil {
break; break;
case FILTER_UNREAD: case FILTER_UNREAD:
for (BaseUiConversation conversation : data) { for (BaseUiConversation conversation : data) {
boolean isRead;
if (conversation.mCore.getMessage() != null && conversation.mCore.getMessage().getMessageDirection() != null) { if (conversation.mCore.getMessage() != null && conversation.mCore.getMessage().getMessageDirection() != null) {
if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) { if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) {
if (conversation.mCore.getSentStatus() != Message.SentStatus.READ) { if (conversation.mCore.getSentStatus() != Message.SentStatus.READ) {
@ -117,6 +187,7 @@ public class UiConversationCodeUtil {
} }
break; break;
} }
Log.i("MainConversationListAdapter", "FilterData: 结果" + showData.size());
return showData; return showData;
} }

View File

@ -90,6 +90,10 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
tools:text="[已读]" tools:text="[已读]"
app:layout_constraintEnd_toStartOf="@id/rc_conversation_content"
android:layout_marginEnd="6dp"
android:visibility="gone"
tools:visibility="visible"
android:textColor="@color/rc_secondary_color" android:textColor="@color/rc_secondary_color"
android:textSize="13dp" /> android:textSize="13dp" />
@ -99,7 +103,6 @@
style="@style/TextStyle.Alignment" style="@style/TextStyle.Alignment"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="6dp"
android:paddingEnd="6dp" android:paddingEnd="6dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"

View File

@ -1609,6 +1609,6 @@
<string name="all_chats">全部聊天</string> <string name="all_chats">全部聊天</string>
<string name="online_only">僅展示在線</string> <string name="online_only">僅展示在線</string>
<string name="offline_only">僅展示離線</string> <string name="offline_only">僅展示離線</string>
<string name="read_only">展示對方已讀</string> <string name="read_only">展示對方已讀</string>
<string name="unread_only">展示對方未讀</string> <string name="unread_only">展示對方未讀</string>
</resources> </resources>

View File

@ -512,7 +512,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
tabTexts.get(0).setText(WordUtil.getNewString(R.string.message_chat_msg_recommend)); tabTexts.get(0).setText(WordUtil.getNewString(R.string.message_chat_msg_recommend));
relativeLayouts.get(1).setVisibility(View.VISIBLE); relativeLayouts.get(1).setVisibility(View.VISIBLE);
tabTexts.get(1).setText(WordUtil.getNewString(chatViewModel.getTitleTextId())); tabTexts.get(1).setText(WordUtil.getNewString(chatViewModel.getTitleTextId()));
// tabExpend.get(1).setVisibility(View.VISIBLE); tabExpend.get(1).setVisibility(View.VISIBLE);
} else { //主播B } else { //主播B
tabExpend.get(0).setVisibility(View.VISIBLE); tabExpend.get(0).setVisibility(View.VISIBLE);
relativeLayouts.get(0).setVisibility(View.VISIBLE); relativeLayouts.get(0).setVisibility(View.VISIBLE);