Last active
September 24, 2018 07:33
-
-
Save Lamartio/b3dc52bfaf7e7c6aab3e563c8d82895c to your computer and use it in GitHub Desktop.
kotlins_simple_layout_trick_pt2_bind_implementation.kt
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
open class BindableLayout<T, V : ViewGroup>(layout: V) : Layout<V>(layout) { | |
private val observers = Observers() | |
fun bind(observer: Observer<T>) { | |
observers.add(observer) | |
} | |
private inner class Observers : ArrayList<Observer<T>>(), Consumer<T> { | |
override fun accept(value: T) = | |
forEach { observer -> observer(value, value) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment