Skip to content

Instantly share code, notes, and snippets.

@tomaszrykala
Created January 20, 2018 23:52
Show Gist options
  • Save tomaszrykala/7ac5f8cdb080ec567757c7c58395a764 to your computer and use it in GitHub Desktop.
Save tomaszrykala/7ac5f8cdb080ec567757c7c58395a764 to your computer and use it in GitHub Desktop.
AbcButtonsSupplierImpl.kt
class AbcButtonsSupplierImpl : AbcButtonsSupplier {
private val buttons: Map<Button, AbcButton> = mapOf(
RainbowHat.openButtonA() to AbcButton.A,
RainbowHat.openButtonB() to AbcButton.B,
RainbowHat.openButtonC() to AbcButton.C
)
private lateinit var listener: AbcButtonsSupplier.Listener
init {
buttons.keys.forEach { it.setOnButtonEventListener(this) }
}
override fun setListener(listener: AbcButtonsSupplier.Listener) {
this.listener = listener
}
override fun onButtonEvent(button: Button, pressed: Boolean) {
buttons[button]?.let { listener.onButtonEvent(it, pressed) }
}
@Throws(Exception::class)
override fun close() {
buttons.keys.forEach { it.close() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment