修改已读未读判断逻辑

选择框外部可以点击
This commit is contained in:
ningwenqiang
2024-08-27 18:01:03 +08:00
parent 6abe02390e
commit ba47239e12
8 changed files with 314 additions and 218 deletions

View File

@@ -36,6 +36,7 @@ import java.util.List;
import java.util.Map;
import io.rong.imkit.IMCenter;
import io.rong.imkit.RongIM;
import io.rong.imkit.conversationlist.ConversationListAdapter;
import io.rong.imkit.conversationlist.model.BaseUiConversation;
import io.rong.imkit.conversationlist.model.SingleConversation;
@@ -104,14 +105,28 @@ public class MainConversationListAdapter extends ConversationListAdapter {
break;
case FILTER_READ:
for (BaseUiConversation conversation : data) {
if (conversation.mCore.getUnreadMessageCount() <= 0) {
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) {
if (conversation.mCore.getUnreadMessageCount() > 0) {
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);
}
}
@@ -220,14 +235,27 @@ public class MainConversationListAdapter extends ConversationListAdapter {
if (unReadCount > 0) {
holder.setVisible(R.id.rc_conversation_unread_count, true);
holder.setText(R.id.rc_conversation_unread_count, String.valueOf(unReadCount));
holder.setTextColor(R.id.rc_conversation_unread_tv, ContextCompat.getColor(holder.itemView.getContext(), R.color.red));
holder.setText(R.id.rc_conversation_unread_tv, WordUtil.getNewString(R.string.message_chat_msg_unread_tip));
} else {
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();
}
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));
} else {
holder.setTextColor(R.id.rc_conversation_unread_tv, ContextCompat.getColor(holder.itemView.getContext(), R.color.red));
holder.setText(R.id.rc_conversation_unread_tv, WordUtil.getNewString(R.string.message_chat_msg_unread_tip));
}
if (holder.getView(R.id.rc_conversation_live_status) == null || IMLoginManager.get(holder.getContext()).getAnchorB() != 1) {
return;
}

View File

@@ -3,7 +3,9 @@ package com.yunbao.common.views;
import static io.rong.imlib.publicservice.model.PublicServiceMenu.PublicServiceMenuItemType.View;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
@@ -13,6 +15,7 @@ import androidx.core.content.ContextCompat;
import com.lxj.xpopup.core.AttachPopupView;
import com.yunbao.common.R;
import com.yunbao.common.adapter.MainConversationListAdapter;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import org.repackage.com.zui.opendeviceidlibrary.OpenDeviceId;
@@ -24,12 +27,14 @@ public class MsgChatTypeSelectPoPupView extends AttachPopupView implements andro
private ResultCallBack mResultCallBack;
private int lastType;
public MsgChatTypeSelectPoPupView(@NonNull Context context,int type, ResultCallBack itemDelListener) {
public MsgChatTypeSelectPoPupView(@NonNull Context context, int type, ResultCallBack itemDelListener) {
super(context);
mResultCallBack = itemDelListener;
lastType = type;
}
@Override
protected int getImplLayoutId() {
return R.layout.view_msg_select_chat_type;
@@ -37,16 +42,27 @@ public class MsgChatTypeSelectPoPupView extends AttachPopupView implements andro
@Override
protected void onCreate() {
chatTypeTv1 =findViewById(R.id.chatTypeTv1);
chatTypeImg1 =findViewById(R.id.chatTypeImg1);
chatTypeTv2 =findViewById(R.id.chatTypeTv2);
chatTypeImg2 =findViewById(R.id.chatTypeImg2);
chatTypeTv3 =findViewById(R.id.chatTypeTv3);
chatTypeImg3 =findViewById(R.id.chatTypeImg3);
chatTypeTv4 =findViewById(R.id.chatTypeTv4);
chatTypeImg4 =findViewById(R.id.chatTypeImg4);
chatTypeTv5 =findViewById(R.id.chatTypeTv5);
chatTypeImg5 =findViewById(R.id.chatTypeImg5);
// 获取屏幕宽度
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
int screenWidth = displayMetrics.widthPixels;
// 设置弹窗宽度为屏幕宽度的 3/4
View view = findViewById(R.id.root);
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = screenWidth*3/4;
view.setLayoutParams(layoutParams);
chatTypeTv1 = findViewById(R.id.chatTypeTv1);
chatTypeImg1 = findViewById(R.id.chatTypeImg1);
chatTypeTv2 = findViewById(R.id.chatTypeTv2);
chatTypeImg2 = findViewById(R.id.chatTypeImg2);
chatTypeTv3 = findViewById(R.id.chatTypeTv3);
chatTypeImg3 = findViewById(R.id.chatTypeImg3);
chatTypeTv4 = findViewById(R.id.chatTypeTv4);
chatTypeImg4 = findViewById(R.id.chatTypeImg4);
chatTypeTv5 = findViewById(R.id.chatTypeTv5);
chatTypeImg5 = findViewById(R.id.chatTypeImg5);
chatTypeImg1.setOnClickListener(this);
chatTypeImg2.setOnClickListener(this);
@@ -58,52 +74,49 @@ public class MsgChatTypeSelectPoPupView extends AttachPopupView implements andro
}
private void handleChatTypeClick(int type) {
switch (type) {
case MainConversationListAdapter.FILTER_ALL:
chatTypeImg1.setImageResource(R.mipmap.ic_chat_type_select);
chatTypeTv1.setTextColor(ContextCompat.getColor(chatTypeTv1.getContext(),R.color.colorMainTab));
chatTypeTv1.setTextColor(ContextCompat.getColor(chatTypeTv1.getContext(), R.color.colorMainTab));
break;
case MainConversationListAdapter.FILTER_ONLINE:
chatTypeImg2.setImageResource(R.mipmap.ic_chat_type_select);
chatTypeTv2.setTextColor(ContextCompat.getColor(chatTypeTv2.getContext(),R.color.colorMainTab));
chatTypeTv2.setTextColor(ContextCompat.getColor(chatTypeTv2.getContext(), R.color.colorMainTab));
break;
case MainConversationListAdapter.FILTER_OFFLINE:
chatTypeImg3.setImageResource(R.mipmap.ic_chat_type_select);
chatTypeTv3.setTextColor(ContextCompat.getColor(chatTypeTv3.getContext(),R.color.colorMainTab));
chatTypeTv3.setTextColor(ContextCompat.getColor(chatTypeTv3.getContext(), R.color.colorMainTab));
break;
case MainConversationListAdapter.FILTER_READ:
chatTypeImg4.setImageResource(R.mipmap.ic_chat_type_select);
chatTypeTv4.setTextColor(ContextCompat.getColor(chatTypeTv4.getContext(),R.color.colorMainTab));
chatTypeTv4.setTextColor(ContextCompat.getColor(chatTypeTv4.getContext(), R.color.colorMainTab));
break;
case MainConversationListAdapter.FILTER_UNREAD:
chatTypeImg5.setImageResource(R.mipmap.ic_chat_type_select);
chatTypeTv5.setTextColor(ContextCompat.getColor(chatTypeTv5.getContext(),R.color.colorMainTab));
chatTypeTv5.setTextColor(ContextCompat.getColor(chatTypeTv5.getContext(), R.color.colorMainTab));
break;
}
}
@Override
public void onClick(android.view.View v) {
if (v.getId()==R.id.chatTypeImg1){
mResultCallBack.callBack(MainConversationListAdapter.FILTER_ALL,chatTypeTv1.getText().toString());
}else if (v.getId()==R.id.chatTypeImg2){
mResultCallBack.callBack(MainConversationListAdapter.FILTER_ONLINE,chatTypeTv2.getText().toString());
}else if (v.getId()==R.id.chatTypeImg3){
mResultCallBack.callBack(MainConversationListAdapter.FILTER_OFFLINE,chatTypeTv3.getText().toString());
}else if (v.getId()==R.id.chatTypeImg4){
mResultCallBack.callBack(MainConversationListAdapter.FILTER_READ,chatTypeTv4.getText().toString());
}else if (v.getId()==R.id.chatTypeImg5){
mResultCallBack.callBack(MainConversationListAdapter.FILTER_UNREAD,chatTypeTv5.getText().toString());
if (v.getId() == R.id.chatTypeImg1) {
mResultCallBack.callBack(MainConversationListAdapter.FILTER_ALL, chatTypeTv1.getText().toString());
} else if (v.getId() == R.id.chatTypeImg2) {
mResultCallBack.callBack(MainConversationListAdapter.FILTER_ONLINE, chatTypeTv2.getText().toString());
} else if (v.getId() == R.id.chatTypeImg3) {
mResultCallBack.callBack(MainConversationListAdapter.FILTER_OFFLINE, chatTypeTv3.getText().toString());
} else if (v.getId() == R.id.chatTypeImg4) {
mResultCallBack.callBack(MainConversationListAdapter.FILTER_READ, chatTypeTv4.getText().toString());
} else if (v.getId() == R.id.chatTypeImg5) {
mResultCallBack.callBack(MainConversationListAdapter.FILTER_UNREAD, chatTypeTv5.getText().toString());
}
dismiss();
}
public interface ResultCallBack {
void callBack(int i,String string);
void callBack(int i, String string);
}
}

View File

@@ -2,7 +2,8 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="360dp"
android:id="@+id/root"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/shape_white">
@@ -10,8 +11,8 @@
android:id="@+id/chatTypeTv1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginStart="24dp"
android:layout_marginTop="22dp"
android:layout_weight="1"
android:text="@string/all_chats"
android:textColor="#777777"
@@ -26,6 +27,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="20dp"
android:padding="5dp"
android:src="@mipmap/ic_chat_type_unselect"
app:layout_constraintBottom_toBottomOf="@+id/chatTypeTv1"
app:layout_constraintEnd_toEndOf="parent"
@@ -37,8 +39,8 @@
android:id="@+id/chatTypeTv2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginStart="24dp"
android:layout_marginTop="22dp"
android:layout_weight="1"
android:text="@string/online_only"
android:textColor="#777777"
@@ -51,6 +53,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:src="@mipmap/ic_chat_type_unselect"
app:layout_constraintBottom_toBottomOf="@+id/chatTypeTv2"
app:layout_constraintEnd_toEndOf="@+id/chatTypeImg1"
@@ -61,8 +64,8 @@
android:id="@+id/chatTypeTv3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginStart="24dp"
android:layout_marginTop="22dp"
android:layout_weight="1"
android:text="@string/offline_only"
android:textColor="#777777"
@@ -75,6 +78,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:src="@mipmap/ic_chat_type_unselect"
app:layout_constraintBottom_toBottomOf="@+id/chatTypeTv3"
app:layout_constraintEnd_toEndOf="@+id/chatTypeImg1"
@@ -85,8 +89,8 @@
android:id="@+id/chatTypeTv4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginStart="24dp"
android:layout_marginTop="22dp"
android:layout_weight="1"
android:text="@string/read_only"
android:textColor="#777777"
@@ -99,6 +103,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:src="@mipmap/ic_chat_type_unselect"
app:layout_constraintBottom_toBottomOf="@+id/chatTypeTv4"
app:layout_constraintEnd_toEndOf="@+id/chatTypeImg1"
@@ -109,8 +114,8 @@
android:id="@+id/chatTypeTv5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginStart="24dp"
android:layout_marginTop="22dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:text="@string/unread_only"
@@ -125,6 +130,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="5dp"
android:src="@mipmap/ic_chat_type_unselect"
app:layout_constraintBottom_toBottomOf="@+id/chatTypeTv5"
app:layout_constraintEnd_toEndOf="@+id/chatTypeImg1"

View File

@@ -1477,8 +1477,8 @@ Limited ride And limited avatar frame</string>
<string name="message_chat_msg_read_tip">[Read]</string>
<string name="message_chat_msg_unread_tip">[Unread]</string>
<string name="all_chats">All Chats</string>
<string name="online_only">Show Online Only</string>
<string name="offline_only">Show Offline Only</string>
<string name="read_only">Show Read Only</string>
<string name="unread_only">Show Unread Only</string>
<string name="online_only">Show Online </string>
<string name="offline_only">Show Offline </string>
<string name="read_only">Show Read </string>
<string name="unread_only">Show Unread </string>
</resources>

View File

@@ -1415,8 +1415,8 @@ Limited ride And limited avatar frame</string>
<string name="message_chat_msg_read_tip">[Read]</string>
<string name="message_chat_msg_unread_tip">[Unread]</string>
<string name="all_chats">All Chats</string>
<string name="online_only">Show Online Only</string>
<string name="offline_only">Show Offline Only</string>
<string name="read_only">Show Read Only</string>
<string name="unread_only">Show Unread Only</string>
<string name="online_only">Show Online </string>
<string name="offline_only">Show Offline </string>
<string name="read_only">Show Read </string>
<string name="unread_only">Show Unread </string>
</resources>