Bläddra i källkod

1、增加聊天室消息未读数;

yzs 4 år sedan
förälder
incheckning
5cd3f0a5c5

+ 20 - 0
uchat_common/src/main/res/drawable/common_bg_msg_unread_num.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+
+
+
+    <!-- 填充的颜色 -->
+    <solid android:color="#FF6968"/>
+
+
+
+
+    <!-- 设置按钮的四个角为弧形 -->
+    <!-- android:radius 弧形的半径 -->
+    <corners android:radius="9.5dp"/>
+
+     <!--边框粗细及颜色-->
+
+    <size android:width="14dp"
+        android:height="14dp"/>
+</shape>

+ 3 - 0
uchat_im/src/main/java/com/shanp/youqi/im/dialog/ConversationDialog.kt

@@ -58,6 +58,9 @@ class ConversationDialog : BaseDialogFragment() {
 
     override fun convert(holder: BaseViewHolder, dialog: BaseDialogFragment?) {
         ARouter.getInstance().inject(this)
+        if (TextUtils.isEmpty(targetId)) arguments?.getString("targetId")?.let { targetId = it }
+        if (TextUtils.isEmpty(targetUserName)) arguments?.getString("targetUserName")?.let { targetUserName = it }
+        if (TextUtils.isEmpty(targetHeadImg)) arguments?.getString("targetId")?.let { targetHeadImg = it }
         if (TextUtils.isEmpty(targetId)) {
             ToastUtils.showShort("数据异常,请稍后再试")
             this.dismiss()

+ 51 - 0
uchat_room/src/main/java/com/hncx/xxm/room/avroom/fragment/HNCXHomePartyRoomFragment.java

@@ -67,11 +67,15 @@ import com.hncx.xxm.room.widget.dialog.UserInfoDialog;
 import com.hncx.xxm.utils.HNCXImageLoadUtils;
 import com.netease.nim.uikit.common.util.sys.ScreenUtil;
 import com.netease.nimlib.sdk.msg.model.RecentContact;
+import com.shanp.youqi.base.rx.EventSubscriber;
+import com.shanp.youqi.base.rx.RxBus;
 import com.shanp.youqi.base.util.GsonUtil;
 import com.shanp.youqi.common.anim.ObjectAnimatorAssist;
 import com.shanp.youqi.common.app.Route.ARouterFun;
 import com.shanp.youqi.common.base.BaseDialogFragment;
 import com.shanp.youqi.core.config.C;
+import com.shanp.youqi.core.event.IMReceivedMessageEvent;
+import com.shanp.youqi.core.memory.AppManager;
 import com.shanp.youqi.core.utils.SP;
 import com.shanp.youqi.room.activity.RoomRankActivity;
 import com.shanp.youqi.room.config.AccompanyConstants;
@@ -152,6 +156,8 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.disposables.Disposable;
 import io.reactivex.functions.Consumer;
 import io.reactivex.schedulers.Schedulers;
+import io.rong.imlib.RongIMClient;
+import io.rong.imlib.model.Conversation;
 
 import static com.tongdaxing.xchat_core.im.custom.bean.IMCustomAttachment.CUSTOM_MSG_HEADER_TYPE_REMOVE_MSG_FILTER_CLOSE;
 import static com.tongdaxing.xchat_core.im.custom.bean.IMCustomAttachment.CUSTOM_MSG_HEADER_TYPE_REMOVE_MSG_FILTER_OPEN;
@@ -202,6 +208,7 @@ public class HNCXHomePartyRoomFragment extends HNCXBaseMvpFragment<IHomePartyVie
     private AnimatorSet animatorSet;
 
     private boolean messageListDialogIsShowing = false;
+    private EventSubscriber<IMReceivedMessageEvent> messageEventEventSubscriber;
 
     @Override
     public int getRootLayoutId() {
@@ -270,6 +277,9 @@ public class HNCXHomePartyRoomFragment extends HNCXBaseMvpFragment<IHomePartyVie
             }
         }
         setFloatEnterRoomRefreshHomeownerCharmApi();
+        if (AppManager.get().isConnectRongCloud()) {
+            refreshUnreadMessage();
+        }
     }
 
     // todo 魅力值。下个版本回滚,此接口不需要调用
@@ -1225,6 +1235,45 @@ public class HNCXHomePartyRoomFragment extends HNCXBaseMvpFragment<IHomePartyVie
         }
     }
 
