Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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