Moved the error message to TextInputLayout

This commit is contained in:
SoyaLeaf 2018-02-18 11:20:02 +08:00 committed by Daniel Gultsch
parent 22a722c06d
commit f334349cd6
2 changed files with 34 additions and 23 deletions

View File

@ -12,6 +12,7 @@ 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;
@ -74,7 +75,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private static final int REQUEST_DATA_SAVER = 0x37af244;
private AutoCompleteTextView mAccountJid;
private TextInputLayout mAccountJidLayout;
private EditText mPassword;
private TextInputLayout mPasswordLayout;
private CheckBox mRegisterNew;
private Button mCancelButton;
private Button mSaveButton;
@ -101,7 +104,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private TextView mOwnFingerprintDesc;
private TextView mOtrFingerprintDesc;
private TextView getmPgpFingerprintDesc;
private TextView mAccountJidLabel;
private ImageView mAvatar;
private RelativeLayout mOtrFingerprintBox;
private RelativeLayout mAxolotlFingerprintBox;
@ -113,7 +115,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private LinearLayout keysCard;
private LinearLayout mNamePort;
private EditText mHostname;
private TextInputLayout mHostnameLayout;
private EditText mPort;
private TextInputLayout mPortLayout;
private AlertDialog mCaptchaDialog = null;
private Jid jidToEdit;
@ -148,7 +152,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
if (mUsernameMode && mAccountJid.getText().toString().contains("@")) {
mAccountJid.setError(getString(R.string.invalid_username));
mAccountJidLayout.setError(getString(R.string.invalid_username));
mAccountJid.requestFocus();
return;
}
@ -177,9 +181,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
} catch (final InvalidJidException e) {
if (mUsernameMode) {
mAccountJid.setError(getString(R.string.invalid_username));
mAccountJidLayout.setError(getString(R.string.invalid_username));
} else {
mAccountJid.setError(getString(R.string.invalid_jid));
mAccountJidLayout.setError(getString(R.string.invalid_jid));
}
mAccountJid.requestFocus();
return;
@ -190,20 +194,20 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
hostname = mHostname.getText().toString().replaceAll("\\s","");
final String port = mPort.getText().toString().replaceAll("\\s","");
if (hostname.contains(" ")) {
mHostname.setError(getString(R.string.not_valid_hostname));
mHostnameLayout.setError(getString(R.string.not_valid_hostname));
mHostname.requestFocus();
return;
}
try {
numericPort = Integer.parseInt(port);
if (numericPort < 0 || numericPort > 65535) {
mPort.setError(getString(R.string.not_a_valid_port));
mPortLayout.setError(getString(R.string.not_a_valid_port));
mPort.requestFocus();
return;
}
} catch (NumberFormatException e) {
mPort.setError(getString(R.string.not_a_valid_port));
mPortLayout.setError(getString(R.string.not_a_valid_port));
mPort.requestFocus();
return;
}
@ -211,9 +215,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
if (jid.isDomainJid()) {
if (mUsernameMode) {
mAccountJid.setError(getString(R.string.invalid_username));
mAccountJidLayout.setError(getString(R.string.invalid_username));
} else {
mAccountJid.setError(getString(R.string.invalid_jid));
mAccountJidLayout.setError(getString(R.string.invalid_jid));
}
mAccountJid.requestFocus();
return;
@ -225,7 +229,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
mAccount.setJid(jid);
mAccount.setPort(numericPort);
mAccount.setHostname(hostname);
mAccountJid.setError(null);
mAccountJidLayout.setError(null);
mAccount.setPassword(password);
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
if (!xmppConnectionService.updateAccount(mAccount)) {
@ -234,7 +238,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
} else {
if (xmppConnectionService.findAccountByJid(jid) != null) {
mAccountJid.setError(getString(R.string.account_already_exists));
mAccountJidLayout.setError(getString(R.string.account_already_exists));
mAccountJid.requestFocus();
return;
}
@ -246,8 +250,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
xmppConnectionService.createAccount(mAccount);
}
mHostname.setError(null);
mPort.setError(null);
mHostnameLayout.setError(null);
mPortLayout.setError(null);
if (mAccount.isEnabled()
&& !registerNewAccount
&& !mInitMode) {
@ -535,8 +539,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
this.mAccountJid.addTextChangedListener(this.mTextWatcher);
this.mAccountJid.setOnFocusChangeListener(this.mEditTextFocusListener);
this.mAccountJidLayout = (TextInputLayout) findViewById(R.id.account_jid_layout);
this.mPassword = (EditText) findViewById(R.id.account_password);
this.mPassword.addTextChangedListener(this.mTextWatcher);
this.mPasswordLayout = (TextInputLayout) findViewById(R.id.account_password_layout);
this.mAvatar = (ImageView) findViewById(R.id.avater);
this.mAvatar.setOnClickListener(this.mAvatarClickListener);
this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
@ -574,6 +580,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mHostname = (EditText) findViewById(R.id.hostname);
this.mHostname.addTextChangedListener(mTextWatcher);
this.mHostname.setOnFocusChangeListener(mEditTextFocusListener);
this.mHostnameLayout = (TextInputLayout)findViewById(R.id.hostname_layout);
this.mClearDevicesButton = (Button) findViewById(R.id.clear_devices);
this.mClearDevicesButton.setOnClickListener(new OnClickListener() {
@Override
@ -584,6 +591,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mPort = (EditText) findViewById(R.id.port);
this.mPort.setText("5222");
this.mPort.addTextChangedListener(mTextWatcher);
this.mPortLayout = (TextInputLayout)findViewById(R.id.port_layout);
this.mSaveButton = (Button) findViewById(R.id.save_button);
this.mCancelButton = (Button) findViewById(R.id.cancel_button);
this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
@ -753,7 +761,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,
@ -1055,24 +1062,24 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
} else {
if (this.mAccount.errorStatus()) {
final EditText errorTextField;
final TextInputLayout errorLayout;
if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
errorTextField = this.mPassword;
errorLayout = this.mPasswordLayout;
} else if (mShowOptions
&& this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND
&& this.mHostname.getText().length() > 0) {
errorTextField = this.mHostname;
errorLayout = this.mHostnameLayout;
} else {
errorTextField = this.mAccountJid;
errorLayout = this.mAccountJidLayout;
}
errorTextField.setError(getString(this.mAccount.getStatus().getReadableId()));
errorLayout.setError(getString(this.mAccount.getStatus().getReadableId()));
if (init || !accountInfoEdited()) {
errorTextField.requestFocus();
errorLayout.requestFocus();
}
} else {
this.mAccountJid.setError(null);
this.mPassword.setError(null);
this.mHostname.setError(null);
this.mAccountJidLayout.setError(null);
this.mPasswordLayout.setError(null);
this.mHostnameLayout.setError(null);
}
this.mStats.setVisibility(View.GONE);
}

View File

@ -46,6 +46,7 @@
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/account_jid_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/account_settings_jabber_id">
@ -63,6 +64,7 @@
<android.support.design.widget.TextInputLayout
android:id="@+id/account_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleDrawable="@drawable/visibility_toggle_drawable"
@ -98,6 +100,7 @@
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/hostname_layout"
android:hint="@string/account_settings_hostname">
<EditText
@ -120,6 +123,7 @@
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/port_layout"
android:hint="@string/account_settings_port">
<EditText