use show password widget in Change Password Activity

This commit is contained in:
Daniel Gultsch 2017-12-15 12:31:31 +01:00
parent a817a96c58
commit df37e34e02
2 changed files with 105 additions and 124 deletions

View File

@ -21,20 +21,15 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
if (mAccount != null) {
final String currentPassword = mCurrentPassword.getText().toString();
final String newPassword = mNewPassword.getText().toString();
final String newPasswordConfirm = mNewPasswordConfirm.getText().toString();
if (!mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && !currentPassword.equals(mAccount.getPassword())) {
mCurrentPassword.requestFocus();
mCurrentPassword.setError(getString(R.string.account_status_unauthorized));
} else if (!newPassword.equals(newPasswordConfirm)) {
mNewPasswordConfirm.requestFocus();
mNewPasswordConfirm.setError(getString(R.string.passwords_do_not_match));
} else if (newPassword.trim().isEmpty()) {
mNewPassword.requestFocus();
mNewPassword.setError(getString(R.string.password_should_not_be_empty));
} else {
mCurrentPassword.setError(null);
mNewPassword.setError(null);
mNewPasswordConfirm.setError(null);
xmppConnectionService.updateAccountPasswordOnServer(mAccount, newPassword, ChangePasswordActivity.this);
mChangePasswordButton.setEnabled(false);
mChangePasswordButton.setTextColor(getSecondaryTextColor());
@ -46,7 +41,6 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
private TextView mCurrentPasswordLabel;
private EditText mCurrentPassword;
private EditText mNewPassword;
private EditText mNewPasswordConfirm;
private Account mAccount;
@Override
@ -65,19 +59,13 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_password);
Button mCancelButton = (Button) findViewById(R.id.left_button);
mCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
this.mChangePasswordButton = (Button) findViewById(R.id.right_button);
Button mCancelButton = findViewById(R.id.left_button);
mCancelButton.setOnClickListener(view -> finish());
this.mChangePasswordButton = findViewById(R.id.right_button);
this.mChangePasswordButton.setOnClickListener(this.mOnChangePasswordButtonClicked);
this.mCurrentPasswordLabel = (TextView) findViewById(R.id.current_password_label);
this.mCurrentPassword = (EditText) findViewById(R.id.current_password);
this.mNewPassword = (EditText) findViewById(R.id.new_password);
this.mNewPasswordConfirm = (EditText) findViewById(R.id.new_password_confirm);
this.mCurrentPasswordLabel = findViewById(R.id.current_password_label);
this.mCurrentPassword = findViewById(R.id.current_password);
this.mNewPassword = findViewById(R.id.new_password);
}
@Override
@ -93,25 +81,19 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
@Override
public void onPasswordChangeSucceeded() {
runOnUiThread(new Runnable() {
@Override
public void run() {
runOnUiThread(() -> {
Toast.makeText(ChangePasswordActivity.this,R.string.password_changed,Toast.LENGTH_LONG).show();
finish();
}
});
}
@Override
public void onPasswordChangeFailed() {
runOnUiThread(new Runnable() {
@Override
public void run() {
runOnUiThread(() -> {
mNewPassword.setError(getString(R.string.could_not_change_password));
mChangePasswordButton.setEnabled(true);
mChangePasswordButton.setTextColor(getPrimaryTextColor());
mChangePasswordButton.setText(R.string.change_password);
}
});
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_secondary">
@ -8,16 +9,17 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button_bar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:background="?attr/infocard_border"
android:padding="@dimen/infocard_padding"
android:orientation="vertical">
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<TextView
android:id="@+id/current_password_label"
@ -27,16 +29,22 @@
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
<EditText
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="64sp">
<com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText
android:id="@+id/current_password"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:hint="@string/password"
android:inputType="textPassword"
android:textColor="?attr/color_text_primary"
android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
@ -45,33 +53,24 @@
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
<EditText
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="56sp">
<com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText
android:id="@+id/new_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_alignParentTop="true"
android:hint="@string/password"
android:inputType="textPassword"
android:textColor="?attr/color_text_primary"
android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody"/>
android:textSize="?attr/TextSizeBody"
app:tint_color="?attr/color_text_secondary"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account_settings_confirm_password"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
<EditText
android:id="@+id/new_password_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword"
android:textColor="?attr/color_text_primary"
android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody"/>
</LinearLayout>
</ScrollView>