@@ -21,6 +21,7 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.app.AlertDialog.Builder;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
+import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
@@ -101,11 +102,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private ImageButton mAxolotlFingerprintToClipboardButton;
private ImageButton mPgpDeleteFingerprintButton;
private LinearLayout keys;
- private LinearLayout mNamePort;
- private EditText mHostname;
- private TextInputLayout mHostnameLayout;
private EditText mPort;
- private TextInputLayout mPortLayout;
private AlertDialog mCaptchaDialog = null;
private Jid jidToEdit;
@@ -183,26 +180,26 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
String hostname = null;
int numericPort = 5222;
if (mShowOptions) {
- hostname = mHostname.getText().toString().replaceAll("\\s", "");
+ hostname = binding.hostname.getText().toString().replaceAll("\\s", "");
final String port = mPort.getText().toString().replaceAll("\\s", "");
if (hostname.contains(" ")) {
- mHostnameLayout.setError(getString(R.string.not_valid_hostname));
- mHostname.requestFocus();
- removeErrorsOnAllBut(mHostnameLayout);
+ binding.hostnameLayout.setError(getString(R.string.not_valid_hostname));
+ binding.hostname.requestFocus();
+ removeErrorsOnAllBut(binding.hostnameLayout);
return;
}
try {
numericPort = Integer.parseInt(port);
if (numericPort < 0 || numericPort > 65535) {
- mPortLayout.setError(getString(R.string.not_a_valid_port));
- removeErrorsOnAllBut(mPortLayout);
+ binding.portLayout.setError(getString(R.string.not_a_valid_port));
+ removeErrorsOnAllBut(binding.portLayout);
mPort.requestFocus();
return;
}
} catch (NumberFormatException e) {
- mPortLayout.setError(getString(R.string.not_a_valid_port));
- removeErrorsOnAllBut(mPortLayout);
+ binding.portLayout.setError(getString(R.string.not_a_valid_port));
+ removeErrorsOnAllBut(binding.portLayout);
mPort.requestFocus();
return;
}
@@ -247,8 +244,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
xmppConnectionService.createAccount(mAccount);
}
- mHostnameLayout.setError(null);
- mPortLayout.setError(null);
+ binding.hostnameLayout.setError(null);
+ binding.portLayout.setError(null);
if (mAccount.isEnabled()
&& !registerNewAccount
&& !mInitMode) {
@@ -346,6 +343,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
@Override
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
+ updatePortLayout();
updateSaveButton();
}
@@ -446,6 +444,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
}
+ private void updatePortLayout() {
+ String hostname = this.binding.hostname.getText().toString();
+ this.binding.portLayout.setEnabled(!TextUtils.isEmpty(hostname));
+ }
+
protected void updateSaveButton() {
boolean accountInfoEdited = accountInfoEdited();
@@ -497,7 +500,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
return jidEdited() ||
!this.mAccount.getPassword().equals(this.mPassword.getText().toString()) ||
- !this.mAccount.getHostname().equals(this.mHostname.getText().toString()) ||
+ !this.mAccount.getHostname().equals(this.binding.hostname.getText().toString()) ||
!String.valueOf(this.mAccount.getPort()).equals(this.mPort.getText().toString());
}
@@ -556,18 +559,14 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
this.mOwnFingerprintDesc = (TextView) findViewById(R.id.own_fingerprint_desc);
- this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
- this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
- this.mHostname = (EditText) findViewById(R.id.hostname);
- this.mHostname.addTextChangedListener(mTextWatcher);
- this.mHostname.setOnFocusChangeListener(mEditTextFocusListener);
- this.mHostnameLayout = (TextInputLayout) findViewById(R.id.hostname_layout);
+ this.keys = findViewById(R.id.other_device_keys);
+ this.binding.hostname.addTextChangedListener(mTextWatcher);
+ this.binding.hostname.setOnFocusChangeListener(mEditTextFocusListener);
this.mClearDevicesButton = (Button) findViewById(R.id.clear_devices);
this.mClearDevicesButton.setOnClickListener(v -> showWipePepDialog());
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);
@@ -676,7 +675,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
SharedPreferences preferences = getPreferences();
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);
+ this.binding.namePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
}
@Override
@@ -749,7 +748,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
processFingerprintVerification(pendingUri, false);
pendingUri = null;
}
-
+ updatePortLayout();
updateSaveButton();
invalidateOptionsMenu();
}
@@ -930,11 +929,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
this.mPassword.getEditableText().clear();
this.mPassword.getEditableText().append(this.mAccount.getPassword());
- this.mHostname.setText("");
- this.mHostname.getEditableText().append(this.mAccount.getHostname());
+ this.binding.hostname.setText("");
+ this.binding.hostname.getEditableText().append(this.mAccount.getHostname());
this.mPort.setText("");
this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort()));
- this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
+ this.binding.namePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
}
@@ -1094,8 +1093,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
errorLayout = this.mPasswordLayout;
} else if (mShowOptions
&& this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND
- && this.mHostname.getText().length() > 0) {
- errorLayout = this.mHostnameLayout;
+ && this.binding.hostname.getText().length() > 0) {
+ errorLayout = this.binding.hostnameLayout;
} else {
errorLayout = this.mAccountJidLayout;
}
@@ -1121,13 +1120,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mPasswordLayout.setErrorEnabled(false);
this.mPasswordLayout.setError(null);
}
- if (this.mHostnameLayout != exception) {
- this.mHostnameLayout.setErrorEnabled(false);
- this.mHostnameLayout.setError(null);
+ if (this.binding.hostnameLayout != exception) {
+ this.binding.hostnameLayout.setErrorEnabled(false);
+ this.binding.hostnameLayout.setError(null);
}
- if (this.mPortLayout != exception) {
- this.mPortLayout.setErrorEnabled(false);
- this.mPortLayout.setError(null);
+ if (this.binding.portLayout != exception) {
+ this.binding.portLayout.setErrorEnabled(false);
+ this.binding.portLayout.setError(null);
}
}
@@ -117,7 +117,7 @@
android:id="@+id/hostname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:inputType="textNoSuggestions"
+ android:inputType="textWebEmailAddress"
style="@style/Widget.Conversations.EditText"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>