Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void bindUI(){
- txtEmail = (EditText) findViewById(R.id.txtEmail);
- txtPassword = (EditText) findViewById(R.id.txtPassword);
- swtRecordar = (Switch) findViewById(R.id.swtRecordar);
- btnLogin = (Button) findViewById(R.id.btnLogin);
- }
- private void setCredentialsIfExist() {
- String email = Util.getUserMailPrefs(prefs);
- String password = Util.getUserPassPrefs(prefs);
- boolean recordar = Util.getrecordarPrefs(prefs);
- String strRecordar = Boolean.toString(recordar);
- if(!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password) && TextUtils.equals("true", strRecordar)){
- txtEmail.setText(email);
- txtPassword.setText(password);
- swtRecordar.setChecked(recordar);
- }
- }
- private void removeSharedPreferences(SharedPreferences preferences){
- SharedPreferences.Editor editor = preferences.edit();
- editor.remove("email");
- editor.remove("pass");
- editor.remove("recordar");
- editor.apply();
- }
- private boolean login(String email, String password){
- if(!isValidEmail(email)){
- Toast.makeText(this, "Correo no válido, intente nuevamente", Toast.LENGTH_LONG).show();
- return false;
- } else if(!isValidPassword(password)){
- Toast.makeText(this, "Contraseña muy corta, intente nuevamente", Toast.LENGTH_LONG).show();
- return false;
- } else {
- return true;
- }
- }
- private void saveOnPreferences(String email, String password, boolean recordar){
- if(swtRecordar.isChecked()){
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString("email", email);
- editor.putString("pass", password);
- editor.putBoolean("recordar", recordar);
- editor.commit();
- editor.apply();
- }
- }
- private boolean isValidEmail(String email){
- email.trim();
- return !TextUtils.isEmpty(email) && Patterns.EMAIL_ADDRESS.matcher(email).matches();
- }
- private boolean isValidPassword(String password){
- password.trim();
- return password.length() > 4;
- }
- private void goToMain(){
- Intent intent = new Intent(this, MainActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement