Skip to content

Instantly share code, notes, and snippets.

@marciogranzotto
Last active March 9, 2018 09:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciogranzotto/d974d2819b3447dde0ec3db1d9e0d7eb to your computer and use it in GitHub Desktop.
Save marciogranzotto/d974d2819b3447dde0ec3db1d9e0d7eb to your computer and use it in GitHub Desktop.
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