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

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

相关推荐
每次的天空29 分钟前
Android学习总结之Glide篇(缓存和生命周期)
android·学习·glide
非凡ghost1 小时前
LSPatch官方版:无Root Xposed框架,自由定制手机体验
android·智能手机·软件需求
_extraordinary_1 小时前
MySQL 库的操作 -- 增删改查,备份和恢复,系统编码
android·mysql·oracle
西瓜本瓜@4 小时前
在Android中如何使用Protobuf上传协议
android·java·开发语言·git·学习·android-studio
似霰7 小时前
安卓adb shell串口基础指令
android·adb
fatiaozhang95279 小时前
中兴云电脑W102D_晶晨S905X2_2+16G_mt7661无线_安卓9.0_线刷固件包
android·adb·电视盒子·魔百盒刷机·魔百盒固件
CYRUS_STUDIO10 小时前
Android APP 热修复原理
android·app·hotfix
鸿蒙布道师11 小时前
鸿蒙NEXT开发通知工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
鸿蒙布道师11 小时前
鸿蒙NEXT开发网络相关工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
大耳猫11 小时前
【解决】Android Gradle Sync 报错 Could not read workspace metadata
android·gradle·android studio