Coder Social home page Coder Social logo

qdong415 / qlivemessagehelper Goto Github PK

View Code? Open in Web Editor NEW
90.0 1.0 12.0 134 KB

直播间聊天消息列表,直播间RecyclerView。采用3层缓冲机制,一秒内收到几百条消息依然不卡顿。ChatRoom in LiveRoom.Using the three kind of cache strategy and async in HandlerThread.Can carry many messages

Java 8.21% Kotlin 91.79%
barrage live livemessage chatroom livechat liverecyclerview

qlivemessagehelper's Introduction

QLiveMessage

简介:

直播间聊天消息RecyclerView列表,直播间RecyclerView。采用3层缓存机制,一秒内收到几百条消息依然不卡顿。 ChatRoom in LiveRoom.Using the three kind of cache strategy and async in HandlerThread.Can carry many messages

安装体验:

功能(优点):

  • ✅采用3层缓存机制 + 异步解析ImageSpan。一秒内收到几百条消息依然不卡顿
  • ✅可配置RecyclerView最短刷新时间间隔 。如0.5秒只触发一次notify
  • ✅可配置在短时间内如果收到太多消息可选择丢弃消息 。如0.5秒收到超过10条就丢弃了
  • ✅根据缓冲区消息数量选择不同的ScrollToBottom速度 。用户体验细节
  • ✅Demo中提供"底部还有XX条未读消息"的处理方式 。并解耦出来,用在你的聊天界面也可以
  • ✅Demo中提供弹幕中仿抖音的"粉丝团"标签处理方式 。我自己写的控件
  • ✅内存占用控制的很好,1秒收到几百条消息 帧数也控制在55以上
  • ✅完美解耦,无内存泄漏,接入很简单

具体技术说明:

  • 第一层缓存:消息的标签ImageSpan缓存,比如"榜1" "等级" "粉丝团等级"

  • 第二层缓存:收到消息时候,检查上次刷新时间。如果刚上次刚刷新不到0.n秒,那么就插入到缓冲区。0.n秒后将全部缓冲区显示出来再清空缓冲区

  • 第三层缓存:model中的SpannableString。让用户手指滚动列表更顺畅,无需再次解析SpannableString

  • 额外缓存:解析标签ImageSpan时候全程只采用一个TextView,避免每次都new,json解析也是如此

  • 异步解析:解析完整的(昵称前有3个标签)SpannableString在低性能手机上最慢需要20-40ms。会造成丢帧。本库采用HandlerThread解析

  • 提供策略模式解析标签ImageSpan,拓展性极强

效果gif图(Gif图有点卡,实际运行一点都不卡):

导入

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

	dependencies {
	        implementation 'com.github.QDong415:QLiveMessageHelper:v1.0'
	}

使用

//给我们的库 liveMessageRecyclerHelper,绑定recyclerView
        liveMessageRecyclerHelper.setRecyclerView(recyclerView)
        liveMessageRecyclerHelper.setUnreadTipsView(unreadTipsTextView)
        liveMessageRecyclerHelper.messageRecyclerHelperListener = object: LiveMessageRecyclerHelper.LiveMessageRecyclerHelperListener<LiveMessageModel> {
            override fun unreadMessageCountUpdate(unreadCount: Int) {
                unreadTipsTextView.setText("还有"+unreadCount +"条未读")
            }

            override fun asyncParseSpannableString(model: LiveMessageModel) {
                //这一步是在子线程中
                model.spannableString = liveMessageTextViewHelper.displaySpannableString(model)
            }
        }

        //RecyclerView最短刷新时间间隔(0秒 - 2.0秒)
        liveMessageRecyclerHelper.diffRefreshDuration = (intent.getFloatExtra("minRefreshTime",0.6f) * 1000).toLong()

Author:DQ

有问题联系QQ:285275534, [email protected]

qlivemessagehelper's People

Contributors

qdong415 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

qlivemessagehelper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.