Skip to content

Commit 3bccb86

Browse files
Update README.md
1 parent 383b4e8 commit 3bccb86

File tree

1 file changed

+83
-12
lines changed

1 file changed

+83
-12
lines changed

README.md

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Add it in your root build.gradle at the end of repositories:
2525
```groovy
2626
allprojects {
2727
repositories {
28-
...
28+
// ...
2929
maven { url 'https://www.jitpack.io' }
3030
}
3131
}
@@ -49,25 +49,96 @@ dependencies {
4949
}
5050
```
5151

52-
## Wiki
52+
## Usage
5353

54-
#### Kotlin usage
54+
:pencil: **[Usage documentation](https://dylancaicoding.github.io/ViewBindingKTX)**
5555

56-
- [Using the extension function](https://github.com/DylanCaiCoding/ViewBindingKtx/wiki/使用拓展函数)
56+
## Sample
5757

58-
- [Modify base class](https://github.com/DylanCaiCoding/ViewBindingKtx/wiki/改造基类-(Kotlin))
58+
Get the binding instance using the Kotlin property delegate:
5959

60-
- [Compatible with BRVAH](https://github.com/DylanCaiCoding/ViewBindingKtx/wiki/兼容-BRVAH-(Kotlin))
60+
```kotlin
61+
class MainActivity : AppCompatActivity() {
6162

62-
#### Java usage
63+
private val binding: ActivityMainBinding by binding()
64+
// private val binding by binding(ActivityMainBinding::inflate)
6365

64-
- [Modify base class](https://github.com/DylanCaiCoding/ViewBindingKtx/wiki/改造基类-(Java))
66+
override fun onCreate(savedInstanceState: Bundle?) {
67+
super.onCreate(savedInstanceState)
68+
binding.tvHelloWorld.text = "Hello Android!"
69+
}
70+
}
71+
```
72+
73+
```kotlin
74+
class HomeFragment : Fragment(R.layout.fragment_home) {
75+
76+
private val binding: FragmentHomeBinding by binding()
77+
// private val binding by binding(FragmentHomeBinding::bind)
78+
79+
private val childBinding: LayoutChildBinding by binding(Method.INFLATE)
80+
// private val childBinding by binding { LayoutChildBinding.inflate(layoutInflater) }
81+
82+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
83+
super.onViewCreated(view, savedInstanceState)
84+
binding.container.addView(childBinding.root)
85+
}
86+
}
87+
```
88+
89+
Use in the base class:
90+
91+
```kotlin
92+
class MainActivity : BaseBindingActivity<ActivityMainBinding>() {
93+
94+
override fun onCreate(savedInstanceState: Bundle?) {
95+
super.onCreate(savedInstanceState)
96+
binding.tvHelloWorld.text = "Hello Android!"
97+
}
98+
}
99+
```
100+
101+
```kotlin
102+
class HomeFragment: BaseBindingFragment<FragmentHomeBinding>() {
65103

66-
- [Compatible with BRVAH](https://github.com/DylanCaiCoding/ViewBindingKtx/wiki/兼容-BRVAH-(Java))
104+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
105+
super.onViewCreated(view, savedInstanceState)
106+
binding.tvHelloWorld.text = "Hello Android!"
107+
}
108+
}
109+
```
110+
111+
Use multiple ways to compatible [BaseRecyclerViewAdapterHelper](https://github.com/CymChad/BaseRecyclerViewAdapterHelper)
112+
113+
```kotlin
114+
class FooAdapter : BaseQuickAdapter<Foo, BaseViewHolder>(R.layout.item_foo) {
115+
116+
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
117+
return super.onCreateDefViewHolder(parent, viewType).withBinding { ItemFooBinding.bind(it) }
118+
}
119+
120+
override fun convert(holder: BaseViewHolder, item: Foo) {
121+
holder.getViewBinding<ItemFooBinding>().apply {
122+
tvFoo.text = item.value
123+
}
124+
}
125+
}
126+
```
127+
128+
```kotlin
129+
class FooAdapter : BaseBindingQuickAdapter<Foo, ItemFooBinding>() {
130+
131+
override fun convert(holder: BaseBindingHolder<ItemFooBinding>, item: Foo) {
132+
holder.getViewBinding<ItemFooBinding>().apply {
133+
tvFoo.text = item.value
134+
}
135+
}
136+
}
137+
```
67138

68-
#### Others
139+
See the [usage documentation](https://dylancaicoding.github.io/ViewBindingKTX) for more usage.
69140

70-
- [Q&A](https://github.com/DylanCaiCoding/ViewBindingKtx/wiki/Q&A)
141+
##
71142

72143
## Change log
73144

@@ -79,7 +150,7 @@ dependencies {
79150
| ------------------------------------------------------------ | ------------------------------------------------------------ |
80151
| [Longan](https://github.com/DylanCaiCoding/Longan) | A collection of Kotlin utils which makes Android application development faster and easier. |
81152
| [LoadingStateView](https://github.com/DylanCaiCoding/LoadingStateView) | Decoupling the code of toolbar or loading status view. |
82-
| [MMKV-KTX](https://github.com/DylanCaiCoding/MMKV-KTX) | Easier to use the MMKV. |
153+
| [MMKV-KTX](https://github.com/DylanCaiCoding/MMKV-KTX) | Use MMKV with property delegates. |
83154
| [ActivityResultLauncher](https://github.com/DylanCaiCoding/ActivityResultLauncher) | Replace startActivityForResult() method gracefully. |
84155

85156
## Thanks

0 commit comments

Comments
 (0)