Moved the error message to TextInputLayout in the ChangePasswordActivity
This commit is contained in:
parent
235275ba91
commit
c7fd54a17e
|
@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.TextInputLayout;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
@ -23,13 +24,15 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
|
||||||
final String newPassword = mNewPassword.getText().toString();
|
final String newPassword = mNewPassword.getText().toString();
|
||||||
if (!mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && !currentPassword.equals(mAccount.getPassword())) {
|
if (!mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && !currentPassword.equals(mAccount.getPassword())) {
|
||||||
mCurrentPassword.requestFocus();
|
mCurrentPassword.requestFocus();
|
||||||
mCurrentPassword.setError(getString(R.string.account_status_unauthorized));
|
mCurrentPasswordLayout.setError(getString(R.string.account_status_unauthorized));
|
||||||
|
removeErrorsOnAllBut(mCurrentPasswordLayout);
|
||||||
} else if (newPassword.trim().isEmpty()) {
|
} else if (newPassword.trim().isEmpty()) {
|
||||||
mNewPassword.requestFocus();
|
mNewPassword.requestFocus();
|
||||||
mNewPassword.setError(getString(R.string.password_should_not_be_empty));
|
mNewPasswordLayout.setError(getString(R.string.password_should_not_be_empty));
|
||||||
|
removeErrorsOnAllBut(mNewPasswordLayout);
|
||||||
} else {
|
} else {
|
||||||
mCurrentPassword.setError(null);
|
mCurrentPasswordLayout.setError(null);
|
||||||
mNewPassword.setError(null);
|
mNewPasswordLayout.setError(null);
|
||||||
xmppConnectionService.updateAccountPasswordOnServer(mAccount, newPassword, ChangePasswordActivity.this);
|
xmppConnectionService.updateAccountPasswordOnServer(mAccount, newPassword, ChangePasswordActivity.this);
|
||||||
mChangePasswordButton.setEnabled(false);
|
mChangePasswordButton.setEnabled(false);
|
||||||
mChangePasswordButton.setTextColor(getSecondaryTextColor());
|
mChangePasswordButton.setTextColor(getSecondaryTextColor());
|
||||||
|
@ -40,6 +43,8 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
|
||||||
};
|
};
|
||||||
private EditText mCurrentPassword;
|
private EditText mCurrentPassword;
|
||||||
private EditText mNewPassword;
|
private EditText mNewPassword;
|
||||||
|
private TextInputLayout mNewPasswordLayout;
|
||||||
|
private TextInputLayout mCurrentPasswordLayout;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,6 +69,8 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
|
||||||
this.mCurrentPassword.setCustomSelectionActionModeCallback(new DisabledActionModeCallback());
|
this.mCurrentPassword.setCustomSelectionActionModeCallback(new DisabledActionModeCallback());
|
||||||
this.mNewPassword = findViewById(R.id.new_password);
|
this.mNewPassword = findViewById(R.id.new_password);
|
||||||
this.mNewPassword.setCustomSelectionActionModeCallback(new DisabledActionModeCallback());
|
this.mNewPassword.setCustomSelectionActionModeCallback(new DisabledActionModeCallback());
|
||||||
|
this.mCurrentPasswordLayout = findViewById(R.id.current_password_layout);
|
||||||
|
this.mNewPasswordLayout = findViewById(R.id.new_password_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,7 +95,7 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
|
||||||
@Override
|
@Override
|
||||||
public void onPasswordChangeFailed() {
|
public void onPasswordChangeFailed() {
|
||||||
runOnUiThread(() -> {
|
runOnUiThread(() -> {
|
||||||
mNewPassword.setError(getString(R.string.could_not_change_password));
|
mNewPasswordLayout.setError(getString(R.string.could_not_change_password));
|
||||||
mChangePasswordButton.setEnabled(true);
|
mChangePasswordButton.setEnabled(true);
|
||||||
mChangePasswordButton.setTextColor(getPrimaryTextColor());
|
mChangePasswordButton.setTextColor(getPrimaryTextColor());
|
||||||
mChangePasswordButton.setText(R.string.change_password);
|
mChangePasswordButton.setText(R.string.change_password);
|
||||||
|
@ -96,6 +103,18 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeErrorsOnAllBut(TextInputLayout exception) {
|
||||||
|
if (this.mCurrentPasswordLayout != exception) {
|
||||||
|
this.mCurrentPasswordLayout.setErrorEnabled(false);
|
||||||
|
this.mCurrentPasswordLayout.setError(null);
|
||||||
|
}
|
||||||
|
if (this.mNewPasswordLayout != exception) {
|
||||||
|
this.mNewPasswordLayout.setErrorEnabled(false);
|
||||||
|
this.mNewPasswordLayout.setError(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void refreshUiReal() {
|
public void refreshUiReal() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
|
|
||||||
<android.support.design.widget.TextInputLayout
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/current_password_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:passwordToggleDrawable="@drawable/visibility_toggle_drawable"
|
app:passwordToggleDrawable="@drawable/visibility_toggle_drawable"
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
</android.support.design.widget.TextInputLayout>
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
<android.support.design.widget.TextInputLayout
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:id="@+id/new_password_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:passwordToggleDrawable="@drawable/visibility_toggle_drawable"
|
app:passwordToggleDrawable="@drawable/visibility_toggle_drawable"
|
||||||
|
|
Loading…
Reference in New Issue