Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class LoginContracts {
interface View {
fun showError(message: String)
//fun presentHomeScreen(user: User) <- This is no longer a part of the View's responsibilities
}
interface Router {
fun presentHomeScreen(user: User) // Now the router handles it
}
}
class LoginPresenter(var view: LoginContracts.View?): LoginContracts.Presenter, LoginContracts.InteractorOutput {
var interactor: LoginContracts.Interactor? = LoginInteractor(this)
//now the presenter has a instance of the Router and passes the Activity to it on the constructor
var router: LoginContracts.Router? = LoginRouter(view as? Activity)
//...
fun onLoginSuccess(user: User) {
router?.presentHomeScreen(user)
}
//...
}
class LoginRouter(var activity: Activity?): LoginContracts.Router {
fun presentHomeScreen(user: User) {
val intent = Intent(view, HomeActivity::class.java)
intent.putExtra(Constants.IntentExtras.USER, user)
activity?.startActivity(intent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment