Merge pull request #805 from SamWhited/removeoldvalidator

Remove old JID validator
This commit is contained in:
Daniel Gultsch 2014-12-23 22:46:51 +01:00
commit 7c02677531
3 changed files with 77 additions and 105 deletions

View file

@ -29,7 +29,6 @@ import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.Validator;
import eu.siacs.conversations.xmpp.XmppConnection.Features; import eu.siacs.conversations.xmpp.XmppConnection.Features;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
@ -67,19 +66,14 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private OnClickListener mSaveButtonClickListener = new OnClickListener() { private OnClickListener mSaveButtonClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(final View v) {
if (mAccount != null if (mAccount != null
&& mAccount.getStatus() == Account.State.DISABLED) { && mAccount.getStatus() == Account.State.DISABLED) {
mAccount.setOption(Account.OPTION_DISABLED, false); mAccount.setOption(Account.OPTION_DISABLED, false);
xmppConnectionService.updateAccount(mAccount); xmppConnectionService.updateAccount(mAccount);
return; return;
} }
if (!Validator.isValidJid(mAccountJid.getText().toString())) { final boolean registerNewAccount = mRegisterNew.isChecked();
mAccountJid.setError(getString(R.string.invalid_jid));
mAccountJid.requestFocus();
return;
}
boolean registerNewAccount = mRegisterNew.isChecked();
final Jid jid; final Jid jid;
try { try {
jid = Jid.fromString(mAccountJid.getText().toString()); jid = Jid.fromString(mAccountJid.getText().toString());
@ -88,8 +82,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
mAccountJid.requestFocus(); mAccountJid.requestFocus();
return; return;
} }
String password = mPassword.getText().toString(); final String password = mPassword.getText().toString();
String passwordConfirm = mPasswordConfirm.getText().toString(); final String passwordConfirm = mPasswordConfirm.getText().toString();
if (registerNewAccount) { if (registerNewAccount) {
if (!password.equals(passwordConfirm)) { if (!password.equals(passwordConfirm)) {
mPasswordConfirm mPasswordConfirm

View file

@ -38,6 +38,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner; 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.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.ui.adapter.ListItemAdapter; import eu.siacs.conversations.ui.adapter.ListItemAdapter;
import eu.siacs.conversations.utils.Validator;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
@ -349,11 +349,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(final View v) {
if (!xmppConnectionServiceBound) { if (!xmppConnectionServiceBound) {
return; return;
} }
if (Validator.isValidJid(jid.getText().toString())) {
final Jid accountJid; final Jid accountJid;
try { try {
accountJid = Jid.fromString((String) spinner.getSelectedItem()); accountJid = Jid.fromString((String) spinner.getSelectedItem());
@ -367,13 +366,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
jid.setError(getString(R.string.invalid_jid)); jid.setError(getString(R.string.invalid_jid));
return; return;
} }
Account account = xmppConnectionService final Account account = xmppConnectionService
.findAccountByJid(accountJid); .findAccountByJid(accountJid);
if (account == null) { if (account == null) {
dialog.dismiss(); dialog.dismiss();
return; return;
} }
Contact contact = account.getRoster().getContact(contactJid); final Contact contact = account.getRoster().getContact(contactJid);
if (contact.showInRoster()) { if (contact.showInRoster()) {
jid.setError(getString(R.string.contact_already_exists)); jid.setError(getString(R.string.contact_already_exists));
} else { } else {
@ -382,19 +381,16 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
dialog.dismiss(); dialog.dismiss();
switchToConversation(contact); switchToConversation(contact);
} }
} else {
jid.setError(getString(R.string.invalid_jid));
}
} }
}); });
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
protected void showJoinConferenceDialog(String prefilledJid) { protected void showJoinConferenceDialog(final String prefilledJid) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.join_conference); 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 Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid); final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
jid.setAdapter(new KnownHostsAdapter(this,android.R.layout.simple_list_item_1, mKnownConferenceHosts)); 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); jid.append(prefilledJid);
} }
populateAccountSpinner(spinner); populateAccountSpinner(spinner);
final CheckBox bookmarkCheckBox = (CheckBox) dialogView final Checkable bookmarkCheckBox = (CheckBox) dialogView
.findViewById(R.id.bookmark); .findViewById(R.id.bookmark);
builder.setView(dialogView); builder.setView(dialogView);
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
@ -413,11 +409,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(final View v) {
if (!xmppConnectionServiceBound) { if (!xmppConnectionServiceBound) {
return; return;
} }
if (Validator.isValidJid(jid.getText().toString())) {
final Jid accountJid; final Jid accountJid;
try { try {
accountJid = Jid.fromString((String) spinner.getSelectedItem()); accountJid = Jid.fromString((String) spinner.getSelectedItem());
@ -431,7 +426,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
jid.setError(getString(R.string.invalid_jid)); jid.setError(getString(R.string.invalid_jid));
return; return;
} }
Account account = xmppConnectionService final Account account = xmppConnectionService
.findAccountByJid(accountJid); .findAccountByJid(accountJid);
if (account == null) { if (account == null) {
dialog.dismiss(); dialog.dismiss();
@ -441,13 +436,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (account.hasBookmarkFor(conferenceJid)) { if (account.hasBookmarkFor(conferenceJid)) {
jid.setError(getString(R.string.bookmark_already_exists)); jid.setError(getString(R.string.bookmark_already_exists));
} else { } else {
Bookmark bookmark = new Bookmark(account, final Bookmark bookmark = new Bookmark(account,
conferenceJid); conferenceJid);
bookmark.setAutojoin(true); bookmark.setAutojoin(true);
account.getBookmarks().add(bookmark); account.getBookmarks().add(bookmark);
xmppConnectionService xmppConnectionService
.pushBookmarks(account); .pushBookmarks(account);
Conversation conversation = xmppConnectionService final Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, .findOrCreateConversation(account,
conferenceJid, true); conferenceJid, true);
conversation.setBookmark(bookmark); conversation.setBookmark(bookmark);
@ -459,7 +454,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
switchToConversation(conversation); switchToConversation(conversation);
} }
} else { } else {
Conversation conversation = xmppConnectionService final Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, .findOrCreateConversation(account,
conferenceJid, true); conferenceJid, true);
if (!conversation.getMucOptions().online()) { if (!conversation.getMucOptions().online()) {
@ -468,9 +463,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
dialog.dismiss(); dialog.dismiss();
switchToConversation(conversation); switchToConversation(conversation);
} }
} else {
jid.setError(getString(R.string.invalid_jid));
}
} }
}); });
} }

View file

@ -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();
}
}