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控件

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

相关推荐
橙子199110164 分钟前
在 Kotlin 中,什么是解构,如何使用?
android·开发语言·kotlin
androidwork1 小时前
Android 中使用通知(Kotlin 版)
android·kotlin
Digitally2 小时前
如何从 Android 设备打印短信(5 种方法)
android
casual_clover2 小时前
Android 中 打开文件选择器(ACTION_OPEN_DOCUMENT )
android
_龙小鱼_3 小时前
卡顿检测与 Choreographer 原理
android·kotlin
云手机管家4 小时前
账号风控突破:云手机设备指纹篡改检测与反制技术解析
android·运维·网络协议·网络安全·智能手机·矩阵·自动化
千里马-horse5 小时前
Detected for tasks ‘compileDebugJavaWithJavac‘ (17) and ‘kspDebugKotlin‘ (21).
android·jdk·kspdebugkotlin
柯南二号7 小时前
【Android】Android 实现一个依赖注入的注解
android
archko9 小时前
语音识别-3,添加ai问答
android·人工智能
奔跑吧 android14 小时前
【android bluetooth 案例分析 03】【PTS 测试 】【PBAP/PCE/SGSIT/SERR/BV-01-C】
android·pts·aosp·pbap·sgsit