Skip to content

Commit

Permalink
first submit
Browse files Browse the repository at this point in the history
  • Loading branch information
QDong415 committed May 26, 2022
1 parent 5048ffc commit d02a359
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 45 deletions.
75 changes: 38 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@

## 简介:

下拉拖拽关闭Activity,下拉返回Activity。仿大众点评、快手、小红书详情界面:可下滑关闭详情界面
Drag down to close activity
直播间聊天消息RecyclerView列表,直播间RecyclerView。采用3层缓存机制,一秒内收到几百条消息依然不卡顿
ChatRoom in LiveRoom.Using the three kind of cache strategy and async in HandlerThread.Can carry many messages

## 安装体验:
![](https://upload-images.jianshu.io/upload_images/26002059-94273eadb7cf0295.png)
![](https://upload-images.jianshu.io/upload_images/26002059-97c094d65ebedd5f.png)

## 功能(优点):
- ✅Demo包含`瀑布列表跳转到详情,带动画`+`详情可左滑进入个人主页`+`下拉拖拽关闭Activity`
- ✅到为了让Activity的xml布局层级最少,只需要把本库设置为最外层的RelativeLayout
- ✅仿大众点评:下拉过程中除了图片,别的部分随着下拉距离而半透明
- ✅仿快手:fling快速下滑也可触发关闭
- ✅详情界面可左滑进入个人主页,你可以自己实现懒加载
- ✅解决下拉返回ImageView闪一下问题
- ✅完美解耦,可轻松让你的任何Activity实现下拉关闭效果
- ✅采用3层缓存机制 + 异步解析ImageSpan。一秒内收到几百条消息依然不卡顿
- ✅可配置RecyclerView最短刷新时间间隔
- ✅可配置在短时间内如果收到太多消息可选择丢弃消息
- ✅根据缓冲区消息数量选择不同的ScrollToBottom速度
- ✅Demo中提供"底部还有XX条未读消息"的处理方式
- ✅Demo中提供弹幕中仿抖音的"粉丝团"标签处理方式
- ✅内存占用控制的很好,收到再多消息帧数也控制在55以上
- ✅完美解耦,无内存泄漏,接入很简单

## 作者说明:
- Android系统的Activity过场动画会让shareElementImageView.setAlpha(0);然后回退动画结束再进行.setAlpha(1)<bar />
- 这样会导致一个问题:我们下拉返回的时候,由于弹回动画是我们自己做的。但是系统依然会再进行一遍.setAlpha(1),导致回弹动画结束时候图片会闪一下。参考下面的第1个gif<bar />
- 为了解决"闪一下"的问题,我用这种方法把他提前设为.setAlpha(1)<bar />
## 具体技术说明:
- 第一层缓存:消息的标签ImageSpan缓存,比如"榜1" "等级" "粉丝团等级"<bar />
- 第二层缓存:收到消息时候,检查上次刷新时间。如果刚上次刚刷新不到0.n秒,那么就插入到缓冲区。0.n秒后将全部缓冲区显示出来再清空缓冲区<bar />
- 第三层缓存:model中的SpannableString。让用户手指滚动列表更顺畅,无需再次解析SpannableString<bar />
- 额外缓存:解析标签ImageSpan时候全程只采用一个TextView,避免每次都new,json解析也是如此

- 异步解析:解析完整的(3个)SpannableString在低性能手机上最慢需要20-40ms。会造成丢帧。本库采用HandlerThread解析<bar />
- 提供策略模式解析标签ImageSpan,拓展性极强

## 效果gif图(Gif图有点卡,实际运行一点都不卡):
![](https://upload-images.jianshu.io/upload_images/26002059-96c272f540bddb21.gif)
![](https://upload-images.jianshu.io/upload_images/26002059-da019a1de650eca8.gif)
![](https://upload-images.jianshu.io/upload_images/26002059-536ebf49fa017bd3.gif)
![](https://upload-images.jianshu.io/upload_images/26002059-4809cca72bd1c551.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/640)

## 导入
```
Expand All @@ -37,34 +41,31 @@ Drag down to close activity
}
dependencies {
implementation 'com.github.QDong415:QLiveMessage:v1.0.1'
implementation 'com.github.QDong415:QLiveMessageHelper:v1.0'
}
```

## 使用

```java
QDragRelativeLayout contentLayout = findViewById(R.id.drag_layout);
contentLayout.setOnLiveMessageListener(this);
//传入列表的点击项目的ImageView的坐标
contentLayout.setupFromImageView(fromX, fromY, fromWidth, fromHeight, transition_share_view);
```

```xml
<declare-styleable name="QLiveMessage">
<!-- 是否可以手势下拉,默认true -->
<attr name="dragEnable" format="boolean" />
<!-- 下拉距离占总height百分之多少就触发关闭,0 - 1之间,默认0.2 -->
<attr name="closeYRatio" format="float" />
<!-- 手指快速下滑也可以触发关闭,默认true -->
<attr name="flingCloseEnable" format="boolean" />
<!-- 手势下拉过程中,其他View根据滑动距离半透明,默认false -->
<attr name="alphaWhenDragging" format="boolean" />
<!-- 关闭动画耗时,默认450 -->
<attr name="closeAnimationDuration" format="integer" />
<!-- 下拉力度不够,反弹回正常状态动画耗时,默认200 -->
<attr name="rollToNormalAnimationDuration" format="integer" />
</declare-styleable>
//给我们的库 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()

```


Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'

//性能监控 kotlin编译插件为1.3.72; 支持Gradle 6.8及以下
debugImplementation 'io.github.didi.dokit:dokitx:3.5.0.1'
// debugImplementation 'io.github.didi.dokit:dokitx:3.5.0.1'

implementation project(path: ':liveMessage')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.dq.livemessagedemo.tool

import android.app.Application
import android.util.Log
import com.didichuxing.doraemonkit.DoKit
import com.dq.livemessagedemo.model.LiveMessageIntrinsicModel
import com.dq.livemessagedemo.model.LiveMessageModel
import com.squareup.moshi.Moshi
import java.util.*

class QApplication : Application(){

Expand All @@ -24,7 +18,7 @@ class QApplication : Application(){

instance = this
socketManager = SocketManager()
DoKit.Builder(this).build()
// DoKit.Builder(this).build()
}

}

0 comments on commit d02a359

Please sign in to comment.