public ContentValues generateContentValuesUser(User user) { ContentValues contentValues = new ContentValues(); contentValues.put(USERNAME_COLUMN, user.getUsername()); contentValues.put(PASSWORD_COLUMN, user.getPassword()); contentValues.put(NAME_COLUMN, user.getName()); contentValues.put(CREDITS_COLUMN, user.getCredits()); return contentValues; }
public User contentValuesUser(ContentValues contentValues) { User user = new User(); user.setPassword(contentValues.getAsString(PASSWORD_COLUMN)); user.setUsername(contentValues.getAsString(USERNAME_COLUMN)); user.setName(contentValues.getAsString(NAME_COLUMN)); user.setCredits(contentValues.getAsInteger(CREDITS_COLUMN)); return user; }
public void attemptLogin() { Intent intent; boolean cancel = false; View focusView = null; mPasswordView.setError(null); String password = mPasswordView.getText().toString(); int loginResult = userToBeLogged.getAuthentication(password, getApplicationContext()); switch (loginResult) { case OK: intent = new Intent(); intent.setClass(this, AppsListActivity.class); startActivity(intent); finish(); break; case INCORRECT: userToBeLogged = new User(); mPasswordView.setError(getString(R.string.error_incorrect_password)); focusView = mPasswordView; cancel = true; break; default: intent = new Intent(); intent.setClass(this, RegisterUserActivity.class); startActivity(intent); CharSequence text = "First access! Register a password"; Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG); toast.show(); finish(); break; } if (cancel) { focusView.requestFocus(); } else { showProgress(true); } }
public void editUserInformations(User user) { ContentValues values = generateContentValuesUser(user); database.update(TABLE_NAME, values, USERNAME_COLUMN + " = " + user.getUsername(), null); }
public void deleteUser(User user) { String[] valuesToReplace = {String.valueOf(user.getUsername())}; database.delete(TABLE_NAME, USERNAME_COLUMN + " = ?", valuesToReplace); }