diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-03-15 21:28:30 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-03-15 21:28:30 +0100 |
commit | 4d5754ac5ddbe0f02f8afd8b5b9a0bae4bfc633d (patch) | |
tree | faabd510a99a684fa46db9302ec4045fd97d05ef /src/main/java/de/pixart/messenger | |
parent | 1bfaacc66fd3ba1640a5d09a9b27a47df89bc99d (diff) |
Change ShowHidePasswordEditText to TextInputEditText.
change the input fields in the AccountActivity to use the TextInputLayout.
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ChangePasswordActivity.java | 12 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/EditAccountActivity.java | 54 |
2 files changed, 30 insertions, 36 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ChangePasswordActivity.java b/src/main/java/de/pixart/messenger/ui/ChangePasswordActivity.java index 49a826f29..b73393b0c 100644 --- a/src/main/java/de/pixart/messenger/ui/ChangePasswordActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ChangePasswordActivity.java @@ -5,7 +5,6 @@ import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; -import android.widget.TextView; import android.widget.Toast; import de.pixart.messenger.R; @@ -21,20 +20,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()); @@ -43,20 +37,16 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti } } }; - private TextView mCurrentPasswordLabel; private EditText mCurrentPassword; private EditText mNewPassword; - private EditText mNewPasswordConfirm; private Account mAccount; @Override void onBackendConnected() { this.mAccount = extractAccount(getIntent()); if (this.mAccount != null && this.mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)) { - this.mCurrentPasswordLabel.setVisibility(View.GONE); this.mCurrentPassword.setVisibility(View.GONE); } else { - this.mCurrentPasswordLabel.setVisibility(View.VISIBLE); this.mCurrentPassword.setVisibility(View.VISIBLE); } } @@ -74,10 +64,8 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti }); this.mChangePasswordButton = findViewById(R.id.right_button); this.mChangePasswordButton.setOnClickListener(this.mOnChangePasswordButtonClicked); - this.mCurrentPasswordLabel = findViewById(R.id.current_password_label); this.mCurrentPassword = findViewById(R.id.current_password); this.mNewPassword = findViewById(R.id.new_password); - this.mNewPasswordConfirm = findViewById(R.id.new_password_confirm); } @Override diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 41d48af99..d407f26ac 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -1,6 +1,5 @@ package de.pixart.messenger.ui; -import android.support.v7.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.PendingIntent; import android.content.ActivityNotFoundException; @@ -10,11 +9,14 @@ import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.provider.Settings; import android.security.KeyChain; import android.security.KeyChainAliasCallback; +import android.support.design.widget.TextInputLayout; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; +import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.TextWatcher; import android.view.Menu; @@ -73,7 +75,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private static final int REQUEST_DATA_SAVER = 0x37af244; private AutoCompleteTextView mAccountJid; private EditText mPassword; - private EditText mPasswordConfirm; private CheckBox mRegisterNew; private Button mCancelButton; private Button mSaveButton; @@ -100,7 +101,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private TextView mOwnFingerprintDesc; private TextView mOtrFingerprintDesc; private TextView getmPgpFingerprintDesc; - private TextView mAccountJidLabel; + private TextInputLayout mPasswordToggle; private ImageView mAvatar; private RelativeLayout mOtrFingerprintBox; private RelativeLayout mAxolotlFingerprintBox; @@ -129,7 +130,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat @Override public void onClick(final View v) { final String password = mPassword.getText().toString(); - final String passwordConfirm = mPasswordConfirm.getText().toString(); final boolean wasDisabled = mAccount != null && mAccount.getStatus() == Account.State.DISABLED; if (!mInitMode && passwordChangedInMagicCreateMode()) { @@ -222,11 +222,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat if (XmppConnection.errorMessage != null) { Toast.makeText(EditAccountActivity.this, XmppConnection.errorMessage, Toast.LENGTH_LONG).show(); } - if (!password.equals(passwordConfirm)) { - mPasswordConfirm.setError(getString(R.string.passwords_do_not_match)); - mPasswordConfirm.requestFocus(); - return; - } } if (mAccount != null) { if (mInitMode && mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE)) { @@ -240,7 +235,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } else { mAccountJid.setError(null); } - mPasswordConfirm.setError(null); mAccount.setPassword(password); mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); if (!xmppConnectionService.updateAccount(mAccount)) { @@ -288,6 +282,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private boolean mSavedInstanceInit = false; private Button mClearDevicesButton; private XmppUri pendingUri = null; + private boolean mUseTor; public void refreshUiReal() { invalidateOptionsMenu(); @@ -371,6 +366,24 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } }; + private View.OnFocusChangeListener mEditTextFocusListener = new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean b) { + EditText et = (EditText) view; + if (b) { + int resId = mUsernameMode ? R.string.username : R.string.account_settings_example_jabber_id; + if (view.getId() == R.id.hostname) { + resId = mUseTor ? R.string.hostname_or_onion : R.string.hostname_example; + } + final int res = resId; + new Handler().postDelayed(() -> et.setHint(res), 500); + } else { + et.setHint(null); + } + } + }; + + private final OnClickListener mAvatarClickListener = new OnClickListener() { @Override public void onClick(final View view) { @@ -529,10 +542,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat setContentView(R.layout.activity_edit_account); this.mAccountJid = findViewById(R.id.account_jid); this.mAccountJid.addTextChangedListener(this.mTextWatcher); - this.mAccountJidLabel = findViewById(R.id.account_jid_label); + this.mAccountJid.setOnFocusChangeListener(this.mEditTextFocusListener); this.mPassword = findViewById(R.id.account_password); this.mPassword.addTextChangedListener(this.mTextWatcher); - this.mPasswordConfirm = findViewById(R.id.account_password_confirm); + this.mPasswordToggle = findViewById(R.id.text_input_password_toggle); this.mAvatar = findViewById(R.id.avater); this.mAvatar.setOnClickListener(this.mAvatarClickListener); this.mRegisterNew = findViewById(R.id.account_register_new); @@ -569,6 +582,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mNamePort = findViewById(R.id.name_port); this.mHostname = findViewById(R.id.hostname); this.mHostname.addTextChangedListener(mTextWatcher); + this.mHostname.setOnFocusChangeListener(mEditTextFocusListener); this.mClearDevicesButton = findViewById(R.id.clear_devices); this.mClearDevicesButton.setOnClickListener(new OnClickListener() { @Override @@ -589,13 +603,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() { @Override - public void onCheckedChanged(final CompoundButton buttonView, - final boolean isChecked) { - if (isChecked) { - mPasswordConfirm.setVisibility(View.VISIBLE); - } else { - mPasswordConfirm.setVisibility(View.GONE); - } + public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { updateSaveButton(); } }; @@ -704,9 +712,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } } SharedPreferences preferences = getPreferences(); - boolean useTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false); - this.mShowOptions = useTor || preferences.getBoolean("show_connection_options", false); - mHostname.setHint(useTor ? R.string.hostname_or_onion : R.string.hostname_example); + mUseTor = Config.FORCE_ORBOT || preferences.getBoolean("use_tor", false); + this.mShowOptions = mUseTor || preferences.getBoolean("show_connection_options", false); this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); } @@ -769,7 +776,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mCancelButton.setTextColor(getSecondaryTextColor()); } if (mUsernameMode) { - this.mAccountJidLabel.setText(R.string.username); this.mAccountJid.setHint(R.string.username_hint); } else { final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, @@ -911,6 +917,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mAccountJid.setEnabled(editable); this.mAccountJid.setFocusable(editable); this.mAccountJid.setFocusableInTouchMode(editable); + this.mPasswordToggle.setPasswordVisibilityToggleEnabled(editable); if (!mInitMode) { this.mAvatar.setVisibility(View.VISIBLE); @@ -922,7 +929,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) { this.mRegisterNew.setVisibility(View.VISIBLE); this.mRegisterNew.setChecked(true); - this.mPasswordConfirm.setText(this.mAccount.getPassword()); } else { this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setChecked(false); |