This commit is contained in:
Aran Zaiger 2016-07-03 12:52:10 +03:00
commit 8c711b6cf5
3 changed files with 43 additions and 38 deletions

View file

@ -5,7 +5,7 @@
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.10" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.10" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View file

@ -177,7 +177,7 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
Log.d(TAG, "user: " + username);
Log.d(TAG, "pwd: " + password);
if(TextUtils.isEmpty(username) || !isPasswordValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) {
if(TextUtils.isEmpty(username) || !isUsernameValid(username) || TextUtils.isEmpty(password) || !isPasswordValid(password)) {
return false;
} else{
return true;
@ -187,6 +187,7 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
if (mAuthTask != null) {
return;
}
showProgress(true);
// Reset errors.
// mEmailView.setError(null);
@ -198,26 +199,12 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
// String email = mEmailView.getText().toString();
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString())) {
String username = mUsernameView.getText().toString();
String password = mPasswordView.getText().toString();
boolean cancel = false;
View focusView = null;
// Check for a valid password, if the user entered one.
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
mPasswordView.setError(getString(R.string.error_invalid_password));
focusView = mPasswordView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
showProgress(true);
// mAuthTask = new UserLoginTask(username, password); // TODO: RETRIEVE ?
// mAuthTask.execute((Void) null); // TODO: RETRIEVE ?
@ -231,10 +218,25 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
}
VolleyUtilSingleton.getInstance(LoginActivity.this).post(BASE_URL + LOGIN_PATH, tempJson, onLoginSuccess, onLoginError);
}
// Check for a valid password, if the user entered one.
// if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
// mPasswordView.setError(getString(R.string.error_invalid_password));
// focusView = mPasswordView;
// cancel = true;
// }
// if (cancel) {
// // There was an error; don't attempt login and focus the first
// // form field with an error.
// focusView.requestFocus();
// } else {
// // Show a progress spinner, and kick off a background task to
// // perform the user login attempt.
//
// }
} else {
showProgress(false);
Log.d(TAG, "Invalid params");
Log.d(TAG, "Invalid params - make sure username exist & password is 4 characters or more");
}
// Check for a valid username
@ -253,13 +255,17 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
@Override
public void onResponse(JSONObject response) {
try {
if(response.get("user") != null) {
// if(response.get("user") != null) {
if(!response.isNull("user")) {
Log.e(TAG, "onLoginSuccess => user exist"); // TODO: REMOVE console
Intent personalSpaceActivity = new Intent(LoginActivity.this, PersonalSpaceActivity.class);
Bundle b = new Bundle();
b.putString("user_id", response.getJSONObject("user").getString("id"));
personalSpaceActivity.putExtras(b);
Bundle loginUserBundle = new Bundle();
loginUserBundle.putString("user_id", response.getJSONObject("user").getString("id"));
personalSpaceActivity.putExtras(loginUserBundle);
startActivity(personalSpaceActivity);
} else {
showProgress(false);
Log.d(TAG, "No such user, " + response.get("user"));
}
}catch (Exception e) {
Log.e(TAG, "onLoginSuccess:" + e.getMessage());
@ -270,19 +276,18 @@ public class LoginActivity extends AppCompatActivity{ // implements LoaderCallba
Response.ErrorListener onLoginError = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
showProgress(false);
Log.d(TAG, "onLoginError: msg: " + error.getMessage());
}
};
private boolean isEmailValid(String email) {
//TODO: Replace this with your own logic
return email.contains("@") && email.contains(".");
private boolean isUsernameValid(String username) {
return username.length() > 0;
}
private boolean isPasswordValid(String password) {
//TODO: Replace this with your own logic
return password.length() > 4;
return password.length() > 3;
}
/**

View file

@ -4,7 +4,7 @@
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_username">Username</string>
<string name="prompt_password">Password (optional)</string>
<string name="prompt_password">Password</string>
<string name="action_login">Login</string>
<string name="action_register">Register</string>
<string name="action_sign_in_short">Sign in</string>