Login Error Handeling
This commit is contained in:
@@ -15,7 +15,9 @@ import android.view.View;
|
|||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
|
|
||||||
@@ -25,20 +27,15 @@ import static de.sebse.fuplanner.services.fulogin.UserLoginTask.PARAM_USER_PASS;
|
|||||||
* A login screen that offers login via email/password.
|
* A login screen that offers login via email/password.
|
||||||
*/
|
*/
|
||||||
public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
||||||
|
|
||||||
/**
|
|
||||||
* Id to identity READ_CONTACTS permission request.
|
|
||||||
*/
|
|
||||||
private static final int REQUEST_READ_CONTACTS = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep track of the login task to ensure we can cancel it if requested.
|
* Keep track of the login task to ensure we can cancel it if requested.
|
||||||
*/
|
*/
|
||||||
UserLoginTask mAuthTask = null;
|
UserLoginTask mAuthTask = null;
|
||||||
|
|
||||||
// UI references.
|
// UI references.
|
||||||
private EditText mEmailView;
|
private TextInputEditText mEmailView;
|
||||||
EditText mPasswordView;
|
TextInputEditText mPasswordView;
|
||||||
|
TextView mErrorView;
|
||||||
private View mProgressView;
|
private View mProgressView;
|
||||||
private View mLoginFormView;
|
private View mLoginFormView;
|
||||||
|
|
||||||
@@ -61,6 +58,7 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
|||||||
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
|
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
|
||||||
|
|
||||||
setContentView(R.layout.activity_fu_authenticator);
|
setContentView(R.layout.activity_fu_authenticator);
|
||||||
|
mErrorView = findViewById(R.id.error_textview);
|
||||||
// Set up the login form.
|
// Set up the login form.
|
||||||
mEmailView = findViewById(R.id.input_username);
|
mEmailView = findViewById(R.id.input_username);
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
|||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
AtomicReference<String> login = new AtomicReference<>();
|
AtomicReference<String> login = new AtomicReference<>();
|
||||||
NetworkErrorCallback errorFunc = error -> {
|
NetworkErrorCallback errorFunc = error -> {
|
||||||
login.set("Error: "+String.valueOf(error.getCode()));
|
|
||||||
log.e(error);
|
log.e(error);
|
||||||
|
login.set("Error: "+String.valueOf(error.getCode()));
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
};
|
};
|
||||||
switch (mTokenType) {
|
switch (mTokenType) {
|
||||||
@@ -113,16 +113,20 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
|||||||
mActivity.mAuthTask = null;
|
mActivity.mAuthTask = null;
|
||||||
mActivity.showProgress(false);
|
mActivity.showProgress(false);
|
||||||
|
|
||||||
if (success != null) {
|
if (success != null && !success.startsWith("Error: ")) {
|
||||||
final Intent res = new Intent();
|
final Intent res = new Intent();
|
||||||
res.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
|
res.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
|
||||||
res.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE);
|
res.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE);
|
||||||
res.putExtra(AccountManager.KEY_AUTHTOKEN, success);
|
res.putExtra(AccountManager.KEY_AUTHTOKEN, success);
|
||||||
res.putExtra(PARAM_USER_PASS, mPassword);
|
res.putExtra(PARAM_USER_PASS, mPassword);
|
||||||
mActivity.finishLogin(res);
|
mActivity.finishLogin(res);
|
||||||
} else {
|
} else if (success != null && (success.contains("100143") || success.contains("100243"))) {
|
||||||
mActivity.mPasswordView.setError(mActivity.getString(R.string.error_incorrect_password));
|
mActivity.mPasswordView.setError(mActivity.getString(R.string.error_incorrect_password));
|
||||||
mActivity.mPasswordView.requestFocus();
|
mActivity.mPasswordView.requestFocus();
|
||||||
|
} else if (success != null) {
|
||||||
|
mActivity.mErrorView.setText(mActivity.getString(R.string.network_error_parameter, success.substring(7)));
|
||||||
|
} else {
|
||||||
|
mActivity.mErrorView.setText(R.string.network_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,16 +41,24 @@
|
|||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:contentDescription="@string/cd_ic_launcher"/>
|
android:contentDescription="@string/cd_ic_launcher"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/error_textview"
|
||||||
|
android:textAppearance="@style/TextAppearance.Design.Error"
|
||||||
|
android:textColor="@color/colorFURed"
|
||||||
|
tools:text="@string/hello_blank_fragment" />
|
||||||
|
|
||||||
<!-- Email Label -->
|
<!-- Email Label -->
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginBottom="8dp">
|
android:layout_marginBottom="8dp">
|
||||||
<EditText android:id="@+id/input_username"
|
<com.google.android.material.textfield.TextInputEditText android:id="@+id/input_username"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="textEmailAddress"
|
android:inputType="textNoSuggestions"
|
||||||
android:hint="@string/username"
|
android:hint="@string/username"
|
||||||
android:autofillHints="username"
|
android:autofillHints="username"
|
||||||
tools:targetApi="o" />
|
tools:targetApi="o" />
|
||||||
@@ -62,7 +70,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginBottom="8dp">
|
android:layout_marginBottom="8dp">
|
||||||
<EditText android:id="@+id/input_password"
|
<com.google.android.material.textfield.TextInputEditText android:id="@+id/input_password"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
|
|||||||
@@ -112,4 +112,6 @@
|
|||||||
<string name="event_removed">Event entfernt: %1$s</string>
|
<string name="event_removed">Event entfernt: %1$s</string>
|
||||||
<string name="gradebook_removed">Noteneintrag entfernt: %1$s</string>
|
<string name="gradebook_removed">Noteneintrag entfernt: %1$s</string>
|
||||||
<string name="resource_removed">Ressource entfernt: %1$s</string>
|
<string name="resource_removed">Ressource entfernt: %1$s</string>
|
||||||
|
<string name="network_error">Ein Netzwerkfehler ist aufgetreten!</string>
|
||||||
|
<string name="network_error_parameter">Ein Netzwerkfehler ist aufgetreten: %s!</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -120,4 +120,6 @@
|
|||||||
<string name="resource_updated">Resource updated: %1$s</string>
|
<string name="resource_updated">Resource updated: %1$s</string>
|
||||||
<string name="resource_added">New resource: %1$s</string>
|
<string name="resource_added">New resource: %1$s</string>
|
||||||
<string name="resource_removed">Resource removed: %1$s</string>
|
<string name="resource_removed">Resource removed: %1$s</string>
|
||||||
|
<string name="network_error">A network error occured!</string>
|
||||||
|
<string name="network_error_parameter">A network error occured: %s!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user