Selaa lähdekoodia

1、同步消息未读数;

yzs 4 vuotta sitten
vanhempi
commit
9c82b7737b

+ 17 - 0
app/src/main/java/com/shanp/youqi/app/fragment/ChatMessageListFragment.java

@@ -46,6 +46,7 @@ import com.shanp.youqi.common.utils.StatusBarUtils;
 import com.shanp.youqi.common.vo.im.ConversationListVo;
 import com.shanp.youqi.common.vo.im.ConversationListVo;
 import com.shanp.youqi.common.widget.UQCarouselAvatarView;
 import com.shanp.youqi.common.widget.UQCarouselAvatarView;
 import com.shanp.youqi.core.config.C;
 import com.shanp.youqi.core.config.C;
+import com.shanp.youqi.core.event.IMReadMsgEvent;
 import com.shanp.youqi.core.event.IMReceivedMessageEvent;
 import com.shanp.youqi.core.event.IMReceivedMessageEvent;
 import com.shanp.youqi.core.event.IMSendMessageEvent;
 import com.shanp.youqi.core.event.IMSendMessageEvent;
 import com.shanp.youqi.core.event.LogOutEvent;
 import com.shanp.youqi.core.event.LogOutEvent;
@@ -380,6 +381,22 @@ public class ChatMessageListFragment extends UChatFragment implements View.OnCli
     }
     }
 
 
     private void initListener() {
     private void initListener() {
+        register(RxBus.get().toFlowable(IMReadMsgEvent.class), new EventSubscriber<IMReadMsgEvent>() {
+            @Override
+            public void onReceive(IMReadMsgEvent event) {
+                if (rongImIsConnect() && !TextUtils.isEmpty(event.getId())) {
+                    List<ConversationListVo> data = mAdapter.getData();
+                    for (int i = 0; i < data.size(); i++) {
+                        String targetId = data.get(i).getConversation().getTargetId();
+                        if (targetId.equals(event.getId())) {
+                            notifyItemChanged(i, 444);
+                            break;
+                        }
+                    }
+                }
+            }
+        });
+
         register(RxBus.get().toFlowable(IMReceivedMessageEvent.class), new EventSubscriber<IMReceivedMessageEvent>() {
         register(RxBus.get().toFlowable(IMReceivedMessageEvent.class), new EventSubscriber<IMReceivedMessageEvent>() {
             @Override
             @Override
             public void onReceive(IMReceivedMessageEvent event) {
             public void onReceive(IMReceivedMessageEvent event) {

+ 11 - 0
app/src/main/java/com/shanp/youqi/app/fragment/MainFragment.java

@@ -34,6 +34,7 @@ import com.shanp.youqi.common.widget.NoScrollViewPager;
 import com.shanp.youqi.common.widget.ViewPagerAdapter;
 import com.shanp.youqi.common.widget.ViewPagerAdapter;
 import com.shanp.youqi.core.account.UserCore;
 import com.shanp.youqi.core.account.UserCore;
 import com.shanp.youqi.core.config.C;
 import com.shanp.youqi.core.config.C;
+import com.shanp.youqi.core.event.IMReadMsgEvent;
 import com.shanp.youqi.core.event.IMReceivedMessageEvent;
 import com.shanp.youqi.core.event.IMReceivedMessageEvent;
 import com.shanp.youqi.core.event.LogOutEvent;
 import com.shanp.youqi.core.event.LogOutEvent;
 import com.shanp.youqi.core.event.LoginSuccessEvent;
 import com.shanp.youqi.core.event.LoginSuccessEvent;
@@ -397,9 +398,19 @@ public class MainFragment extends UChatFragment {
                 return message != null;
                 return message != null;
             }
             }
         });
         });
+        register(RxBus.get().toFlowable(IMReadMsgEvent.class), new EventSubscriber<IMReadMsgEvent>() {
+            @Override
+            public void onReceive(IMReadMsgEvent event) {
+                super.onReceive(event);
+                if (!TextUtils.isEmpty(event.getId())) {
+                    refreshUnreadMessage();
+                }
+            }
+        });
     }
     }
 
 
     public void refreshUnreadMessage() {
     public void refreshUnreadMessage() {
+        if (!AppManager.get().isConnectRongCloud()) return;
         RongIMClient.getInstance().getUnreadCount(new RongIMClient.ResultCallback<Integer>() {
         RongIMClient.getInstance().getUnreadCount(new RongIMClient.ResultCallback<Integer>() {
             @Override
             @Override
             public void onSuccess(Integer integer) {
             public void onSuccess(Integer integer) {

+ 22 - 6
uchat_common/src/main/java/com/shanp/youqi/common/utils/ViewHideShowUtils.kt

@@ -3,6 +3,8 @@ package com.shanp.youqi.common.utils
 import android.animation.Animator
 import android.animation.Animator
 import android.animation.ValueAnimator
 import android.animation.ValueAnimator
 import android.view.View
 import android.view.View
+import android.view.animation.Interpolator
+import android.view.animation.LinearInterpolator
 import com.shanp.youqi.common.anim.ObjectAnimatorAssist
 import com.shanp.youqi.common.anim.ObjectAnimatorAssist
 
 
 /**
 /**
@@ -11,11 +13,20 @@ import com.shanp.youqi.common.anim.ObjectAnimatorAssist
  */
  */
 object ViewHideShowUtils {
 object ViewHideShowUtils {
 
 
-    fun performAnim(view: View, from: Int, to: Int, animationEnd: () -> Unit) {
+    /**
+     * 给View 做
+     * view 做动画的 view
+     * from 起始值
+     * to 目标值
+     * duration 动画时长
+     * interpolator 插值器
+     * isRL 是都左右变化动画 默认做上下变化动画
+     */
+    fun performAnim(view: View, from: Int, to: Int, duration: Long = 333, interpolator: Interpolator = LinearInterpolator(), isRL: Boolean = false, animationEnd: () -> Unit) {
 
 
         //属性动画对象
         //属性动画对象
         val va = ValueAnimator.ofInt(from, to)
         val va = ValueAnimator.ofInt(from, to)
-
+        va.interpolator = interpolator
         va.addListener(object : ObjectAnimatorAssist.SimpleAnimatorListener() {
         va.addListener(object : ObjectAnimatorAssist.SimpleAnimatorListener() {
             override fun onAnimationEnd(animation: Animator?) {
             override fun onAnimationEnd(animation: Animator?) {
                 super.onAnimationEnd(animation)
                 super.onAnimationEnd(animation)
@@ -23,12 +34,17 @@ object ViewHideShowUtils {
             }
             }
         })
         })
         va.addUpdateListener { valueAnimator -> //获取当前的height值
         va.addUpdateListener { valueAnimator -> //获取当前的height值
-            val h = valueAnimator.animatedValue as Int
-            //动态更新view的高度
-            view.layoutParams.height = h
+            val value = valueAnimator.animatedValue as Int
+            if (isRL) {
+                //动态更新view的高度
+                view.layoutParams.width = value
+            } else {
+                //动态更新view的高度
+                view.layoutParams.height = value
+            }
             view.requestLayout()
             view.requestLayout()
         }
         }
-        va.duration = 333
+        va.duration = duration
         //开始动画
         //开始动画
         va.start()
         va.start()
     }
     }

+ 18 - 0
uchat_core/src/main/java/com/shanp/youqi/core/event/IMReadMsgEvent.java

@@ -0,0 +1,18 @@
+package com.shanp.youqi.core.event;
+
+/**
+ * yzs
+ * 11/26/20.
+ * 同步已读消息event
+ */
+public class IMReadMsgEvent {
+    private String id;
+
+    public IMReadMsgEvent(String id) {
+        this.id = id;
+    }
+
+    public String getId() {
+        return id;
+    }
+}

+ 30 - 1
uchat_im/src/main/java/com/shanp/youqi/im/adapter/MessageListAdapter.java

@@ -35,6 +35,7 @@ import io.reactivex.Observable;
 import io.reactivex.disposables.Disposable;
 import io.reactivex.disposables.Disposable;
 import io.reactivex.functions.Function;
 import io.reactivex.functions.Function;
 import io.reactivex.internal.disposables.ListCompositeDisposable;
 import io.reactivex.internal.disposables.ListCompositeDisposable;
+import io.rong.imlib.RongIMClient;
 import io.rong.imlib.model.Conversation;
 import io.rong.imlib.model.Conversation;
 import io.rong.imlib.model.MessageContent;
 import io.rong.imlib.model.MessageContent;
 import io.rong.imlib.model.UnknownMessage;
 import io.rong.imlib.model.UnknownMessage;
@@ -89,15 +90,43 @@ public class MessageListAdapter extends BaseQuickAdapter<ConversationListVo, Bas
                 Conversation conversation = vo.getConversation();
                 Conversation conversation = vo.getConversation();
                 if (conversation == null) return;
                 if (conversation == null) return;
                 int unreadMessageCount = conversation.getUnreadMessageCount();
                 int unreadMessageCount = conversation.getUnreadMessageCount();
+                TextView tvCount = helper.getView(R.id.tv_item_msg_count);
                 String unreadCountString = String.valueOf(unreadMessageCount);
                 String unreadCountString = String.valueOf(unreadMessageCount);
                 if (unreadMessageCount > 99) unreadCountString = "99+";
                 if (unreadMessageCount > 99) unreadCountString = "99+";
-                TextView tvCount = helper.getView(R.id.tv_item_msg_count);
                 tvCount.setText(unreadCountString);
                 tvCount.setText(unreadCountString);
                 tvCount.setVisibility(unreadMessageCount > 0 ? View.VISIBLE : View.INVISIBLE);
                 tvCount.setVisibility(unreadMessageCount > 0 ? View.VISIBLE : View.INVISIBLE);
+            } else if (i == 444) {
+                Conversation conversation = vo.getConversation();
+                if (conversation == null) return;
+                TextView tvCount = helper.getView(R.id.tv_item_msg_count);
+                getUnReadCount(conversation.getConversationType(), conversation.getTargetId(), tvCount);
             }
             }
         }
         }
     }
     }
 
 
+    public void getUnReadCount(Conversation.ConversationType type, String id, TextView tvCount) {
+        if (!AppManager.get().isConnectRongCloud()) return;
+        RongIMClient.getInstance().getUnreadCount(type, id, new RongIMClient.ResultCallback<Integer>() {
+            @Override
+            public void onSuccess(Integer count) {
+                if (count != null) {
+                    String num;
+                    if (count > 99) {
+                        num = "99+";
+                    } else {
+                        num = "" + count;
+                    }
+                    tvCount.setText(num);
+                    tvCount.setVisibility(count > 0 ? View.VISIBLE : View.INVISIBLE);
+                }
+            }
+
+            @Override
+            public void onError(RongIMClient.ErrorCode errorCode) {
+            }
+        });
+    }
+
     @Override
     @Override
     protected void convert(@NonNull BaseViewHolder helper, ConversationListVo vo) {
     protected void convert(@NonNull BaseViewHolder helper, ConversationListVo vo) {
         Conversation conversation = vo.getConversation();
         Conversation conversation = vo.getConversation();

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

@@ -9,6 +9,7 @@ import com.alibaba.android.arouter.launcher.ARouter
 import com.blankj.utilcode.util.FragmentUtils
 import com.blankj.utilcode.util.FragmentUtils
 import com.blankj.utilcode.util.KeyboardUtils
 import com.blankj.utilcode.util.KeyboardUtils
 import com.blankj.utilcode.util.ToastUtils
 import com.blankj.utilcode.util.ToastUtils
+import com.shanp.youqi.base.util.LogUtil
 import com.shanp.youqi.common.app.Route.RouterUrl
 import com.shanp.youqi.common.app.Route.RouterUrl
 import com.shanp.youqi.common.base.BaseDialogFragment
 import com.shanp.youqi.common.base.BaseDialogFragment
 import com.shanp.youqi.common.base.BaseViewHolder
 import com.shanp.youqi.common.base.BaseViewHolder
@@ -55,9 +56,13 @@ class ConversationDialog : BaseDialogFragment() {
         setOutCancel(true)
         setOutCancel(true)
     }
     }
 
 
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        ARouter.getInstance().inject(this)
+    }
 
 
     override fun convert(holder: BaseViewHolder, dialog: BaseDialogFragment?) {
     override fun convert(holder: BaseViewHolder, dialog: BaseDialogFragment?) {
-        ARouter.getInstance().inject(this)
+        LogUtil.d("聊天 id$targetId targetUserName$targetUserName targetHeadImg$targetHeadImg")
         if (TextUtils.isEmpty(targetId)) arguments?.getString("targetId")?.let { targetId = it }
         if (TextUtils.isEmpty(targetId)) arguments?.getString("targetId")?.let { targetId = it }
         if (TextUtils.isEmpty(targetUserName)) arguments?.getString("targetUserName")?.let { targetUserName = it }
         if (TextUtils.isEmpty(targetUserName)) arguments?.getString("targetUserName")?.let { targetUserName = it }
         if (TextUtils.isEmpty(targetHeadImg)) arguments?.getString("targetId")?.let { targetHeadImg = it }
         if (TextUtils.isEmpty(targetHeadImg)) arguments?.getString("targetId")?.let { targetHeadImg = it }
@@ -80,14 +85,14 @@ class ConversationDialog : BaseDialogFragment() {
                 if (height > 0) {
                 if (height > 0) {
                     if (currentHeight != upHeight) {
                     if (currentHeight != upHeight) {
                         currentHeight = upHeight
                         currentHeight = upHeight
-                        ViewHideShowUtils.performAnim(flContainer, downHeight, upHeight) {
+                        ViewHideShowUtils.performAnim(flContainer, downHeight, upHeight, 430) {
                             fragment?.rcvToBottom()
                             fragment?.rcvToBottom()
                         }
                         }
                     }
                     }
                 } else {
                 } else {
                     if (currentHeight != downHeight) {
                     if (currentHeight != downHeight) {
                         currentHeight = downHeight
                         currentHeight = downHeight
-                        ViewHideShowUtils.performAnim(flContainer, upHeight, downHeight) {
+                        ViewHideShowUtils.performAnim(flContainer, upHeight, downHeight, 430) {
                             fragment?.rcvToBottom()
                             fragment?.rcvToBottom()
                         }
                         }
                     }
                     }

+ 3 - 1
uchat_im/src/main/java/com/shanp/youqi/im/fragment/MessageListOnlyUserFragment.kt

@@ -10,6 +10,7 @@ import com.shanp.youqi.common.R2
 import com.shanp.youqi.common.base.UChatFragment
 import com.shanp.youqi.common.base.UChatFragment
 import com.shanp.youqi.common.vo.im.ConversationListVo
 import com.shanp.youqi.common.vo.im.ConversationListVo
 import com.shanp.youqi.common.widget.EmptyView
 import com.shanp.youqi.common.widget.EmptyView
+import com.shanp.youqi.core.event.IMReadMsgEvent
 import com.shanp.youqi.core.event.IMReceivedMessageEvent
 import com.shanp.youqi.core.event.IMReceivedMessageEvent
 import com.shanp.youqi.core.memory.AppManager
 import com.shanp.youqi.core.memory.AppManager
 import com.shanp.youqi.im.R
 import com.shanp.youqi.im.R
@@ -55,7 +56,7 @@ class MessageListOnlyUserFragment : UChatFragment() {
     private fun initRecyclerView() {
     private fun initRecyclerView() {
         binding.emptyView
         binding.emptyView
                 .setColorStyle(true)
                 .setColorStyle(true)
-                .setNoDataTitle("暂无聊天联系人")
+                .setNoDataTitle("暂无私信")
                 .setNoDataIconIds(R.drawable.empty_box_bright)
                 .setNoDataIconIds(R.drawable.empty_box_bright)
                 .setLayoutType(EmptyView.LayoutType.TYPE_LAYOUT_NO_DATA)
                 .setLayoutType(EmptyView.LayoutType.TYPE_LAYOUT_NO_DATA)
 
 
@@ -144,6 +145,7 @@ class MessageListOnlyUserFragment : UChatFragment() {
         RongIMClient.getInstance().clearMessagesUnreadStatus(conversationType, targetId,
         RongIMClient.getInstance().clearMessagesUnreadStatus(conversationType, targetId,
                 object : RongIMClient.ResultCallback<Boolean?>() {
                 object : RongIMClient.ResultCallback<Boolean?>() {
                     override fun onSuccess(aBoolean: Boolean?) {
                     override fun onSuccess(aBoolean: Boolean?) {
+                        RxBus.get().post(IMReadMsgEvent(targetId))
                     }
                     }
 
 
                     override fun onError(errorCode: RongIMClient.ErrorCode) {
                     override fun onError(errorCode: RongIMClient.ErrorCode) {

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

@@ -155,13 +155,13 @@ public class HNCXBottomView extends RelativeLayout implements View.OnClickListen
     public void showMsgCount(int count) {
     public void showMsgCount(int count) {
         if (tvMsgCount != null) {
         if (tvMsgCount != null) {
             tvMsgCount.setVisibility(count > 0 ? View.VISIBLE : View.GONE);
             tvMsgCount.setVisibility(count > 0 ? View.VISIBLE : View.GONE);
-            String i = count + "";
+            String num;
             if (count > 99) {
             if (count > 99) {
-                i = "99+";
+                num = "99+";
             } else {
             } else {
-                i = "" + count;
+                num = "" + count;
             }
             }
-            tvMsgCount.setText(i);
+            tvMsgCount.setText(num);
         }
         }
     }
     }