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 小时前
MySQL ORDER BY 性能优化详解:Using filesort、联合索引、ASC/DESC 与覆盖索引
android·adb
OriginCoding2 小时前
用 AI Agent 协作完成一个 Android TOTP 应用:从需求边界到 v1.0.0
android·ai编程
杉氧4 小时前
React 灵魂:深入剖析 Hooks 与副作用(Side Effects)陷阱
android·前端·react native
又见情义5 小时前
RK3568 + RTL8211F 网络唤醒(WOL)功能适配全记录
android·网络·驱动开发
用户0934077735145 小时前
HarmonyOS WPS Open SDK 实践:registerApp 鉴权与就绪门禁
android·typescript·harmonyos
jike_20265 小时前
会议离线录音APP:无网络记录能力对比
android·智能手机·语音识别
always_TT7 小时前
【Python 字符串格式化:format() 方法】
android·开发语言·python
恋猫de小郭7 小时前
AI 时代,一个优化 Flutter 的重复代码工具 Deslop
android·前端·flutter
RisunJan7 小时前
Android 面试知识点整理
android·面试·职场和发展
脚踏实地,坚持不懈!7 小时前
Android ANR 内核底层全解析:从一次触摸到“应用无响应”
android·linux