Skip to content

Commit 5888a1e

Browse files
Optimize docs
1 parent 4e45fa3 commit 5888a1e

File tree

5 files changed

+46
-27
lines changed

5 files changed

+46
-27
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- 支持创建 PopupWindow
1919
- 支持 TabLayout 实现自定义标签布局
2020
- 支持 NavigationView 设置头部控件
21-
- 支持 DataBinding 自动设置 lifecycleOwner
21+
- 支持无缝切换 DataBinding
2222

2323
## Gradle
2424

docs/cn/kotlin/brvah.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ class FooAdapter : BaseQuickAdapter<Foo, BaseViewHolder>(R.layout.item_foo) {
1919
}
2020
}
2121
}
22-
```
22+
```
23+
24+
如果使用了 `viewbinding-nonreflection-ktx` 依赖,无需增加 `viewbinding-brvah` 依赖就能支持。

docs/cn/kotlin/ext.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 开始使用
44

5-
添加依赖,本库提供了使用反射和不使用反射的用法,如果希望不使用反射,可换成代码下方对应的注释代码
5+
添加依赖,本库提供了使用反射和不使用反射的用法,如果希望不使用反射,可换成对应的注释代码
66

77
```gradle
88
implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-ktx:2.0.0'
@@ -62,9 +62,7 @@ class TextAdapter : ListAdapter<String, BindingViewHolder<ItemTextBinding>>(Diff
6262
}
6363

6464
override fun onBindViewHolder(holder: BindingViewHolder<ItemTextBinding>, position: Int) {
65-
holder.binding.apply {
66-
tvText.text = currentList[position]
67-
}
65+
holder.binding.tvText.text = currentList[position]
6866
}
6967

7068
class DiffCallback : DiffUtil.ItemCallback<String>() {
@@ -74,7 +72,18 @@ class TextAdapter : ListAdapter<String, BindingViewHolder<ItemTextBinding>>(Diff
7472
}
7573
```
7674

77-
如果项目中的适配器封装了 ViewHolder 基类,可参考[兼容 BaseRecyclerViewAdapterHelper](/cn/kotlin/brvah) 的方式另行适配。
75+
如果项目中的适配器像 `BRVAH` 那样封装了自定义的 ViewHolder,那么可以直接通过 ViewHolder 获取 binding 对象。
76+
77+
```kotlin
78+
class FooAdapter : BaseQuickAdapter<Foo, BaseViewHolder>(R.layout.item_foo) {
79+
80+
override fun convert(holder: BaseViewHolder, item: Foo) {
81+
holder.getBinding<ItemFooBinding>()
82+
// holder.getBinding(ItemFooBinding::bind)
83+
.tvFoo.text = item.value
84+
}
85+
}
86+
```
7887

7988
### DialogFragment & Dialog
8089

@@ -125,19 +134,19 @@ TabLayoutMediator(tabLayout, viewPager2) { tab, position ->
125134
tab.setCustomView<LayoutBottomTabBinding> {
126135
// tab.setCustomView(LayoutBottomTabBinding::bind) {
127136
tvTitle.setText(titleList[position])
128-
tvTitle.textSize = if (position == 0) 16f else 14f
137+
tvTitle.textSize = if (position == 0) 12f else 10f
129138
ivIcon.setImageResource(iconList[position])
130-
ivIcon.contentDescription = getString(titleList[position])
139+
ivIcon.contentDescription = tvTitle.text.toString()
131140
}
132141
}.attach()
133142