+    /**
+     * 获取未读数
+     */
+    public void refreshUnreadMessage() {
+        disposeMsg();
+        messageEventEventSubscriber = new EventSubscriber<IMReceivedMessageEvent>() {
+            @Override
+            public void onReceive(IMReceivedMessageEvent imReceivedMessageEvent) {
+                super.onReceive(imReceivedMessageEvent);
+                getUnreadCount();
+            }
+        };
+        RxBus.get().toFlowable(IMReceivedMessageEvent.class).subscribe(messageEventEventSubscriber);
+        getUnreadCount();
+    }
+
+    private void getUnreadCount() {
+        if (!AppManager.get().isConnectRongCloud()) return;
+        RongIMClient.getInstance().getUnreadCount(new RongIMClient.ResultCallback<Integer>() {
+            @Override
+            public void onSuccess(Integer count) {
+                if (count != null) {
+                    gameBinding.bottomView.showMsgCount(count);
+                }
+            }
+
+            @Override
+            public void onError(RongIMClient.ErrorCode errorCode) {
+            }
+        }, Conversation.ConversationType.PRIVATE);
+    }
+
+    private void disposeMsg() {
+        if (messageEventEventSubscriber != null) {
+            messageEventEventSubscriber.dispose();
+            messageEventEventSubscriber = null;
+        }
+    }
+
     //------------------------------IShareCoreClient----------------------------------
     @CoreEvent(coreClientClass = IShareCoreClient.class)
     public void onShareRoom() {
@@ -1243,6 +1292,7 @@ public class HNCXHomePartyRoomFragment extends HNCXBaseMvpFragment<IHomePartyVie
 
     @Override
     public void onDestroyView() {
+        disposeMsg();
         super.onDestroyView();
         releaseView();
         isShowing = false;
@@ -2182,6 +2232,7 @@ public class HNCXHomePartyRoomFragment extends HNCXBaseMvpFragment<IHomePartyVie
                 @Override
                 public void onHidden() {
                     messageListDialogIsShowing = false;
+                    getUnreadCount();
                 }
             }).show(getChildFragmentManager());
 //            ARouterFun.startIMMain();

+ 19 - 1
uchat_room/src/main/java/com/hncx/xxm/room/avroom/widget/HNCXBottomView.java

@@ -32,6 +32,7 @@ public class HNCXBottomView extends RelativeLayout implements View.OnClickListen
     private ImageView faceLayout;
     private FrameLayout rlMsg;
     private ImageView ivMsgMark;
+    private TextView tvMsgCount;
     private boolean micInListOption;
     private ImageView iconRoomMicInList;
 
@@ -63,6 +64,7 @@ public class HNCXBottomView extends RelativeLayout implements View.OnClickListen
         rlMsg = findViewById(R.id.rl_room_msg);
         iconRoomMicInList = findViewById(R.id.icon_room_mic_in_list);
         ivMsgMark = findViewById(R.id.iv_room_msg_mark);
+        tvMsgCount = findViewById(R.id.tv_msg_count);
 
         iconRoomMicInList.setOnClickListener(this);
         openMic.setOnClickListener(this);
@@ -148,6 +150,22 @@ public class HNCXBottomView extends RelativeLayout implements View.OnClickListen
     }
 
     /**
+     * 新私聊消息提示
+     */
+    public void showMsgCount(int count) {
+        if (tvMsgCount != null) {
+            tvMsgCount.setVisibility(count > 0 ? View.VISIBLE : View.GONE);
+            String i = count + "";
+            if (count > 99) {
+                i = "99+";
+            } else {
+                i = "" + count;
+            }
+            tvMsgCount.setText(i);
+        }
+    }
+
+    /**
      * 公屏发言按钮状态
      */
     public void setInputMsgBtnEnable(boolean enable) {
@@ -180,7 +198,7 @@ public class HNCXBottomView extends RelativeLayout implements View.OnClickListen
             if (wrapper != null) {
                 wrapper.onRemoteMuteBtnClick();
             }
-        }  else if (id == R.id.icon_room_mic_in_list) {
+        } else if (id == R.id.icon_room_mic_in_list) {
             if (wrapper != null) {
                 wrapper.onBuShowMicInList();
             }

+ 15 - 0
uchat_room/src/main/res/layout/layout_bottom_view.xml

@@ -80,12 +80,27 @@
             android:visibility="gone"
             tools:visibility="visible" />
 
+
         <ImageView
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:background="@drawable/ic_room_msg"
             android:contentDescription="@null" />
 
+        <TextView
+            android:id="@+id/tv_msg_count"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="end"
+            android:background="@drawable/common_bg_msg_unread_num"
+            android:gravity="center"
+            android:paddingStart="4dp"
+            android:paddingEnd="4dp"
+            android:text="12"
+            android:textColor="@color/white"
+            android:textSize="10sp"
+            android:visibility="gone"
+            tools:visibility="visible" />
     </FrameLayout>
 
     <ImageView