Advertisement
Guest User

Untitled

a guest
May 11th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public class LoginPresenter implements LoginPresenterInterface, IListener<User> {
  2.  
  3. LoginView iLoginView;
  4. LoginServiceInterface iLoginService;
  5.  
  6. public LoginPresenter(LoginView loginView){
  7. iLoginView = loginView;
  8. iLoginService = new LoginService();
  9. }
  10.  
  11. @Override
  12. public void validateCredentials(){
  13. String username = iLoginView.getUsername();
  14. /**
  15. * Check if username is empty or not
  16. */
  17. if(username.isEmpty()){
  18. iLoginView.showError("Username cannot be empty");
  19. return;
  20. }
  21.  
  22. String password = iLoginView.getPassword();
  23. /**
  24. * Check if password is empty or not
  25. */
  26. if(password.isEmpty()){
  27. iLoginView.showError("Password cannot be empty");
  28. return;
  29. }
  30.  
  31. /**
  32. * Call login service to authenticate user credentials from the backend
  33. */
  34. iLoginService.validateCredentialsFromBackendService(username, password, this);
  35. }
  36.  
  37. @Override
  38. public void onSuccess(User user){
  39. /**
  40. * After successful authentication take the user to the main activity
  41. */
  42. iLoginView.navigateToMainActivity();
  43. }
  44.  
  45. @Override
  46. public void onFailure(String errorMessage){
  47. /**
  48. * Show error message if the authentication fails
  49. */
  50. iLoginView.showError(errorMessage);
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement