Skip to content

Commit

Permalink
docs: 更新开发文档
Browse files Browse the repository at this point in the history
  • Loading branch information
liangjingkanji committed Aug 8, 2023
1 parent 4dea8a0 commit ead11e9
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 43 deletions.
4 changes: 2 additions & 2 deletions docs/animation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
列表动画即自定义列表Item出现时的动画
自定义列表Item出现时的动画

## 动画类型
通过函数快速设置BRV自带的几种动画类型
设置BRV自带的动画类型

```kotlin
fun setAnimation(animationType: AnimationType)
Expand Down
29 changes: 7 additions & 22 deletions docs/checked.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="https://i.loli.net/2021/08/14/MIe74pdKf5c1hTX.gif" width="250"/>

可编辑/多选列表在开发中很常见, BRV可以几行代码实现[选择模式](https://github.com/liangjingkanji/BRV/blob/master/sample/src/main/java/com/drake/brv/sample/ui/fragment/CheckModeFragment.kt)
BRV可快速实现支持单选/多选的[选择模式](https://github.com/liangjingkanji/BRV/blob/master/sample/src/main/java/com/drake/brv/sample/ui/fragment/CheckModeFragment.kt)

## 多选列表

Expand All @@ -16,13 +16,13 @@
data class CheckModel(
var isChecked: Boolean = false,
var visibility: Boolean = false
) : BaseObservable() // BaseObservable 这是DataBinding的数据绑定写法
) : BaseObservable() // 支持DataBinding数据绑定
```

3. 监听选择事件
```kotlin hl_lines="3"
rv.linear().setup {
addType<CheckModel>(R.layout.item_check_mode)
// ...
onChecked { position, isChecked, isAllChecked ->
val model = getModel<CheckModel>(position)
model.isChecked = isChecked
Expand All @@ -32,20 +32,9 @@
```

4. 触发选择事件
```kotlin hl_lines="11"
rv.linear().setup {
addType<CheckModel>(R.layout.item_check_mode)
onChecked { position, isChecked, isAllChecked ->
val model = getModel<CheckModel>(position)
model.isChecked = isChecked
model.notifyChange() // 通知UI跟随数据变化
}

onClick(R.id.cb, R.id.item) {
var isChecked = getModel<CheckModel>().isChecked
setChecked(adapterPosition, !isChecked) // 在点击事件中触发选择事件, 即点击列表条目就选中
}
}.models = getData
```kotlin hl_lines="2"
val isChecked = getModel<CheckModel>().isChecked
setChecked(adapterPosition, !isChecked) // 在点击事件中触发选择事件, 即点击列表条目就选中
```


Expand All @@ -56,11 +45,7 @@
首次加载列表默认选中指定Item, 应调用`setChecked`而不是将Model中某个属性置为true

```kotlin
// 切换选择模式
tv_manage.setOnClickListener {
adapter.toggle()
rv.bindingAdapter.setChecked(0, true) // 一开始就选中第一个
}
rv.bindingAdapter.setChecked(0, true) // 一开始就选中第一个
```

!!! question "原因"
Expand Down
18 changes: 9 additions & 9 deletions docs/divider-linear.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img src="https://i.loli.net/2021/08/14/IoBfnz6ERXVHlq3.png" width="250" />

创建一个`drawable`文件来描述分隔线, 其具备复用的特点
创建`drawable`来描述分隔线

```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
Expand All @@ -25,7 +25,7 @@ rv.linear().divider(R.drawable.divider_horizontal).setup {

<img src="https://i.loli.net/2021/08/14/rAeDXkfV6HxJUym.png" width="250"/>

创建Drawable作为分隔线
创建`drawable`来描述分隔线
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/dividerDecoration" />
Expand All @@ -41,9 +41,9 @@ rv.linear(RecyclerView.HORIZONTAL).divider(R.drawable.divider_vertical).setup {
```


- 这里使用`Drawable`资源来快速设置分隔线, Drawable的宽高就是分隔线的宽高
- 如果水平分隔线, 则Drawable的宽度值无效(实际宽度值为RecyclerView的宽)
- 如果垂直分隔线, 则Drawable的高度值无效(实际分隔线高度为RecyclerView高度)
- 使用`drawable`资源可复用分隔线, 其宽高就是分隔线的宽高
- 如果水平分隔线, `drawable`的宽度值无效(实际宽度值为RecyclerView的宽)
- 如果垂直分隔线, `drawable`的高度值无效(实际分隔线高度为RecyclerView高度)


## 边缘分隔线
Expand All @@ -56,7 +56,7 @@ rv.linear(RecyclerView.HORIZONTAL).divider(R.drawable.divider_vertical).setup {

<img src="https://i.loli.net/2021/08/14/iL5epWdOQKnwZAc.png" width="250"/>

通过两个字段可以控制首尾是否显示分隔线
两个字段控制首尾是否显示分隔线

```kotlin hl_lines="3 4"
rv.linear().divider {
Expand Down Expand Up @@ -93,9 +93,9 @@ rv.grid().divider{

有两种方式

1. 直接配置一个具备间隔margin的drawable, 以下为间距16的水平分隔线
1. 创建有间隔`内间距`的drawable, 以下为间距16水平分隔线

```xml
```xml hl_lines="2"
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="16dp"
android:insetRight="16dp">
Expand All @@ -108,7 +108,7 @@ rv.grid().divider{

2. 使用setMargin()

```kotlin
```kotlin hl_lines="3"
binding.rv.linear().divider {
setDivider(1, true)
setMargin(16, 0, dp = true)
Expand Down
4 changes: 2 additions & 2 deletions docs/extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## 布局管理器

扩展函数快速创建布局管理器
快速创建布局管理器

=== "线性列表"
```kotlin hl_lines="1"
Expand Down Expand Up @@ -43,7 +43,7 @@

## 分隔线

扩展函数`divider`快速创建[DefaultDecoration](api/-b-r-v/com.drake.brv/-default-decoration/index.html)
使用`divider`快速创建[DefaultDecoration](api/-b-r-v/com.drake.brv/-default-decoration/index.html)

```kotlin hl_lines="1"
rv.linear().divider(R.drawable.divider_horizontal).setup {
Expand Down
2 changes: 1 addition & 1 deletion docs/header-footer.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ binding.rv.bindingAdapter.run {
}
```

其他头/脚布局实现
其他头/脚布局实现方式

1. 可使用[ConcatAdapter](https://developer.android.com/reference/androidx/recyclerview/widget/ConcatAdapter)连接多个`BindingAdapter`
1. `NestedScrollView`嵌套RV会导致RV一次性加载全部列表, 大量列表数据时会卡顿
Expand Down
6 changes: 3 additions & 3 deletions docs/net.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Net是一个强大的三方网络请求框架, 优秀的Api设计让他可以和BRV联动, 更加自动化
[Net](https://github.com/liangjingkanji/Net/)是一个强大的三方网络请求框架, 优秀的Api设计让他可以和BRV联动, 更加自动化

首先引用[Net](https://github.com/liangjingkanji/Net/)依赖库
首先依赖

[![](https://jitpack.io/v/liangjingkanji/Net.svg)](https://github.com/liangjingkanji/Net/)

Expand All @@ -12,7 +12,7 @@ dependencies {
推荐使用指定的版本号替换`+`


配合[Net](https://github.com/liangjingkanji/Net/)可以新增以下特性
新增以下特性

- [自动下拉刷新](https://liangjingkanji.github.io/Net/auto-refresh/)
- [自动分页加载](https://liangjingkanji.github.io/Net/auto-page/)
Expand Down
1 change: 0 additions & 1 deletion docs/refresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout -> ClassicsF
```kotlin
rv.linear().setup {
addType<Model>(R.layout.item_simple)
addType<DoubleItemModel>(R.layout.item_full_span)
}

page.onRefresh {
Expand Down
1 change: 0 additions & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ StateConfig.apply {
```kotlin
rv.linear().setup {
addType<Model>(R.layout.item_simple)
addType<DoubleItemModel>(R.layout.item_full_span)
}.models = getData()
```

Expand Down
2 changes: 1 addition & 1 deletion docs/toggle.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BRV提供一个遍历所有列表条目的监听事件, 可以在回调内依次更新视图
一个遍历所有列表条目的监听事件, 开发者可以在回调内更新视图

!!! question "切换模式"
`切换`可以理解为`遍历`列表条目, 常用于切换列表为编辑模式
Expand Down
2 changes: 1 addition & 1 deletion docs/upfetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
拉取更多(又称下拉加载更多页), 例如聊天界面下拉加载更多页

<br>
例如聊天记录界面, 最新的消息在底部, 下拉列表会触发顶部加载历史
例如聊天记录界面, 最新的消息在底部, 下拉列表会触发顶部加载历史消息

<br>

Expand Down

0 comments on commit ead11e9

Please sign in to comment.