mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Better messaging for the user.
This commit is contained in:
parent
f55c27a625
commit
3d0d48745e
5 changed files with 93 additions and 20 deletions
|
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v7.app.AppCompatDelegate;
|
import android.support.v7.app.AppCompatDelegate;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
|
@ -17,7 +18,6 @@ import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.BuildConfig;
|
import fr.free.nrw.commons.BuildConfig;
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
|
|
@ -46,6 +46,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
||||||
ProgressDialog progressDialog;
|
ProgressDialog progressDialog;
|
||||||
private LoginTextWatcher textWatcher = new LoginTextWatcher();
|
private LoginTextWatcher textWatcher = new LoginTextWatcher();
|
||||||
private CommonsApplication app;
|
private CommonsApplication app;
|
||||||
|
private ViewGroup errorMessageContainer;
|
||||||
|
private TextView errorMessage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -63,6 +65,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
||||||
usernameEdit = findViewById(R.id.loginUsername);
|
usernameEdit = findViewById(R.id.loginUsername);
|
||||||
passwordEdit = findViewById(R.id.loginPassword);
|
passwordEdit = findViewById(R.id.loginPassword);
|
||||||
twoFactorEdit = findViewById(R.id.loginTwoFactor);
|
twoFactorEdit = findViewById(R.id.loginTwoFactor);
|
||||||
|
errorMessageContainer = findViewById(R.id.error_message_container);
|
||||||
|
errorMessage = findViewById(R.id.error_message);
|
||||||
|
|
||||||
prefs = getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
|
prefs = getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
|
||||||
|
|
||||||
|
|
@ -216,24 +220,24 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
||||||
public void askUserForTwoFactorAuth() {
|
public void askUserForTwoFactorAuth() {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
twoFactorEdit.setVisibility(View.VISIBLE);
|
twoFactorEdit.setVisibility(View.VISIBLE);
|
||||||
showUserToastAndCancelDialog(R.string.login_failed_2fa_needed);
|
showMessageAndCancelDialog(R.string.login_failed_2fa_needed);
|
||||||
} else {
|
} else {
|
||||||
showUserToastAndCancelDialog(R.string.login_failed_2fa_not_supported);
|
showMessageAndCancelDialog(R.string.login_failed_2fa_not_supported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showUserToastAndCancelDialog(int resId) {
|
public void showMessageAndCancelDialog(@StringRes int resId) {
|
||||||
showUserToast(resId);
|
showMessage(resId);
|
||||||
progressDialog.cancel();
|
progressDialog.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showUserToast(int resId) {
|
private void showMessage(@StringRes int resId) {
|
||||||
Toast.makeText(this, resId, Toast.LENGTH_LONG).show();
|
errorMessage.setText(getString(resId));
|
||||||
|
errorMessageContainer.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSuccessToastAndDismissDialog() {
|
public void showSuccessAndDismissDialog() {
|
||||||
Toast successToast = Toast.makeText(this, R.string.login_success, Toast.LENGTH_SHORT);
|
showMessage(R.string.login_success);
|
||||||
successToast.show();
|
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class LoginTask extends AsyncTask<String, String, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePassResult() {
|
private void handlePassResult() {
|
||||||
loginActivity.showSuccessToastAndDismissDialog();
|
loginActivity.showSuccessAndDismissDialog();
|
||||||
|
|
||||||
AccountAuthenticatorResponse response = null;
|
AccountAuthenticatorResponse response = null;
|
||||||
|
|
||||||
|
|
@ -99,27 +99,27 @@ class LoginTask extends AsyncTask<String, String, String> {
|
||||||
private void handleOtherResults(String result) {
|
private void handleOtherResults(String result) {
|
||||||
if (result.equals("NetworkFailure")) {
|
if (result.equals("NetworkFailure")) {
|
||||||
// Matches NetworkFailure which is created by the doInBackground method
|
// Matches NetworkFailure which is created by the doInBackground method
|
||||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_network);
|
loginActivity.showMessageAndCancelDialog(R.string.login_failed_network);
|
||||||
} else if (result.toLowerCase().contains("nosuchuser".toLowerCase()) || result.toLowerCase().contains("noname".toLowerCase())) {
|
} else if (result.toLowerCase().contains("nosuchuser".toLowerCase()) || result.toLowerCase().contains("noname".toLowerCase())) {
|
||||||
// Matches nosuchuser, nosuchusershort, noname
|
// Matches nosuchuser, nosuchusershort, noname
|
||||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_username);
|
loginActivity.showMessageAndCancelDialog(R.string.login_failed_username);
|
||||||
loginActivity.emptySensitiveEditFields();
|
loginActivity.emptySensitiveEditFields();
|
||||||
} else if (result.toLowerCase().contains("wrongpassword".toLowerCase())) {
|
} else if (result.toLowerCase().contains("wrongpassword".toLowerCase())) {
|
||||||
// Matches wrongpassword, wrongpasswordempty
|
// Matches wrongpassword, wrongpasswordempty
|
||||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_password);
|
loginActivity.showMessageAndCancelDialog(R.string.login_failed_password);
|
||||||
loginActivity.emptySensitiveEditFields();
|
loginActivity.emptySensitiveEditFields();
|
||||||
} else if (result.toLowerCase().contains("throttle".toLowerCase())) {
|
} else if (result.toLowerCase().contains("throttle".toLowerCase())) {
|
||||||
// Matches unknown throttle error codes
|
// Matches unknown throttle error codes
|
||||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_throttled);
|
loginActivity.showMessageAndCancelDialog(R.string.login_failed_throttled);
|
||||||
} else if (result.toLowerCase().contains("userblocked".toLowerCase())) {
|
} else if (result.toLowerCase().contains("userblocked".toLowerCase())) {
|
||||||
// Matches login-userblocked
|
// Matches login-userblocked
|
||||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_blocked);
|
loginActivity.showMessageAndCancelDialog(R.string.login_failed_blocked);
|
||||||
} else if (result.equals("2FA")) {
|
} else if (result.equals("2FA")) {
|
||||||
loginActivity.askUserForTwoFactorAuth();
|
loginActivity.askUserForTwoFactorAuth();
|
||||||
} else {
|
} else {
|
||||||
// Occurs with unhandled login failure codes
|
// Occurs with unhandled login failure codes
|
||||||
Timber.d("Login failed with reason: %s", result);
|
Timber.d("Login failed with reason: %s", result);
|
||||||
loginActivity.showUserToastAndCancelDialog(R.string.login_failed_generic);
|
loginActivity.showMessageAndCancelDialog(R.string.login_failed_generic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,34 @@
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/error_message_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/title"
|
||||||
|
android:background="@color/primaryLightColor"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/error_message"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:textColor="@color/primaryDarkColor"
|
||||||
|
tools:text="Check your password, something doesnt look right" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<android.support.design.widget.TextInputLayout
|
<android.support.design.widget.TextInputLayout
|
||||||
android:id="@+id/username_container"
|
android:id="@+id/username_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/title"
|
android:layout_below="@id/error_message_container"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,34 @@
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/error_message_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/title"
|
||||||
|
android:background="@color/primaryLightColor"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/error_message"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:textColor="@color/primaryDarkColor"
|
||||||
|
tools:text="Check your password, something doesnt look right" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<android.support.design.widget.TextInputLayout
|
<android.support.design.widget.TextInputLayout
|
||||||
android:id="@+id/username_container"
|
android:id="@+id/username_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/title"
|
android:layout_below="@id/error_message_container"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,34 @@
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/error_message_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/title"
|
||||||
|
android:background="@color/primaryLightColor"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/error_message"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:textColor="@color/primaryDarkColor"
|
||||||
|
tools:text="Check your password, something doesnt look right" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<android.support.design.widget.TextInputLayout
|
<android.support.design.widget.TextInputLayout
|
||||||
android:id="@+id/username_container"
|
android:id="@+id/username_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/title"
|
android:layout_below="@id/error_message_container"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue