From b84d00330ec25e16c72f5320eca6d33f2d74f741 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Wed, 27 Feb 2013 05:31:33 +0530 Subject: [PATCH] (Bug 45370) Improve Error messages on Login Screen --- commons/commons.iml | 6 ++- commons/pom.xml | 5 +++ commons/res/layout/activity_login.xml | 9 +++- commons/res/values/strings.xml | 7 ++++ .../wikimedia/commons/auth/LoginActivity.java | 41 +++++++++++++++++-- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/commons/commons.iml b/commons/commons.iml index 869d49467..2224e7f87 100644 --- a/commons/commons.iml +++ b/commons/commons.iml @@ -46,7 +46,8 @@ - + + @@ -54,12 +55,13 @@ - + + diff --git a/commons/pom.xml b/commons/pom.xml index 9a44f3d81..5a1d009d4 100644 --- a/commons/pom.xml +++ b/commons/pom.xml @@ -56,6 +56,11 @@ acra 4.4.0 + + de.keyboardsurfer.android.widget + crouton + 1.7 + diff --git a/commons/res/layout/activity_login.xml b/commons/res/layout/activity_login.xml index dba446da6..016637e1c 100644 --- a/commons/res/layout/activity_login.xml +++ b/commons/res/layout/activity_login.xml @@ -30,7 +30,13 @@ android:layout_height="fill_parent" android:layout_margin="16dip" android:gravity="center" - android:orientation="vertical" > + android:orientation="vertical" + > + diff --git a/commons/res/values/strings.xml b/commons/res/values/strings.xml index 4534435dd..8b840ac5b 100644 --- a/commons/res/values/strings.xml +++ b/commons/res/values/strings.xml @@ -38,6 +38,13 @@ View in Browser Title Description + Login failed due to network failure + Unable to login - please check your username + Unable to login - Check your password + You have had too many unsuccessfull attempts. Please try again in 5 minutes + + Sorry, this user has been blocked on Commons + Login failed No uploads yet diff --git a/commons/src/main/java/org/wikimedia/commons/auth/LoginActivity.java b/commons/src/main/java/org/wikimedia/commons/auth/LoginActivity.java index 9b1723961..de176fc7f 100644 --- a/commons/src/main/java/org/wikimedia/commons/auth/LoginActivity.java +++ b/commons/src/main/java/org/wikimedia/commons/auth/LoginActivity.java @@ -3,6 +3,10 @@ package org.wikimedia.commons.auth; import java.io.IOException; import android.content.ContentResolver; +import android.text.Editable; +import android.text.TextWatcher; +import de.keyboardsurfer.android.widget.crouton.Crouton; +import de.keyboardsurfer.android.widget.crouton.Style; import org.wikimedia.commons.CommonsApplication; import org.wikimedia.commons.EventLog; import org.wikimedia.commons.R; @@ -75,9 +79,25 @@ public class LoginActivity extends AccountAuthenticatorActivity { ContentResolver.setSyncAutomatically(account, ContributionsContentProvider.AUTHORITY, true); // Enable sync by default! context.finish(); } else { - Toast failureToast = Toast.makeText(context, R.string.login_failed, Toast.LENGTH_LONG); + int response; + if(result.equals("NetworkFailure")) { + response = R.string.login_failed_network; + } else if(result.equals("NotExists") || result.equals("Illegal") || result.equals("NotExists")) { + response = R.string.login_failed_username; + passwordEdit.setText(""); + } else if(result.equals("EmptyPass") || result.equals("WrongPass")) { + response = R.string.login_failed_password; + passwordEdit.setText(""); + } else if(result.equals("Throttled")) { + response = R.string.login_failed_throttled; + } else if(result.equals("Blocked")) { + response = R.string.login_failed_blocked; + } else { + // Should never really happen + response = R.string.login_failed_generic; + } + Crouton.makeText(context, response, Style.ALERT, id.loginErrors).show(); dialog.dismiss(); - failureToast.show(); } } @@ -104,7 +124,7 @@ public class LoginActivity extends AccountAuthenticatorActivity { return app.getApi().login(username, password); } catch (IOException e) { // Do something better! - return "Failure"; + return "NetworkFailure"; } } @@ -119,6 +139,21 @@ public class LoginActivity extends AccountAuthenticatorActivity { usernameEdit = (EditText) findViewById(R.id.loginUsername); passwordEdit = (EditText) findViewById(R.id.loginPassword); final Activity that = this; + + usernameEdit.addTextChangedListener(new TextWatcher() { + public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) { } + + public void onTextChanged(CharSequence charSequence, int start, int count, int after) { } + + public void afterTextChanged(Editable editable) { + if(usernameEdit.getText().length() != 0) { + loginButton.setEnabled(true); + } else { + loginButton.setEnabled(false); + } + } + }); + loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {