Przeglądaj źródła

1、修复列表出现重复的问题;

yzs 4 lat temu
rodzic
commit
4906fd0e74

+ 3 - 2
app/src/main/java/com/shanp/youqi/app/adapter/UChatMessageListAdapter.kt

@@ -177,9 +177,10 @@ class UChatMessageListAdapter(data: List<ConversationListVo>?)
             tvMessageCount.visibility = View.INVISIBLE
             return
         }
-        tvMessageCount.text = unreadCount.toString()
+        val num: String = if (unreadCount > 99) "99+" else "" + unreadCount
+        tvMessageCount.text = num
         tvMessageCount.visibility = View.VISIBLE
-        val length: Int = unreadCount.toString().length
+        val length: Int = num.length
         var width = ViewGroup.LayoutParams.WRAP_CONTENT
         when (length) {
             1 -> width = WIDTH_16

+ 357 - 102
app/src/main/java/com/shanp/youqi/app/fragment/ChatMessageListFragmentKotlin.kt

@@ -1,18 +1,23 @@
 package com.shanp.youqi.app.fragment
 
+import android.annotation.SuppressLint
 import android.content.Intent
+import android.os.Handler
 import android.text.TextUtils
 import android.view.View
 import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.TextView
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
-import com.blankj.utilcode.util.ActivityUtils
-import com.blankj.utilcode.util.ClickUtils
-import com.blankj.utilcode.util.TimeUtils
+import com.blankj.utilcode.util.*
+import com.blankj.utilcode.util.NetworkUtils.OnNetworkStatusChangedListener
 import com.chad.library.adapter.base.BaseQuickAdapter
 import com.shanp.youqi.R
 import com.shanp.youqi.app.activity.InteractiveMessageListActivity
+import com.shanp.youqi.app.activity.UQChatMsgActivity
 import com.shanp.youqi.app.adapter.UChatMessageListAdapter
+import com.shanp.youqi.base.image.CustomTransformation
 import com.shanp.youqi.base.image.ImageLoader
 import com.shanp.youqi.base.rx.EventSubscriber
 import com.shanp.youqi.base.rx.RxBus
@@ -30,9 +35,11 @@ import com.shanp.youqi.core.event.IMReceivedMessageEvent
 import com.shanp.youqi.core.event.IMSendMessageEvent
 import com.shanp.youqi.core.im.Constant
 import com.shanp.youqi.core.im.IMCore
+import com.shanp.youqi.core.im.vo.RongLikeImageCardVo
 import com.shanp.youqi.core.main.IMainClent
 import com.shanp.youqi.core.memory.AppManager
 import com.shanp.youqi.core.model.IMCheckChat
+import com.shanp.youqi.core.model.IMUnreadInfo
 import com.shanp.youqi.core.model.IMUserOnlineState
 import com.shanp.youqi.databinding.MainFragmentUqchatMsgKotlinBinding
 import com.shanp.youqi.databinding.MainItemMessageHeaderKotlinBinding
@@ -46,38 +53,68 @@ import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
-import java.text.SimpleDateFormat
 import java.util.*
+import java.util.regex.Pattern
 import kotlin.concurrent.thread
 
 /**
  * yzs
  * 11/27/20.
+ * 消息列表
  */
 class ChatMessageListFragmentKotlin : UChatFragment() {
 
-    var unreadCount: Int = 0
+    private lateinit var binding: MainFragmentUqchatMsgKotlinBinding
+    private lateinit var headerBinding: MainItemMessageHeaderKotlinBinding
 
+
+    /**
+     * 获取消息列表 需要传入最后一条消息发送的时间戳
+     */
     private var timeStamp = 0L
 
+    /**
+     * 用于标记刷新列表在线状态的时间间隔记录
+     */
     private var lastRefreshTime = 0L
 
-
-    private val sdf: SimpleDateFormat by lazy { TimeUtils.getSafeDateFormat("yyyy-MM-dd") }
-    private lateinit var binding: MainFragmentUqchatMsgKotlinBinding
-    private lateinit var headerBinding: MainItemMessageHeaderKotlinBinding
-
+    /**
+     * 消息列表 adapter
+     */
     private val adapter = UChatMessageListAdapter(null)
 
+    /**
+     * 刷新 底部tab 的接口类
+     */
     private var mainClient: IMainClent? = null
 
+    /**
+     * 检查通知打开的 helperUtils
+     */
     private val mHelper: NotificationHelper by lazy { NotificationHelper(mContext) }
 
+    /**
+     * 发现老板头像轮播动画时间间隔
+     */
+    private val avatarAnimationTime: Long = 1500
+
+    /**
+     * 轮播 index
+     */
+    private var avatarIndex = 0
+
+    /**
+     * 头像集合
+     */
+    private val avatars = mutableListOf<String>()
+
     override fun getLayoutId(): Int = R.layout.main_fragment_uqchat_msg_kotlin
 
     override fun initEventAndData(view: View) {
         binding = MainFragmentUqchatMsgKotlinBinding.bind(view)
+        // 用户 MainActivity 加载时获取接口实例
         if (mContext.javaClass.simpleName.contains("MainActivity")) mainClient = mContext as IMainClent
+        NetworkUtils.registerNetworkStatusChangedListener(netWorkStatusChangedListener)
         initRecyclerView()
         initListener()
         getSystemConversation()
@@ -110,6 +147,7 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
 
 
         setOnClickListener(viewOnClickListener,
+                // 头部 view
                 headerBinding.clYqConversationLayout,
                 headerBinding.rlFindTheBossLayout,
                 headerBinding.rlPraiseSelfLayout,
@@ -124,6 +162,7 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
                 headerBinding.tvVisitor,
                 headerBinding.tvOpenNotify,
 
+                // 头像
                 binding.civAvatar
         )
 
@@ -169,44 +208,9 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
         }
     }
 
-    private fun openNotificationSetting() {
-        if (!mHelper.isNotificationEnabled) {
-            mHelper.openNotificationSetting()
-            return
-        }
-        if (!mHelper.isOpenChannel(NotificationHelper.YQ_CHAT_CHANNEL)) {
-            mHelper.openChannelSetting(NotificationHelper.YQ_CHAT_CHANNEL)
-        }
-    }
-
-    private fun checkNotifyEnable() {
-        var isEnabled = false
-        val enabled = mHelper.isNotificationEnabled
-        val openChannel = mHelper.isOpenChannel(NotificationHelper.YQ_CHAT_CHANNEL)
-        if (enabled && openChannel) isEnabled = true
-        headerBinding.rlOpenNotifyLayout.visibility = if (isEnabled) View.GONE else View.VISIBLE
-    }
-
-    private fun visitor() {
-        val userMine = AppManager.get().userMine
-        var playerAuthentication = userMine.playerAuthentication
-        if (playerAuthentication == null) playerAuthentication = ""
-        val isPlayer = playerAuthentication == "1"
-        if (!isPlayer && !userMine.isExplotionLight) {
-            PrivilegeDialog(mContext, C.pay.SN_EXPOLSION_LIGHT, null).show()
-        } else ARouterFun.startUserVisitor()
-    }
-
-    private fun likeMe() {
-        if (!AppManager.get().userMine.isExplotionLight) {
-            PrivilegeDialog(mContext, C.pay.SN_EXPOLSION_LIGHT, null).show()
-            return
-        }
-        ARouterFun.startUserLike(3)
-    }
-
 
     private fun initListener() {
+        // 读消息监听
         register(RxBus.get().toFlowable(IMReceivedMessageEvent::class.java), object : EventSubscriber<IMReceivedMessageEvent>() {
             override fun onReceive(event: IMReceivedMessageEvent) {
                 if (!AppManager.get().isConnectRongCloud) return
@@ -220,6 +224,7 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
             }
         })
 
+        // 发消息监听
         register(RxBus.get().toFlowable(IMSendMessageEvent::class.java), object : EventSubscriber<IMSendMessageEvent>() {
             override fun onReceive(event: IMSendMessageEvent) {
                 super.onReceive(event)
@@ -227,6 +232,7 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
             }
         })
 
+        // 融云连接成功监听
         register(RxBus.get().toFlowable(IMConnectSuccessEvent::class.java), object : EventSubscriber<IMConnectSuccessEvent?>() {
             override fun onReceive(e: IMConnectSuccessEvent?) {
                 super.onReceive(e)
@@ -235,47 +241,31 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
             }
         })
 
+        // 列表加载更多监听
         binding.srl.setOnLoadMoreListener {
             getPrivateConversationList()
         }
 
+        // 列表点击监听 不包含小助手
         adapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { _, _, position ->
             adapter.getItem(position)?.conversation?.let {
                 startListConversation(it, position)
             }
         }
 
+        // 长按删除监听
         adapter.onItemLongClickListener = BaseQuickAdapter.OnItemLongClickListener { _, _, position ->
             adapter.getItem(position)?.conversation?.let {
                 showAgainDeleteConversationDialog(it, position)
+                return@OnItemLongClickListener true
             }
-            true
+            false
         }
     }
 
-    private fun showAgainDeleteConversationDialog(item: Conversation, position: Int) {
-        CustomDelDialog().setIsSelf(true)
-                .setListener { isDel: Boolean, isSelf: Boolean ->
-                    if (isDel && isSelf) {
-                        removeConversation(item)
-                        adapter.remove(position)
-                    }
-                }.show(childFragmentManager)
-    }
-
-    // 从数据库中删除会话
-    private fun removeConversation(item: Conversation) {
-        IMChatUtils.removeConversation(
-                item.conversationType,
-                item.targetId, object : RongIMClient.ResultCallback<Boolean>() {
-            override fun onSuccess(b: Boolean) {
-                if (b) IMChatUtils.clearMessage(item.conversationType, item.targetId, null)
-            }
-
-            override fun onError(errorCode: RongIMClient.ErrorCode) {}
-        })
-    }
-
+    /**
+     * ------------ 处理消息 --------------------------------------
+     */
     private fun disposeMessage(message: Message) {
         GlobalScope.launch {
             withContext(Dispatchers.IO) {
@@ -308,6 +298,9 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
         })
     }
 
+    /**
+     * 单独方法获取系统会话
+     */
     private fun getSystemConversation() {
         RongIMClient.getInstance().getConversation(Conversation.ConversationType.SYSTEM,
                 C.im.ROMG_SYSTEM_NOTICE, object : RongIMClient.ResultCallback<Conversation?>() {
@@ -316,7 +309,7 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
                     val latestMessage = conversation.latestMessage
                     headerBinding.tvYqLastMsg.text = IMChatUtils.checkMessageNotificationType(latestMessage)
                     adapter.setUnReadCount(headerBinding.tvYqMsgCount, it.unreadMessageCount)
-                    headerBinding.tvYqTime.text = TimeUtils.millis2String(it.sentTime, sdf)
+                    headerBinding.tvYqTime.text = TimeUtils.millis2String(it.sentTime, TimeUtils.getSafeDateFormat("yyyy-MM-dd"))
                 }
             }
 
@@ -326,14 +319,29 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
         })
     }
 
+    /**
+     * 获取列表私聊会话 分页获取
+     */
     private fun getPrivateConversationList() {
         GlobalScope.launch(Dispatchers.Main) {
             RongIMClient.getInstance().getConversationListByPage(
                     object : RongIMClient.ResultCallback<MutableList<Conversation>?>() {
                         override fun onSuccess(conversations: MutableList<Conversation>?) {
+                            // TODO 可优化
                             if (conversations != null) {
                                 timeStamp = conversations.last().sentTime
                                 val formatConversation = DataFormat.imConversationList(conversations)
+
+                                // 处理数据重复的问题
+                                val data = adapter.data
+                                for (c in formatConversation) {
+                                    if (data.size <= 0) break
+                                    val existedVOIndex = data.indexOfFirst { c.conversation.targetId == it.conversation.targetId }
+                                    if (existedVOIndex > -1) {
+                                        adapter.remove(existedVOIndex)
+                                    }
+                                }
+
                                 adapter.addData(formatConversation)
                                 binding.srl.setEnableLoadMore(conversations.size >= 10)
                                 checkList()
@@ -359,28 +367,20 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
         }
     }
 
-    // 加载用户头像
-    private fun loadUserAvatar() {
-        val loginInfo = AppManager.get().userLoginInfo
-        var url = ""
-        loginInfo?.let { url = it.headImg }
-        ImageLoader.get().loadAvatar(url, binding.civAvatar, R.drawable.ic_yq_tourists_avatar, R.drawable.ic_yq_tourists_avatar)
-    }
-
-    // 启动系统会话
+    /**
+     * 启动系统会话
+     */
     private fun startSystemConversation() {
-        startConversation(
-                Conversation.ConversationType.SYSTEM,
-                C.im.ROMG_SYSTEM_NOTICE,
-                "友期小助手",
-                "")
+        startConversation(Conversation.ConversationType.SYSTEM, C.im.ROMG_SYSTEM_NOTICE, "友期小助手", "")
         thread {
             clearMessagesUnreadStatus(Conversation.ConversationType.SYSTEM, C.im.ROMG_SYSTEM_NOTICE)
             getSystemConversation()
         }
     }
 
-    // 启动私聊会话
+    /**
+     * 启动私聊会话
+     */
     private fun startListConversation(conversation: Conversation, position: Int) {
         if (checkPrivateChat(childFragmentManager)) return
         startConversation(conversation.conversationType,
@@ -394,6 +394,7 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
 
     private fun startConversation(conversationType: Conversation.ConversationType,
                                   targetId: String, targetUserName: String?, targetHeadImg: String?) {
+        // 确保 targetId 不为 null 或者 "" ,用于发送消息
         if (TextUtils.isEmpty(targetId)) return
         var name = targetUserName
         var headImg = targetHeadImg
@@ -405,10 +406,11 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
                 name,
                 headImg,
                 Constant.conversation.ENTRY_TYPE_DEFAULT)
-
     }
 
-    // 清除会话未读数,刷新首页tab未读数
+    /**
+     * 清除会话未读数,刷新首页tab未读数
+     */
     private fun clearMessagesUnreadStatus(type: Conversation.ConversationType, targetId: String) {
         RongIMClient.getInstance().clearMessagesUnreadStatus(type, targetId,
                 object : RongIMClient.ResultCallback<Boolean?>() {
@@ -422,25 +424,139 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
                 })
     }
 
-    // 局部刷新数据,加上 header
+    /**
+     *  统一局部刷新数据,加上 header
+     */
     private fun notifyItemChanged(position: Int, payload: Int) {
         adapter?.notifyItemChanged(position + adapter.headerLayoutCount, payload)
     }
 
+
+    /**
+     * --------------- header 点击处理 -------------------
+     */
+
+    private fun checkNotifyEnable() {
+        var isEnabled = false
+        val enabled = mHelper.isNotificationEnabled
+        val openChannel = mHelper.isOpenChannel(NotificationHelper.YQ_CHAT_CHANNEL)
+        if (enabled && openChannel) isEnabled = true
+        headerBinding.rlOpenNotifyLayout.visibility = if (isEnabled) View.GONE else View.VISIBLE
+    }
+
+    private fun openNotificationSetting() {
+        if (!mHelper.isNotificationEnabled) {
+            mHelper.openNotificationSetting()
+            return
+        }
+        if (!mHelper.isOpenChannel(NotificationHelper.YQ_CHAT_CHANNEL)) {
+            mHelper.openChannelSetting(NotificationHelper.YQ_CHAT_CHANNEL)
+        }
+    }
+
+    private fun visitor() {
+        val userMine = AppManager.get().userMine
+        var playerAuthentication = userMine.playerAuthentication
+        if (playerAuthentication == null) playerAuthentication = ""
+        val isPlayer = playerAuthentication == "1"
+        if (!isPlayer && !userMine.isExplotionLight) {
+            PrivilegeDialog(mContext, C.pay.SN_EXPOLSION_LIGHT, null).show()
+        } else {
+            ARouterFun.startUserVisitor()
+        }
+    }
+
+    private fun likeMe() {
+        if (!AppManager.get().userMine.isExplotionLight) {
+            PrivilegeDialog(mContext, C.pay.SN_EXPOLSION_LIGHT, null).show()
+        } else {
+            ARouterFun.startUserLike(3)
+        }
+    }
+
+    private fun showAgainDeleteConversationDialog(item: Conversation, position: Int) {
+        CustomDelDialog().setIsSelf(true)
+                .setListener { isDel: Boolean, isSelf: Boolean ->
+                    if (isDel && isSelf) {
+                        removeConversation(item)
+                        adapter.remove(position)
+                    }
+                }.show(childFragmentManager)
+    }
+
+    /**
+     * 从数据库中删除会话
+     */
+    private fun removeConversation(item: Conversation) {
+        IMChatUtils.removeConversation(
+                item.conversationType,
+                item.targetId, object : RongIMClient.ResultCallback<Boolean>() {
+            override fun onSuccess(b: Boolean) {
+                if (b) IMChatUtils.clearMessage(item.conversationType, item.targetId, null)
+            }
+
+            override fun onError(errorCode: RongIMClient.ErrorCode) {}
+        })
+    }
+
+    private fun loadUserAvatar() {
+        var url = ""
+        AppManager.get().userLoginInfo?.let { url = it.headImg }
+        ImageLoader.get().loadAvatar(url, binding.civAvatar, R.drawable.ic_yq_tourists_avatar, R.drawable.ic_yq_tourists_avatar)
+    }
+
     fun toTop() {
         binding.rcv.smoothScrollToPosition(0)
     }
 
     fun loginSuccess() {
+        IMCore.get().resetUnreadTime()
+        if (!isFragmentVisible) refresh()
+        binding.srl.setEnableLoadMore(true)
         timeStamp = 0
         lastRefreshTime = 0
         IMChatUtils.connect(AppManager.get().userLoginInfo.rongCloudToken)
+        headerBinding.davAvatar.clearView()
     }
 
     fun logOut() {
+        RongIMClient.getInstance().disconnect()
+        AppManager.get().isConnectRongCloud = false
+        binding.srl.finishLoadMore()
         timeStamp = 0
         lastRefreshTime = 0
+        mMessageHandler.removeMessages(2)
         adapter.setNewData(null)
+        headerBinding.davAvatar.clearView()
+    }
+
+    override fun onVisible() {
+        super.onVisible()
+        StatusBarUtils.statusBarDarkFont(mContext, true)
+        mainClient?.let {
+            it.setMainTabStyle(CommonConfig.FLAG_MSG, false, false, false, false)
+            loadUserAvatar()
+        }
+
+        if (AppManager.get().isLogin && RongIMClient.getInstance() == null) {
+            IMChatUtils.connect(AppManager.get().userLoginInfo.rongCloudToken)
+        }
+        setFindBossIsSow()
+        refresh()
+        checkList()
+        checkNotifyEnable()
+    }
+
+    override fun onHidden() {
+        super.onHidden()
+    }
+
+    override fun onDestroyView() {
+        adapter?.release()
+        mMessageHandler?.removeMessages(2)
+        mMessageHandler?.removeCallbacksAndMessages(null)
+        NetworkUtils.unregisterNetworkStatusChangedListener(netWorkStatusChangedListener)
+        super.onDestroyView()
     }
 
     private fun checkList() {
@@ -503,24 +619,163 @@ class ChatMessageListFragmentKotlin : UChatFragment() {
         })
     }
 
-    override fun onVisible() {
-        super.onVisible()
-        StatusBarUtils.statusBarDarkFont(mContext, true)
-        mainClient?.let {
-            it.setMainTabStyle(CommonConfig.FLAG_MSG, false, false, false, false)
-            loadUserAvatar()
+    /**
+     * ---------------- 这是头部数据 -----------------------------------------------------------
+     */
+
+    private fun setFindBossIsSow() {
+        AppManager.get().userMine?.let { userMine ->
+            var isPlayer = false
+            userMine.playerAuthentication?.let {
+                isPlayer = it == "1"
+            }
+            headerBinding.rlFindTheBossLayout.visibility = if (isPlayer) View.VISIBLE else View.GONE
+        } ?: let {
+            headerBinding.rlFindTheBossLayout.visibility = View.GONE
         }
-        checkList()
-        checkNotifyEnable()
     }
 
-    override fun onHidden() {
-        super.onHidden()
+    /**
+     * 刷新未读数 做了时间间隔处理
+     */
+    private fun refresh() {
+        execute(IMCore.get().unreadInfoRefresh(), object : CoreCallback<IMUnreadInfo?>() {
+            override fun onSuccess(visitorsLast: IMUnreadInfo?) {
+                if (visitorsLast != null && visitorsLast.isRefresh) setHeaderData(visitorsLast)
+                mainClient?.refreshUnreadNumber()
+            }
+        })
     }
 
-    override fun onDestroyView() {
-        adapter?.release()
-        super.onDestroyView()
+    /**
+     * 处理未读数 回调数据
+     */
+    private fun setHeaderData(data: IMUnreadInfo) {
+        // 访客足迹
+        if (!TextUtils.isEmpty(data.lastVistorUserHeadImg) && data.vistorUnreadNum > 0) {
+            loadAvatar(headerBinding.civVisitor, headerBinding.civVisitorMask, data.lastVistorUserHeadImg, false)
+            headerBinding.tvVisitorNumber.visibility = View.VISIBLE
+        } else resetVisitorIconState()
+
+        // 喜欢我的
+        if (!TextUtils.isEmpty(data.lastLikeMeUserHeadImg) && data.likeMeUnreadNum > 0) {
+            loadAvatar(headerBinding.civLikeMe, headerBinding.civLikeMeMask, data.lastLikeMeUserHeadImg, true)
+            headerBinding.tvLikeMeNumber.visibility = View.VISIBLE
+        } else resetLikeIconState()
+
+        // 订单未读
+        setOrderUnreadNum(data.playOrderUnreadNum)
+        //
+        // 互动消息未读 = 动态未读 + 声卡未读
+        val praiseNum = data.dailyDynamicUnreadNum + data.soundCardUnreadNum
+        headerBinding.tvPraiseSelfNumber.visibility = if (praiseNum > 0) View.VISIBLE else View.INVISIBLE
+
+        // 发现老板
+        if (headerBinding.rlFindTheBossLayout.visibility == View.VISIBLE) {
+            if (!CollectionUtils.isEmpty(data.bossHeadImgList)) {
+                mMessageHandler.removeMessages(2)
+                avatars.clear()
+                avatars.addAll(data.bossHeadImgList)
+                mMessageHandler.sendEmptyMessageDelayed(2, avatarAnimationTime)
+            } else {
+                headerBinding.davAvatar.clearView()
+            }
+        }
     }
 
+    /**
+     * 头部访客 喜欢未读数 的头像处理
+     */
+    private fun loadAvatar(iv: ImageView, ivMask: ImageView, url: String, isLikeMe: Boolean) {
+        val userMine = AppManager.get().userMine ?: return
+        if (isLikeMe) {
+            val isExplotionLight = !userMine.isExplotionLight
+            if (isExplotionLight) ImageLoader.get().load(url, iv, CustomTransformation.builder().blur(10))
+            else ImageLoader.get().loadAvatar(url, iv)
+            ivMask.visibility = if (isExplotionLight) View.VISIBLE else View.GONE
+        } else {
+            val isPlayer = userMine.playerAuthentication == "1" // 1 是陪玩师
+            val showMask = !isPlayer && !userMine.isExplotionLight
+            if (showMask) ImageLoader.get().load(url, iv, CustomTransformation.builder().blur(10))
+            else ImageLoader.get().loadAvatar(url, iv)
+            ivMask.visibility = if (showMask) View.VISIBLE else View.GONE
+        }
+    }
+
+    private fun resetVisitorIconState() {
+        headerBinding.tvVisitorNumber.visibility = View.INVISIBLE
+        headerBinding.civVisitorMask.visibility = View.GONE
+        headerBinding.civVisitor.setImageResource(R.drawable.im_ic_top_visitor)
+    }
+
+    private fun resetLikeIconState() {
+        headerBinding.tvLikeMeNumber.visibility = View.GONE
+        headerBinding.civLikeMeMask.visibility = View.GONE
+        headerBinding.civLikeMe.setImageResource(R.drawable.im_ic_top_like_me)
+    }
+
+    private fun resetPraiseNumState() {
+        headerBinding.tvPraiseSelfNumber.visibility = View.INVISIBLE
+    }
+
+    /**
+     * 接收到订单消息 设置 UI 显示
+     */
+    private fun setOrderUnreadNum(orderUnreadNum: Int) {
+        var unreadNum = orderUnreadNum
+        if (unreadNum == -1) {
+            val s: String = headerBinding.tvOrderMessageNumber.text.toString()
+            unreadNum = when {
+                Pattern.matches("[0-9]+", s) -> (s.toInt() + 1)
+                TextUtils.isEmpty(s) -> 1
+                else -> 1
+            }
+        }
+        headerBinding.tvOrderMessageNumber.text = unreadNum.toString()
+        headerBinding.tvOrderMessageNumber.visibility = if (unreadNum > 0) View.VISIBLE else View.INVISIBLE
+    }
+
+    fun getUnreadCount(): Int {
+        return if (!::headerBinding.isInitialized) 0 else getUnreadNumber(headerBinding.tvOrderMessageNumber)
+    }
+
+    /**
+     * 获取当前 头部界面上的 未读数
+     */
+    private fun getUnreadNumber(tv: TextView): Int {
+        if (tv.visibility == View.VISIBLE) {
+            var s = tv.text.toString()
+            if (TextUtils.isEmpty(s)) s = "0"
+            if (s.contains("+")) s = s.replace("+", "")
+            val i = s.toInt()
+            if (i > 0) return i
+        }
+        return 0
+    }
+
+    @SuppressLint("HandlerLeak")
+    var mMessageHandler: Handler = object : Handler() {
+        override fun handleMessage(msg: android.os.Message) {
+            if (msg.what == 2) {
+                if (avatars.size > 0) {
+                    if (avatarIndex > avatars.size - 1) {
+                        avatarIndex = 0
+                    }
+                    val vo = RongLikeImageCardVo(avatars[avatarIndex])
+                    headerBinding.davAvatar.addData(vo, true)
+                    avatarIndex += 1
+                }
+                sendEmptyMessageDelayed(2, avatarAnimationTime)
+            }
+        }
+    }
+
+    private val netWorkStatusChangedListener = object : OnNetworkStatusChangedListener {
+        override fun onDisconnected() {}
+        override fun onConnected(networkType: NetworkUtils.NetworkType) {
+            if (!AppManager.get().isConnectRongCloud && AppManager.get().isLogin) {
+                IMChatUtils.connect(AppManager.get().userLoginInfo.rongCloudToken)
+            }
+        }
+    }
 }