134143
tabLayout.doOnCustomTabSelected<LayoutBottomTabBinding>(
135144
// tabLayout.doOnCustomTabSelected(LayoutBottomTabBinding::bind,
136145
onTabSelected = {
137-
textView.textSize = 16f
146+
textView.textSize = 12f
138147
},
139148
onTabUnselected = {
140-
textView.textSize = 14f
149+
textView.textSize = 10f
141150
})
142151
```
143152

@@ -154,8 +163,7 @@ navigationView.setHeaderView<LayoutNavHeaderBinding> {
154163

155164
```kotlin
156165
private val popupWindow by popupWindow<LayoutPopupBinding> {
157-
btnLike.setOnClickListener {
158-
//...
159-
}
166+
// private val popupWindow by popupWindow(LayoutPopupBinding::inflate) {
167+
btnLike.setOnClickListener { ... }
160168
}
161169
```

docs/en/kotlin/brvah.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ class FooAdapter : BaseQuickAdapter<Foo, BaseViewHolder>(R.layout.item_foo) {
2020
}
2121
}
2222
```
23+
24+
If the `viewbinding-nonreflection-ktx` dependency is used, it can be supported without adding the `viewbinding-brvah` dependency.

docs/en/kotlin/ext.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ class TextAdapter : ListAdapter<String, BindingViewHolder<ItemTextBinding>>(Diff
6060
}
6161

6262
override fun onBindViewHolder(holder: BindingViewHolder<ItemTextBinding>, position: Int) {
63-
holder.binding.apply {
64-
tvText.text = currentList[position]
65-
}
63+
holder.binding.tvText.text = currentList[position]
6664
}
6765

6866
class DiffCallback : DiffUtil.ItemCallback<String>() {
@@ -72,7 +70,18 @@ class TextAdapter : ListAdapter<String, BindingViewHolder<ItemTextBinding>>(Diff
7270
}
7371
```
7472

75-
If the project has custom ViewHolder, please refer to [the usage of BaseRecyclerViewAdapterHelper](/en/kotlin/brvah).
73+
If the project has custom ViewHolder such as `BRVAH`, you can get the binding object with ViewHolder.
74+
75+
```kotlin
76+
class FooAdapter : BaseQuickAdapter<Foo, BaseViewHolder>(R.layout.item_foo) {
77+
78+
override fun convert(holder: BaseViewHolder, item: Foo) {
79+
holder.getBinding<ItemFooBinding>()
80+
// holder.getBinding(ItemFooBinding::bind)
81+
.tvFoo.text = item.value
82+
}
83+
}
84+
```
7685

7786
### DialogFragment & Dialog
7887

@@ -123,19 +132,19 @@ TabLayoutMediator(tabLayout, viewPager2) { tab, position ->
123132
tab.setCustomView<LayoutBottomTabBinding> {
124133
// tab.setCustomView(LayoutBottomTabBinding::bind) {
125134
tvTitle.setText(titleList[position])
126-
tvTitle.textSize = if (position == 0) 16f else 14f
135+
tvTitle.textSize = if (position == 0) 12f else 10f
127136
ivIcon.setImageResource(iconList[position])
128-
ivIcon.contentDescription = getString(titleList[position])
137+
ivIcon.contentDescription = tvTitle.text.toString()
129138
}
130139
}.attach()
131140

132141
tabLayout.doOnCustomTabSelected<LayoutBottomTabBinding>(
133142
// tabLayout.doOnCustomTabSelected(LayoutBottomTabBinding::bind,
134143
onTabSelected = {
135-
textView.textSize = 16f
144+
textView.textSize = 12f
136145
},
137146
onTabUnselected = {
138-
textView.textSize = 14f
147+
textView.textSize = 10f
139148
})
140149
```
141150

@@ -151,10 +160,8 @@ navigationView.setHeaderView<LayoutNavHeaderBinding> {
151160
### PopupWindow
152161

153162
```kotlin
154-
private val popupWindow by popupWindow<LayoutPopupBinding> {
155-
btnLike.setOnClickListener {
156-
//...
157-
}
163+
private val popupWindow by popupWindow<LayoutPopupBinding> {
164+
// private val popupWindow by popupWindow(LayoutPopupBinding::inflate) {
165+
btnLike.setOnClickListener { ... }
158166
}
159167
```
160-

0 commit comments

Comments
 (0)