mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-08-02 04:00:52 +00:00
better feedback on user login
This commit is contained in:
parent
d0e0094a86
commit
29db6a99cc
4 changed files with 51 additions and 15 deletions
|
|
@ -50,10 +50,10 @@ dependencies {
|
|||
transitive = true
|
||||
}
|
||||
|
||||
compile 'com.android.support:appcompat-v7:23.0.1'
|
||||
compile 'com.android.support:design:23.0.1'
|
||||
compile 'com.android.support:gridlayout-v7:23.0.1'
|
||||
compile 'com.android.support:recyclerview-v7:23.0.1'
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile 'com.android.support:design:23.1.1'
|
||||
compile 'com.android.support:gridlayout-v7:23.1.1'
|
||||
compile 'com.android.support:recyclerview-v7:23.1.1'
|
||||
|
||||
// Image Loading/Caching
|
||||
compile 'com.squareup.picasso:picasso:2.5.2'
|
||||
|
|
|
|||
|
|
@ -120,6 +120,13 @@
|
|||
<string name="internal_error_api">There seems to be a problem with the server. Try again later.</string>
|
||||
<string name="network_up">Your internet connection just got back!</string>
|
||||
|
||||
<string name="authentication_error_title">Authentication Error</string>
|
||||
<string name="authentication_error_body">Your Username and/or Password was incorrect.</string>
|
||||
|
||||
<string name="login_validation_error_title">Validation Error</string>
|
||||
<string name="login_validation_error_fieldsmissing">You have to fill out all fields.</string>
|
||||
<string name="login_validation_error_invalid_email">Invalid email address.</string>
|
||||
|
||||
<string name="checklist.title.add">Add checklist</string>
|
||||
<string name="checklist.title.edit">Edit checklist</string>
|
||||
<string name="checklist.item.hint">Add item…</string>
|
||||
|
|
|
|||
|
|
@ -184,23 +184,31 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
if (cause.getKind().equals(RetrofitError.Kind.NETWORK)) {
|
||||
//It also handles timeouts
|
||||
showConnectionProblemDialog(activity, R.string.network_error_no_network_body);
|
||||
}else{
|
||||
/*
|
||||
* CONVERSION An exception was thrown while (de)serializing a body.
|
||||
* HTTP A non-200 HTTP status code was received from the server e.g. 502, 503, etc...
|
||||
* UNEXPECTED An internal error occurred while attempting to execute a request.
|
||||
*/
|
||||
showConnectionProblemDialog(activity,R.string.internal_error_api);
|
||||
}
|
||||
return cause;
|
||||
} else if (cause.getKind().equals(RetrofitError.Kind.HTTP)) {
|
||||
int status = cause.getResponse().getStatus();
|
||||
if (status == 401) {
|
||||
showConnectionProblemDialog(activity, R.string.authentication_error_title, R.string.authentication_error_body);
|
||||
return cause;
|
||||
} else if (status >= 500 && status < 600) {
|
||||
showConnectionProblemDialog(activity,R.string.internal_error_api);
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
showConnectionProblemDialog(activity, R.string.internal_error_api);
|
||||
|
||||
return cause;
|
||||
return cause;
|
||||
}
|
||||
|
||||
private void showConnectionProblemDialog(final Activity activity, final int resourceMessageString){
|
||||
private void showConnectionProblemDialog(final Activity activity, final int resourceMessageString) {
|
||||
showConnectionProblemDialog(activity, R.string.network_error_title, resourceMessageString);
|
||||
}
|
||||
|
||||
private void showConnectionProblemDialog(final Activity activity, final int resourceTitleString, final int resourceMessageString){
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.network_error_title)
|
||||
.setTitle(resourceTitleString)
|
||||
.setMessage(resourceMessageString)
|
||||
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
|
|
|||
|
|
@ -159,11 +159,19 @@ public class LoginActivity extends AppCompatActivity
|
|||
email = String.valueOf(mEmail.getText());
|
||||
password = String.valueOf(mPasswordET.getText());
|
||||
cpassword = String.valueOf(mConfirmPassword.getText());
|
||||
if (username.length() == 0 || password.length() == 0 || email.length() == 0 || cpassword.length() == 0) {
|
||||
showValidationError(R.string.login_validation_error_fieldsmissing);
|
||||
return;
|
||||
}
|
||||
mApiHelper.registerUser(v,username,email,password,cpassword);
|
||||
} else {
|
||||
String username,password;
|
||||
username = String.valueOf(mUsernameET.getText());
|
||||
password = String.valueOf(mPasswordET.getText());
|
||||
if (username.length() == 0 || password.length() == 0) {
|
||||
showValidationError(R.string.login_validation_error_fieldsmissing);
|
||||
return;
|
||||
}
|
||||
mApiHelper.connectUser(username,password, LoginActivity.this);
|
||||
}
|
||||
}
|
||||
|
|
@ -316,4 +324,17 @@ public class LoginActivity extends AppCompatActivity
|
|||
mProgressBar.setVisibility(View.GONE);
|
||||
showSnackbar(getString(R.string.unknown_error));
|
||||
}
|
||||
|
||||
private void showValidationError(int resourceMessageString) {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
new android.support.v7.app.AlertDialog.Builder(this)
|
||||
.setTitle(R.string.login_validation_error_title)
|
||||
.setMessage(resourceMessageString)
|
||||
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.setIcon(R.drawable.ic_warning_black)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue