Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jintin committed Dec 25, 2020
1 parent 63cd1fb commit 6dffe7a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ dependencies {

First of all, BindingExtension using refelction a lot to link many things internally in order to provide simple usage.
To prevent having trouble with proguard, please remember to exclude ViewBinding related class in your proguard file.
For example, if your package is `com.jintin.bindingextension.app`:
For example, if your ViewBinding class is all under `com.jintin.bindingextension.app` package:
```
-keep public class com.jintin.bindingextension.app.databinding** { <methods>; }
```

### Activity

Extend from `BindingActivity` with your actual `ViewBinding` inflate method reference then you can use `binding` directly after calling `super.onCreate(savedInstanceState)` and you don't have to call `setContentView` anymore:
Extend from `BindingActivity` with your `ViewBinding` type then you can use `binding` directly after calling `super.onCreate(savedInstanceState)` and you don't have to call `setContentView` anymore:

```kotlin
class MainActivity : BindingActivity<ActivityMainBinding>() {
Expand All @@ -50,7 +50,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>() {

### Fragment

Extend from `BindingFragment` with your actual `ViewBinding` inflate method reference then you can use `binding` directly after `super.onCreateView(inflater, container, savedInstanceState)` is called:
Extend from `BindingFragment` with your `ViewBinding` type then you can use `binding` directly after `super.onCreateView(inflater, container, savedInstanceState)` is called:

```kotlin
class MainFragment : BindingFragment<FragmentMainBinding>() {
Expand All @@ -67,16 +67,16 @@ class MainFragment : BindingFragment<FragmentMainBinding>() {

### ViewHolder

BindingExtension provide an extension function for ViewGroup, you can call `ViewGroup.toBinding()` in `onCreateViewHolder` to get your desire type of `ViewBinding`.
And ViewHolder can than access ViewBinding directly without further modification.
BindingExtension provide an extension function for `ViewGroup`, you can call `ViewGroup.toBinding()` in `onCreateViewHolder` to get your desire type of `ViewBinding`.
And `ViewHolder` can than access `ViewBinding` directly without further transformation.

```kotlin
// inside adapter
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return MainViewHolder(parent.toBinding())
}

//...

// ViewHolder
class MainViewHolder(private val binding: AdapterMainBinding) :
RecyclerView.ViewHolder(binding.root) {

Expand Down

0 comments on commit 6dffe7a

Please sign in to comment.