From 193d2645e6995a2631a16c88c78e3b0b5581cbc6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 25 Dec 2014 22:28:19 +0100 Subject: code cleanup for change password stuff --- .../conversations/ui/EditAccountActivity.java | 33 +++++++++++++--------- src/main/res/layout/activity_edit_account.xml | 2 +- src/main/res/values/strings.xml | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 3bd4dd1e..f8221f1b 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -94,8 +94,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate final String passwordConfirm = mPasswordConfirm.getText().toString(); if (registerNewAccount || changePassword) { if (!password.equals(passwordConfirm)) { - mPasswordConfirm - .setError(getString(R.string.passwords_do_not_match)); + mPasswordConfirm.setError(getString(R.string.passwords_do_not_match)); mPasswordConfirm.requestFocus(); return; } @@ -210,18 +209,26 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate @Override public void afterTextChanged(final Editable s) { - final boolean registrationReady = mAccount != null && + toggleChangePasswordCheckbox(); + } + }; + + private void toggleChangePasswordCheckbox() { + final boolean registrationReady = mAccount != null && mAccount.isOnlineAndConnected() && mAccount.getXmppConnection().getFeatures().register(); - if (jidToEdit != null && mAccount != null && registrationReady && - !mAccount.getPassword().equals(s.toString()) && !"".equals(s.toString())) { - mChangePassword.setVisibility(View.VISIBLE); - } else { - mChangePassword.setVisibility(View.INVISIBLE); - mChangePassword.setChecked(false); - } + if (passwordFieldEdited() && registrationReady) { + mChangePassword.setVisibility(View.VISIBLE); + } else { + mChangePassword.setVisibility(View.INVISIBLE); + mChangePassword.setChecked(false); } - }; + } + + private boolean passwordFieldEdited() { + final String password = this.mPassword.getText().toString(); + return jidToEdit != null && mAccount != null && !password.isEmpty() && !mAccount.getPassword().equals(password); + } private final OnClickListener mAvatarClickListener = new OnClickListener() { @Override public void onClick(final View view) { @@ -448,8 +455,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mChangePassword.setVisibility(View.GONE); this.mChangePassword.setChecked(false); } - if (this.mAccount.getStatus() == Account.State.ONLINE - && !this.mFetchingAvatar) { + if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) { + toggleChangePasswordCheckbox(); this.mStats.setVisibility(View.VISIBLE); this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection() .getLastSessionEstablished())); diff --git a/src/main/res/layout/activity_edit_account.xml b/src/main/res/layout/activity_edit_account.xml index cb626780..d2987253 100644 --- a/src/main/res/layout/activity_edit_account.xml +++ b/src/main/res/layout/activity_edit_account.xml @@ -84,7 +84,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:text="@string/change_password" + android:text="@string/change_password_on_server" android:textColor="@color/primarytext" android:textSize="?attr/TextSizeBody" /> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6634c96a..f75a698b 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -46,7 +46,7 @@ Contact blocked Would you like to remove %s as a bookmark? The conversation associated with this bookmark will not be removed. Register new account on server - Change password + Change password on server Share with Start Conversation Invite Contact -- cgit v1.2.3