https://github.com/hannesstruss/cheesewire
Lifecycle-friendly view binding in Kotlin for Conductor.
https://github.com/hannesstruss/cheesewire
android conductor kotlin
Last synced: 5 months ago
JSON representation
Lifecycle-friendly view binding in Kotlin for Conductor.
- Host: GitHub
- URL: https://github.com/hannesstruss/cheesewire
- Owner: hannesstruss
- License: apache-2.0
- Created: 2017-12-25T14:56:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-17T12:34:09.000Z (over 6 years ago)
- Last Synced: 2024-04-18T03:10:42.908Z (about 2 years ago)
- Topics: android, conductor, kotlin
- Language: Kotlin
- Homepage:
- Size: 187 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# :warning: Deprecated
CheeseWire is deprecated. From Android Gradle Plugin 3.6 on, you should use [ViewBinding](https://developer.android.com/topic/libraries/view-binding).
# CheeseWire

Lifecycle-friendly view binding in Kotlin for Conductor.
[](https://travis-ci.org/hannesstruss/cheesewire)
[](http://search.maven.org/#search%7Cga%7C1%7Ccheesewire)
To use, add a `ConductorViewBinder` to your base controller:
```kotlin
abstract class BaseController : Controller() {
protected val views = ConductorViewBinder(this)
}
```
This can now be used to bind views in your concrete controllers:
```kotlin
class HomeController : BaseController() {
private val btnLogin: Button by views.bind(R.id.btn_login)
}
```
during `onDestroyView`, the view binder is reset, and your views aren't leaked.
See the [sample app](https://github.com/hannesstruss/cheesewire/tree/master/sample) for an example.
## Generic lazy
CheeseWire view binders also provide a generic lazy property delegate which
is synchronized with your view property lifecycle. This comes in handy e.g. in
combination with [RxBinding](https://github.com/JakeWharton/RxBinding) when you
want to avoid calling the RxBinding methods twice on a view:
```kotlin
class MyMviController : BaseController() {
private val btnLogin: Button by views.bind(R.id.btn_login)
private val btnSignup: Button by views.bind(R.id.btn_login)
val intentions by views.lazy {
Observable.merge(
btnLogin.clicks().map { Intention.Login },
btnSignup.clicks().map { Intention.Signup }
)
}
}
```
## Download
```groovy
dependencies {
implementation 'de.hannesstruss.cheesewire:cheesewire-conductor:0.2'
}
```
## Attributions :bow:
CheeseWire is inspired by the awesome work of [ButterKnife](http://jakewharton.github.io/butterknife/),
[KotterKnife](https://github.com/JakeWharton/kotterknife) and
[ButterknifeConductor](https://gist.github.com/EricKuck/05887d898c85ae4c47bf88b2cd127e71).
## License
Copyright (C) 2017 Hannes Struss
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.