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

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

相关推荐
雨白2 小时前
实现双向滑动的 ScalableImageView(上)
android
Y4090013 小时前
数据库基础知识——聚合函数、分组查询
android·数据库
没有了遇见8 小时前
Android 原生定位(替代高德 / 百度等三方定位)<终极版本>
android
2501_916008898 小时前
iOS 抓包工具有哪些?全面盘点主流工具与功能对比分析
android·ios·小程序·https·uni-app·iphone·webview
2501_915921438 小时前
iOS混淆工具实战 视频流媒体类 App 的版权与播放安全保护
android·ios·小程序·https·uni-app·iphone·webview
CYRUS_STUDIO9 小时前
LLVM 全面解析:NDK 为什么离不开它?如何亲手编译调试 clang
android·编译器·llvm
CYRUS_STUDIO9 小时前
静态分析神器 + 动态调试利器:IDA Pro × Frida 混合调试实战
android·逆向
g_i_a_o_giao12 小时前
Android8 binder源码学习分析笔记(一)
android·java·笔记·学习·binder·安卓源码分析
翻滚丷大头鱼12 小时前
android 四大组件—BroadcastReceiver
android
人生游戏牛马NPC1号12 小时前
学习 Android (二十) 学习 OpenCV (五)
android·opencv·学习