Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. private void bindUI(){
  2. txtEmail = (EditText) findViewById(R.id.txtEmail);
  3. txtPassword = (EditText) findViewById(R.id.txtPassword);
  4. swtRecordar = (Switch) findViewById(R.id.swtRecordar);
  5. btnLogin = (Button) findViewById(R.id.btnLogin);
  6. }
  7.  
  8. private void setCredentialsIfExist() {
  9. String email = Util.getUserMailPrefs(prefs);
  10. String password = Util.getUserPassPrefs(prefs);
  11. boolean recordar = Util.getrecordarPrefs(prefs);
  12. String strRecordar = Boolean.toString(recordar);
  13. if(!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password) && TextUtils.equals("true", strRecordar)){
  14. txtEmail.setText(email);
  15. txtPassword.setText(password);
  16. swtRecordar.setChecked(recordar);
  17. }
  18. }
  19.  
  20. private void removeSharedPreferences(SharedPreferences preferences){
  21. SharedPreferences.Editor editor = preferences.edit();
  22. editor.remove("email");
  23. editor.remove("pass");
  24. editor.remove("recordar");
  25. editor.apply();
  26. }
  27.  
  28. private boolean login(String email, String password){
  29. if(!isValidEmail(email)){
  30. Toast.makeText(this, "Correo no válido, intente nuevamente", Toast.LENGTH_LONG).show();
  31. return false;
  32. } else if(!isValidPassword(password)){
  33. Toast.makeText(this, "Contraseña muy corta, intente nuevamente", Toast.LENGTH_LONG).show();
  34. return false;
  35. } else {
  36. return true;
  37. }
  38. }
  39.  
  40. private void saveOnPreferences(String email, String password, boolean recordar){
  41. if(swtRecordar.isChecked()){
  42. SharedPreferences.Editor editor = prefs.edit();
  43. editor.putString("email", email);
  44. editor.putString("pass", password);
  45. editor.putBoolean("recordar", recordar);
  46. editor.commit();
  47. editor.apply();
  48. }
  49. }
  50.  
  51. private boolean isValidEmail(String email){
  52. email.trim();
  53. return !TextUtils.isEmpty(email) && Patterns.EMAIL_ADDRESS.matcher(email).matches();
  54. }
  55.  
  56. private boolean isValidPassword(String password){
  57. password.trim();
  58. return password.length() > 4;
  59. }
  60.  
  61. private void goToMain(){
  62. Intent intent = new Intent(this, MainActivity.class);
  63. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  64. startActivity(intent);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement