Android开发融云获取多个会话的总未读数

Android开发融云获取多个会话的总未读数

融云没有获取多个会话总未读数的api,只有获取单个会话的未读数。这样我只能通过递归获取。

java 复制代码
private void secretLetterUnReadCount(final List<String> targetIds, final List<Integer> greetUnCount, final int unReadCount, final TextView unread){
        if(Utils.isNotNull(targetIds) && targetIds.size() > 0){
            RongIM.getInstance().getUnreadCount(Conversation.ConversationType.PRIVATE, targetIds.get(0), new RongIMClient.ResultCallback<Integer>() {
                @Override
                public void onSuccess(Integer integer) {
                    if(unReadCount == -1){
                        greetUnCount.set(0,greetUnCount.get(0) + integer);
                    }else {
                        greetUnCount.set(1,greetUnCount.get(1) + 1);
                    }

                    targetIds.remove(0);
                    secretLetterUnReadCount(targetIds, greetUnCount, unReadCount, tv_content, unread);
                }

                @Override
                public void onError(RongIMClient.ErrorCode errorCode) {
                    targetIds.remove(0);
                    secretLetterUnReadCount(targetIds, greetUnCount, unReadCount, tv_content, unread);
                }
            });
        }else {
            if(unReadCount == -1){
                if(greetUnCount.get(0) > 0){
                    secretLetterUnReadCount(SPNoCleanUtil.getSecretReceiveSet() , greetUnCount, greetUnCount.get(0), tv_content, unread);
                } else {
                    unread.setVisibility(View.GONE);
                }
            }else {
                if(!(unReadCount + "").equals(unread.getText().toString())){
                    unread.setText(unReadCount > 99 ? "99+" : unReadCount + "");
                }
                if(unread.getVisibility() != View.VISIBLE){
                    unread.setVisibility(View.VISIBLE);
                }
              
            }
        }
    }

调用:

java 复制代码
secretLetterUnReadCount(SPNoCleanUtil.getSecretReceiveSet(), secretLetterUnCount, -1, ((TextView)holder.getView(R.id.tv_unread_count)));

其中SPNoCleanUtil.getSecretReceiveSet()就是你的多个会话的集合它是List的,secretLetterUnCount默认是0,tv_unread_count就是你的TextView控件

还有问题可以评论或者私信我

相关推荐
小阳睡不醒1 小时前
小白成长之路-部署Zabbix7(二)
android·运维
mmoyula2 小时前
【RK3568 PWM 子系统(SG90)驱动开发详解】
android·linux·驱动开发
你过来啊你5 小时前
Android用户鉴权实现方案深度分析
android·鉴权
kerli7 小时前
Android 嵌套滑动设计思想
android·客户端
恣艺8 小时前
LeetCode 854:相似度为 K 的字符串
android·算法·leetcode
阿华的代码王国9 小时前
【Android】相对布局应用-登录界面
android·xml·java
用户207038619499 小时前
StateFlow与SharedFlow如何取舍?
android
QmDeve9 小时前
原生Android Java调用系统指纹识别方法
android