-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,62 @@ | ||
# BindingExtension | ||
# BindingExtension | ||
|
||
ViewBinding is an amazing tool for Android but it's not so fit in Android development as we still have to do some config. BindingExtension is built to provide a simpler usage. | ||
|
||
## Install | ||
|
||
Add [Jitpack](https://jitpack.io/) repository to your root `build.grable`: | ||
```groovy | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
|
||
Then add dependency in your module `build.gradle`: | ||
```groovy | ||
dependencies { | ||
implementation 'com.github.jintin:BindingExtension:1.0.0' | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
### Activity | ||
|
||
Extend from `BindingActivity` with your actual `ViewBinding` type then you can use `binding` directly after calling `super.onCreate(savedInstanceState)` : | ||
|
||
```kotlin | ||
class MainActivity : BindingActivity<ActivityMainBinding>() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding.label.setText(R.string.activity_label) | ||
} | ||
} | ||
``` | ||
|
||
### Fragment | ||
|
||
Extend from `BindingFragment` with your actual `ViewBinding` type then you can use `binding` directly after `super.onCreateView(inflater, container, savedInstanceState)` is called: | ||
|
||
```kotlin | ||
class MainFragment : BindingFragment<FragmentMainBinding>() { | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
binding.button.setOnClickListener { | ||
binding.button.setText(R.string.fragment_label) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
You can go to ./app module for more information. | ||
## Contributing | ||
Bug reports and pull requests are welcome on GitHub at [https://github.com/Jintin/BindingExtension](https://github.com/Jintin/BindingExtension). | ||
|
||
[![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jintin) |