Last active
January 15, 2016 13:02
-
-
Save tsuharesu/eec2cd6453aad14b5c0b to your computer and use it in GitHub Desktop.
ViewBinder usage
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
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() | |
} | |
} |
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
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