Merge pull request #805 from SamWhited/removeoldvalidator
Remove old JID validator
This commit is contained in:
commit
7c02677531
|
@ -29,7 +29,6 @@ import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
|
|||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||
import eu.siacs.conversations.utils.CryptoHelper;
|
||||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import eu.siacs.conversations.utils.Validator;
|
||||
import eu.siacs.conversations.xmpp.XmppConnection.Features;
|
||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||
|
@ -67,19 +66,14 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||
private OnClickListener mSaveButtonClickListener = new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(final View v) {
|
||||
if (mAccount != null
|
||||
&& mAccount.getStatus() == Account.State.DISABLED) {
|
||||
mAccount.setOption(Account.OPTION_DISABLED, false);
|
||||
xmppConnectionService.updateAccount(mAccount);
|
||||
return;
|
||||
}
|
||||
if (!Validator.isValidJid(mAccountJid.getText().toString())) {
|
||||
mAccountJid.setError(getString(R.string.invalid_jid));
|
||||
mAccountJid.requestFocus();
|
||||
return;
|
||||
}
|
||||
boolean registerNewAccount = mRegisterNew.isChecked();
|
||||
final boolean registerNewAccount = mRegisterNew.isChecked();
|
||||
final Jid jid;
|
||||
try {
|
||||
jid = Jid.fromString(mAccountJid.getText().toString());
|
||||
|
@ -88,8 +82,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||
mAccountJid.requestFocus();
|
||||
return;
|
||||
}
|
||||
String password = mPassword.getText().toString();
|
||||
String passwordConfirm = mPasswordConfirm.getText().toString();
|
||||
final String password = mPassword.getText().toString();
|
||||
final String passwordConfirm = mPasswordConfirm.getText().toString();
|
||||
if (registerNewAccount) {
|
||||
if (!password.equals(passwordConfirm)) {
|
||||
mPasswordConfirm
|
||||
|
|
|
@ -38,6 +38,7 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
|
@ -61,7 +62,6 @@ import eu.siacs.conversations.entities.ListItem;
|
|||
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
|
||||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||
import eu.siacs.conversations.ui.adapter.ListItemAdapter;
|
||||
import eu.siacs.conversations.utils.Validator;
|
||||
import eu.siacs.conversations.utils.XmppUri;
|
||||
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||
|
@ -349,11 +349,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(final View v) {
|
||||
if (!xmppConnectionServiceBound) {
|
||||
return;
|
||||
}
|
||||
if (Validator.isValidJid(jid.getText().toString())) {
|
||||
final Jid accountJid;
|
||||
try {
|
||||
accountJid = Jid.fromString((String) spinner.getSelectedItem());
|
||||
|
@ -367,13 +366,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
jid.setError(getString(R.string.invalid_jid));
|
||||
return;
|
||||
}
|
||||
Account account = xmppConnectionService
|
||||
final Account account = xmppConnectionService
|
||||
.findAccountByJid(accountJid);
|
||||
if (account == null) {
|
||||
dialog.dismiss();
|
||||
return;
|
||||
}
|
||||
Contact contact = account.getRoster().getContact(contactJid);
|
||||
final Contact contact = account.getRoster().getContact(contactJid);
|
||||
if (contact.showInRoster()) {
|
||||
jid.setError(getString(R.string.contact_already_exists));
|
||||
} else {
|
||||
|
@ -382,19 +381,16 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
dialog.dismiss();
|
||||
switchToConversation(contact);
|
||||
}
|
||||
} else {
|
||||
jid.setError(getString(R.string.invalid_jid));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
protected void showJoinConferenceDialog(String prefilledJid) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
protected void showJoinConferenceDialog(final String prefilledJid) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.join_conference);
|
||||
View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
|
||||
final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
|
||||
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
|
||||
final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
|
||||
jid.setAdapter(new KnownHostsAdapter(this,android.R.layout.simple_list_item_1, mKnownConferenceHosts));
|
||||
|
@ -402,7 +398,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
jid.append(prefilledJid);
|
||||
}
|
||||
populateAccountSpinner(spinner);
|
||||
final CheckBox bookmarkCheckBox = (CheckBox) dialogView
|
||||
final Checkable bookmarkCheckBox = (CheckBox) dialogView
|
||||
.findViewById(R.id.bookmark);
|
||||
builder.setView(dialogView);
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
|
@ -413,11 +409,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(final View v) {
|
||||
if (!xmppConnectionServiceBound) {
|
||||
return;
|
||||
}
|
||||
if (Validator.isValidJid(jid.getText().toString())) {
|
||||
final Jid accountJid;
|
||||
try {
|
||||
accountJid = Jid.fromString((String) spinner.getSelectedItem());
|
||||
|
@ -431,7 +426,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
jid.setError(getString(R.string.invalid_jid));
|
||||
return;
|
||||
}
|
||||
Account account = xmppConnectionService
|
||||
final Account account = xmppConnectionService
|
||||
.findAccountByJid(accountJid);
|
||||
if (account == null) {
|
||||
dialog.dismiss();
|
||||
|
@ -441,13 +436,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
if (account.hasBookmarkFor(conferenceJid)) {
|
||||
jid.setError(getString(R.string.bookmark_already_exists));
|
||||
} else {
|
||||
Bookmark bookmark = new Bookmark(account,
|
||||
final Bookmark bookmark = new Bookmark(account,
|
||||
conferenceJid);
|
||||
bookmark.setAutojoin(true);
|
||||
account.getBookmarks().add(bookmark);
|
||||
xmppConnectionService
|
||||
.pushBookmarks(account);
|
||||
Conversation conversation = xmppConnectionService
|
||||
final Conversation conversation = xmppConnectionService
|
||||
.findOrCreateConversation(account,
|
||||
conferenceJid, true);
|
||||
conversation.setBookmark(bookmark);
|
||||
|
@ -459,7 +454,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
switchToConversation(conversation);
|
||||
}
|
||||
} else {
|
||||
Conversation conversation = xmppConnectionService
|
||||
final Conversation conversation = xmppConnectionService
|
||||
.findOrCreateConversation(account,
|
||||
conferenceJid, true);
|
||||
if (!conversation.getMucOptions().online()) {
|
||||
|
@ -468,9 +463,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
dialog.dismiss();
|
||||
switchToConversation(conversation);
|
||||
}
|
||||
} else {
|
||||
jid.setError(getString(R.string.invalid_jid));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package eu.siacs.conversations.utils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Validator {
|
||||
public static final Pattern VALID_JID = Pattern.compile(
|
||||
"^[^@/<>'\"\\s]+@[^@/<>'\"\\s]+$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public static boolean isValidJid(String jid) {
|
||||
Matcher matcher = VALID_JID.matcher(jid);
|
||||
return matcher.find();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue