Skip to content

Instantly share code, notes, and snippets.

@tsuharesu
Last active January 15, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsuharesu/eec2cd6453aad14b5c0b to your computer and use it in GitHub Desktop.
Save tsuharesu/eec2cd6453aad14b5c0b to your computer and use it in GitHub Desktop.
ViewBinder usage
class AccountActivity : AccountView {
lateinit var presenter: AccountPresenter
// Using the ViewBinder is simple
override var accountView: AccountViewModel by ViewBinder {
txt_username.text = it.userName
txt_company.text = it.company
txt_contact_email.text = it.email
txt_contact_phone.text = it.phone
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_account)
presenter = AccountPresenter(this)
}
override fun onStart() {
super.onStart()
presenter.onStart()
}
}
class AccountPresenter(private val view: AccountView) {
// […]
override fun onStart() {
api.getUserInfo()
.subscribeOnIoObserveOnUi {
view.accountView = AccountViewModel(
userName = “${it.firstName} ${it.lastName}”,
company = it.company.name,
email = it.emailAddress,
phone = it.phoneNumber ?: “”)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment