From 114a6472fb7182c6d1b1d1ff7af076b3d1f0dba7 Mon Sep 17 00:00:00 2001 From: ningwenqiang Date: Wed, 28 Aug 2024 11:22:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=BA=9B=E9=9D=9E?= =?UTF-8?q?=E7=A9=BA=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/MainConversationListAdapter.java | 93 ++++--------- .../fragment/MainMessageChatFragment.java | 13 +- .../common/utils/UiConversationCodeUtil.java | 130 ++++++++++++++++++ .../res/layout/view_msg_select_chat_type.xml | 10 +- gradle.properties | 4 +- .../main/views/MainMessageViewHolder.java | 4 +- .../src/main/res/layout/view_main_message.xml | 6 +- 7 files changed, 174 insertions(+), 86 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java diff --git a/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java b/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java index 7e825d1c0..beabaff90 100644 --- a/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java +++ b/common/src/main/java/com/yunbao/common/adapter/MainConversationListAdapter.java @@ -15,6 +15,7 @@ import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import com.blankj.utilcode.util.LogUtils; +import com.google.android.exoplayer2.C; import com.yunbao.common.R; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.interfaces.OnRecyclerListRefreshListener; @@ -24,6 +25,7 @@ import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.ChatMsgTypeUtils; import com.yunbao.common.utils.DateFormatUtil; import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.UiConversationCodeUtil; import com.yunbao.common.utils.ViewUtils; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; @@ -34,6 +36,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import io.rong.imkit.IMCenter; import io.rong.imkit.RongIM; @@ -68,7 +71,6 @@ public class MainConversationListAdapter extends ConversationListAdapter { public static final int FILTER_UNREAD = 2; public static final int FILTER_READ = 4; public static final int FILTER_ALL = 7; - private int mFilter = FILTER_ALL; public int getFilter() { @@ -79,62 +81,9 @@ public class MainConversationListAdapter extends ConversationListAdapter { if (this.mFilter == mFilter) return; this.mFilter = mFilter; - super.setDataCollection(FilterData(mFilter, allDataList)); + super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList)); } - private List FilterData(int filterType, List data){ - List showData= new ArrayList<>();; - Log.i("MainConversationListAdapter", "FilterData: 源" + data.size()); - switch (filterType) { - case FILTER_ALL: - showData = data; - break; - case FILTER_ONLINE : - for (BaseUiConversation conversation : data) { - if ("0".equals(conversation.mCore.getDraft())) { - showData.add(conversation); - } - } - break; - case FILTER_OFFLINE: - for (BaseUiConversation conversation : data) { - if (!"0".equals(conversation.mCore.getDraft())) { - showData.add(conversation); - } - } - break; - case FILTER_READ: - for (BaseUiConversation conversation : data) { - boolean isRead; - if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) - { - isRead = (conversation.mCore.getSentStatus() == Message.SentStatus.READ); - }else { - isRead = conversation.mCore.getReceivedStatus().isRead(); - } - if (isRead) { - showData.add(conversation); - } - } - break; - case FILTER_UNREAD: - for (BaseUiConversation conversation : data) { - boolean isRead; - if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) - { - isRead = (conversation.mCore.getSentStatus() == Message.SentStatus.READ); - }else { - isRead = conversation.mCore.getReceivedStatus().isRead(); - } - if (!isRead) { - showData.add(conversation); - } - } - break; - } - Log.i("MainConversationListAdapter", "FilterData: 结果" + showData.size()); - return showData; - } @@ -143,8 +92,8 @@ public class MainConversationListAdapter extends ConversationListAdapter { } public void setSrcList(List srcList) { - this.srcList = srcList; - super.setDataCollection(FilterData(mFilter, allDataList)); + this.srcList = srcList; + super.setDataCollection(UiConversationCodeUtil.FilterData(mFilter, allDataList)); // notifyDataSetChanged(); } @@ -239,13 +188,17 @@ public class MainConversationListAdapter extends ConversationListAdapter { holder.setVisible(R.id.rc_conversation_unread_count, false); } - boolean isRead; - if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) - { - isRead = (conversation.mCore.getSentStatus() == Message.SentStatus.READ); - }else { - isRead = conversation.mCore.getReceivedStatus().isRead(); + boolean isRead = false; + Message message = conversation.mCore.getMessage(); + if (message != null) { + Message.MessageDirection direction = message.getMessageDirection(); + if (direction != null && direction == Message.MessageDirection.SEND) { + isRead = (conversation.mCore.getSentStatus() == Message.SentStatus.READ); + } else { + isRead = conversation.mCore.getReceivedStatus().isRead(); + } } + if (isRead) { holder.setTextColor(R.id.rc_conversation_unread_tv, ContextCompat.getColor(holder.itemView.getContext(), R.color.rc_secondary_color)); holder.setText(R.id.rc_conversation_unread_tv, WordUtil.getNewString(R.string.message_chat_msg_read_tip)); @@ -255,7 +208,6 @@ public class MainConversationListAdapter extends ConversationListAdapter { } - if (holder.getView(R.id.rc_conversation_live_status) == null || IMLoginManager.get(holder.getContext()).getAnchorB() != 1) { return; } @@ -272,8 +224,6 @@ public class MainConversationListAdapter extends ConversationListAdapter { } else { holder.getView(R.id.rc_conversation_live_status).setVisibility(View.GONE); } - - } @@ -382,11 +332,16 @@ public class MainConversationListAdapter extends ConversationListAdapter { } tmp.add(item); } - allDataList= tmp; - List showData= FilterData(mFilter,tmp); - super.setDataCollection(showData); + allDataList = tmp; + if(mFilter!=FILTER_OFFLINE){ + List showData = UiConversationCodeUtil.FilterData(mFilter, tmp); + if(!UiConversationCodeUtil.checkIsSame(showData,mDataList)){ + super.setDataCollection(showData); + } + } } + private List tmpUids = new ArrayList<>(); public void clear() { diff --git a/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java b/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java index 73d5f9132..eeaaad722 100644 --- a/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java +++ b/common/src/main/java/com/yunbao/common/fragment/MainMessageChatFragment.java @@ -14,6 +14,7 @@ import com.yunbao.common.R; import com.yunbao.common.adapter.MainConversationListAdapter; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.UiConversationCodeUtil; import com.yunbao.common.utils.WordUtil; import java.util.ArrayList; @@ -46,10 +47,13 @@ public class MainMessageChatFragment extends ConversationListFragment { mConversationListViewModel.getConversationListLiveData().observe(this.getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(List uiConversations) { - if (listHashCode != uiConversations.hashCode()) { - listHashCode = uiConversations.hashCode(); + int hashCode = UiConversationCodeUtil.getListHasCode(uiConversations); + if (listHashCode != hashCode) { + Log.i("nwq", "刷新数据"); + listHashCode = hashCode; ((MainConversationListAdapter) mAdapter).onFinish(); } + } }); mConversationListViewModel.getRefreshEventLiveData().observe(this.getViewLifecycleOwner(), new Observer() { @@ -58,7 +62,6 @@ public class MainMessageChatFragment extends ConversationListFragment { listHashCode = 0; } }); - } public void setEmptyView(int viewLayoutMsgId) { @@ -156,10 +159,10 @@ public class MainMessageChatFragment extends ConversationListFragment { } public void onChatList() { - if(mConversationListViewModel==null)return; + if (mConversationListViewModel == null) return; ((MainConversationListAdapter) mAdapter).setChat(); ((MainConversationListAdapter) mAdapter).clear(); - System.out.println(">!>!>!>!!>"+mConversationListViewModel); + System.out.println(">!>!>!>!!>" + mConversationListViewModel); subscribeUi(); } diff --git a/common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java b/common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java new file mode 100644 index 000000000..cc2aac47d --- /dev/null +++ b/common/src/main/java/com/yunbao/common/utils/UiConversationCodeUtil.java @@ -0,0 +1,130 @@ +package com.yunbao.common.utils; + +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; + +import io.rong.imkit.conversationlist.model.BaseUiConversation; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.Message; + +public class UiConversationCodeUtil { + + + public static final int FILTER_OFFLINE = 0; + public static final int FILTER_ONLINE = 1; + public static final int FILTER_UNREAD = 2; + public static final int FILTER_READ = 4; + public static final int FILTER_ALL = 7; + + + public static boolean checkIsSame(List list1, List list2) { + if (list1.size() != list2.size()) return false; + int hashCode1 = getListHasCode(list1); + int hashCode2 = getListHasCode(list2); + return hashCode1 == hashCode2; + } + + public static boolean checkIsSame(int hashCode1, List list2) { + int hashCode2 = getListHasCode(list2); + return hashCode1 == hashCode2; + } + + public static int getListHasCode(List list) { + int hashCodeValue = 1; + for (BaseUiConversation conversation : list) { + if (conversation != null) { + hashCodeValue = 31 * hashCodeValue + getBaseUiConversationHashCode(conversation); + } + } + return hashCodeValue; + } + + + //根据BaseUiConversation对象的属性计算hashCode + private static int getBaseUiConversationHashCode(BaseUiConversation item) { + final int prime = 31; + int result = 1; + Conversation mCore = item.mCore; + result = prime * result + ((mCore.getPortraitUrl() == null) ? 0 : mCore.getPortraitUrl().hashCode()); + result = prime * result + ((mCore.getConversationTitle() == null) ? 0 : mCore.getConversationTitle().hashCode()); + result = prime * result + ((item.mConversationContent == null) ? 0 : item.mConversationContent.hashCode()); + result = prime * result + (int) (mCore.getSentTime() ^ (mCore.getSentTime() >>> 32)); + result = prime * result + ((mCore.getDraft() == null) ? 0 : mCore.getDraft().hashCode()); + result = prime * result + mCore.getUnreadMessageCount(); + + Message message = mCore.getMessage(); + if (message != null) { + Message.MessageDirection direction = message.getMessageDirection(); + if (direction != null) { + result = prime * result + direction.hashCode(); + } + } + + result = prime * result + ((mCore.getSentStatus() == null) ? 0 : mCore.getSentStatus().hashCode()); + result = prime * result + ((mCore.getReceivedStatus() == null) ? 0 : mCore.getReceivedStatus().hashCode()); + result = prime * result + ((mCore.getTargetId() == null) ? 0 : mCore.getTargetId().hashCode()); + return result; + } + + + public static List FilterData(int filterType, List data) { + List showData = new ArrayList<>(); + ; + Log.i("MainConversationListAdapter", "FilterData: 源" + data.size()); + switch (filterType) { + case FILTER_ALL: + showData = data; + break; + case FILTER_ONLINE: + for (BaseUiConversation conversation : data) { + if ("0".equals(conversation.mCore.getDraft())) { + showData.add(conversation); + } + } + break; + case FILTER_OFFLINE: + for (BaseUiConversation conversation : data) { + if (!"0".equals(conversation.mCore.getDraft())) { + showData.add(conversation); + } + } + break; + case FILTER_READ: + for (BaseUiConversation conversation : data) { + boolean isRead; + if (conversation.mCore.getMessage() != null && conversation.mCore.getMessage().getMessageDirection() != null) { + if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) { + isRead = (conversation.mCore.getSentStatus() == Message.SentStatus.READ); + } else { + isRead = conversation.mCore.getReceivedStatus().isRead(); + } + if (isRead) { + showData.add(conversation); + } + } + + } + break; + case FILTER_UNREAD: + for (BaseUiConversation conversation : data) { + boolean isRead; + if (conversation.mCore.getMessage() != null && conversation.mCore.getMessage().getMessageDirection() != null) { + if (conversation.mCore.getMessage().getMessageDirection() == Message.MessageDirection.SEND) { + isRead = (conversation.mCore.getSentStatus() == Message.SentStatus.READ); + } else { + isRead = conversation.mCore.getReceivedStatus().isRead(); + } + if (!isRead) { + showData.add(conversation); + } + } + } + break; + } + return showData; + } + + +} diff --git a/common/src/main/res/layout/view_msg_select_chat_type.xml b/common/src/main/res/layout/view_msg_select_chat_type.xml index 1a0cdc151..694295563 100644 --- a/common/src/main/res/layout/view_msg_select_chat_type.xml +++ b/common/src/main/res/layout/view_msg_select_chat_type.xml @@ -16,7 +16,7 @@ android:layout_weight="1" android:text="@string/all_chats" android:textColor="#777777" - android:textSize="14sp" + android:textSize="15sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:textColor="@color/colorMainTab" /> @@ -44,7 +44,7 @@ android:layout_weight="1" android:text="@string/online_only" android:textColor="#777777" - android:textSize="14sp" + android:textSize="15sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/chatTypeTv1" /> @@ -69,7 +69,7 @@ android:layout_weight="1" android:text="@string/offline_only" android:textColor="#777777" - android:textSize="14sp" + android:textSize="15sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/chatTypeTv2" /> @@ -94,7 +94,7 @@ android:layout_weight="1" android:text="@string/read_only" android:textColor="#777777" - android:textSize="14sp" + android:textSize="15sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/chatTypeTv3" /> @@ -120,7 +120,7 @@ android:layout_weight="1" android:text="@string/unread_only" android:textColor="#777777" - android:textSize="14sp" + android:textSize="15sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/chatTypeTv4" /> diff --git a/gradle.properties b/gradle.properties index c41a7a913..d015f4ba1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,6 +24,6 @@ android.nonTransitiveRClass=false systemProp.http.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1 -systemProp.https.proxyPort=7890 -systemProp.http.proxyPort=7890 +systemProp.https.proxyPort=9098 +systemProp.http.proxyPort=9098 #android.enableR8.fullMode=true \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java index b6ddf386b..7575fd000 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -250,7 +250,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder { } MainMessageChatListFragment chatFragment = (MainMessageChatListFragment) fragment; ImageView expendImg = (ImageView) view; - expendImg.setImageResource(R.mipmap.ic_expend_down); + expendImg.setImageResource(R.mipmap.ic_expend_up); XPopup.Builder builder = new XPopup.Builder(mContext).atView(relativeLayouts.get(position)); builder.offsetY(16); builder.dismissOnTouchOutside(true); @@ -271,7 +271,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder { @Override public void onDismiss(BasePopupView popupView) { - expendImg.setImageResource(R.mipmap.ic_expend_up); + expendImg.setImageResource(R.mipmap.ic_expend_down); } @Override diff --git a/main/src/main/res/layout/view_main_message.xml b/main/src/main/res/layout/view_main_message.xml index 9e95af268..4ea0338f7 100644 --- a/main/src/main/res/layout/view_main_message.xml +++ b/main/src/main/res/layout/view_main_message.xml @@ -383,7 +383,7 @@ android:padding="5dp" android:visibility="gone" tools:visibility="visible" - android:src="@mipmap/ic_expend_up" + android:src="@mipmap/ic_expend_down" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toEndOf="@+id/tab_top1" app:layout_constraintBottom_toBottomOf="parent"/> @@ -448,7 +448,7 @@ android:padding="5dp" android:visibility="gone" tools:visibility="visible" - android:src="@mipmap/ic_expend_up" + android:src="@mipmap/ic_expend_down" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toEndOf="@+id/tab_top2" app:layout_constraintBottom_toBottomOf="parent"/> @@ -514,7 +514,7 @@ android:visibility="gone" tools:visibility="visible" android:layout_centerHorizontal="true" - android:src="@mipmap/ic_expend_up" + android:src="@mipmap/ic_expend_down" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toEndOf="@+id/tab_top3" app:layout_constraintBottom_toBottomOf="parent"/>