Last active
March 9, 2018 09:30
-
-
Save marciogranzotto/d974d2819b3447dde0ec3db1d9e0d7eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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