Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginPresenter implements LoginPresenterInterface, IListener<User> {
- LoginView iLoginView;
- LoginServiceInterface iLoginService;
- public LoginPresenter(LoginView loginView){
- iLoginView = loginView;
- iLoginService = new LoginService();
- }
- @Override
- public void validateCredentials(){
- String username = iLoginView.getUsername();
- /**
- * Check if username is empty or not
- */
- if(username.isEmpty()){
- iLoginView.showError("Username cannot be empty");
- return;
- }
- String password = iLoginView.getPassword();
- /**
- * Check if password is empty or not
- */
- if(password.isEmpty()){
- iLoginView.showError("Password cannot be empty");
- return;
- }
- /**
- * Call login service to authenticate user credentials from the backend
- */
- iLoginService.validateCredentialsFromBackendService(username, password, this);
- }
- @Override
- public void onSuccess(User user){
- /**
- * After successful authentication take the user to the main activity
- */
- iLoginView.navigateToMainActivity();
- }
- @Override
- public void onFailure(String errorMessage){
- /**
- * Show error message if the authentication fails
- */
- iLoginView.showError(errorMessage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement