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() {
Toast.makeText(ChangePasswordActivity.this,R.string.password_changed,Toast.LENGTH_LONG).show();
finish();
}
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() {
mNewPassword.setError(getString(R.string.could_not_change_password));
mChangePasswordButton.setEnabled(true);
mChangePasswordButton.setTextColor(getPrimaryTextColor());
mChangePasswordButton.setText(R.string.change_password);
}
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,110 +1,109 @@
<?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">
<ScrollView
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_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">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button_bar">
<TextView
android:id="@+id/current_password_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/current_password"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
<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:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<EditText
android:id="@+id/current_password"
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"/>
<TextView
android:id="@+id/current_password_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/current_password"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/new_password"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="64sp">
<EditText
android:id="@+id/new_password"
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"/>
<com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText
android:id="@+id/current_password"
android:layout_alignParentTop="true"
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"/>
</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"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/new_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>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="56sp">
<LinearLayout
android:id="@+id/button_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
<com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText
android:id="@+id/new_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
app:tint_color="?attr/color_text_secondary"/>
</RelativeLayout>
<Button
android:id="@+id/left_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"/>
</LinearLayout>
</ScrollView>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginBottom="7dp"
android:layout_marginTop="7dp"
android:background="?attr/divider"/>
<LinearLayout
android:id="@+id/button_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true">
<Button
android:id="@+id/right_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/change_password"/>
</LinearLayout>
<Button
android:id="@+id/left_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"/>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginBottom="7dp"
android:layout_marginTop="7dp"
android:background="?attr/divider"/>
<Button
android:id="@+id/right_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/change_password"/>
</LinearLayout>
</RelativeLayout>