aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java14
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java154
-rw-r--r--src/main/java/eu/siacs/conversations/utils/Validator.java14
3 files changed, 77 insertions, 105 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index 97efa41f..07e06b75 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -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
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index 630dc6ef..cab6e90e 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -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,41 +349,37 @@ 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());
- } catch (final InvalidJidException e) {
- return;
- }
- final Jid contactJid;
- try {
- contactJid = Jid.fromString(jid.getText().toString());
- } catch (final InvalidJidException e) {
- jid.setError(getString(R.string.invalid_jid));
- return;
- }
- Account account = xmppConnectionService
- .findAccountByJid(accountJid);
- if (account == null) {
- dialog.dismiss();
- return;
- }
- Contact contact = account.getRoster().getContact(contactJid);
- if (contact.showInRoster()) {
- jid.setError(getString(R.string.contact_already_exists));
- } else {
- contact.addOtrFingerprint(fingerprint);
- xmppConnectionService.createContact(contact);
- dialog.dismiss();
- switchToConversation(contact);
- }
- } else {
+ final Jid accountJid;
+ try {
+ accountJid = Jid.fromString((String) spinner.getSelectedItem());
+ } catch (final InvalidJidException e) {
+ return;
+ }
+ final Jid contactJid;
+ try {
+ contactJid = Jid.fromString(jid.getText().toString());
+ } catch (final InvalidJidException e) {
jid.setError(getString(R.string.invalid_jid));
+ return;
+ }
+ final Account account = xmppConnectionService
+ .findAccountByJid(accountJid);
+ if (account == null) {
+ dialog.dismiss();
+ return;
+ }
+ final Contact contact = account.getRoster().getContact(contactJid);
+ if (contact.showInRoster()) {
+ jid.setError(getString(R.string.contact_already_exists));
+ } else {
+ contact.addOtrFingerprint(fingerprint);
+ xmppConnectionService.createContact(contact);
+ dialog.dismiss();
+ switchToConversation(contact);
}
}
});
@@ -391,10 +387,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
@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,63 +409,59 @@ 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());
- } catch (final InvalidJidException e) {
- return;
- }
- final Jid conferenceJid;
- try {
- conferenceJid = Jid.fromString(jid.getText().toString());
- } catch (final InvalidJidException e) {
- jid.setError(getString(R.string.invalid_jid));
- return;
- }
- Account account = xmppConnectionService
- .findAccountByJid(accountJid);
- if (account == null) {
- dialog.dismiss();
- return;
- }
- if (bookmarkCheckBox.isChecked()) {
- if (account.hasBookmarkFor(conferenceJid)) {
- jid.setError(getString(R.string.bookmark_already_exists));
- } else {
- Bookmark bookmark = new Bookmark(account,
- conferenceJid);
- bookmark.setAutojoin(true);
- account.getBookmarks().add(bookmark);
- xmppConnectionService
- .pushBookmarks(account);
- Conversation conversation = xmppConnectionService
- .findOrCreateConversation(account,
- conferenceJid, true);
- conversation.setBookmark(bookmark);
- if (!conversation.getMucOptions().online()) {
- xmppConnectionService
- .joinMuc(conversation);
- }
- dialog.dismiss();
- switchToConversation(conversation);
- }
+ final Jid accountJid;
+ try {
+ accountJid = Jid.fromString((String) spinner.getSelectedItem());
+ } catch (final InvalidJidException e) {
+ return;
+ }
+ final Jid conferenceJid;
+ try {
+ conferenceJid = Jid.fromString(jid.getText().toString());
+ } catch (final InvalidJidException e) {
+ jid.setError(getString(R.string.invalid_jid));
+ return;
+ }
+ final Account account = xmppConnectionService
+ .findAccountByJid(accountJid);
+ if (account == null) {
+ dialog.dismiss();
+ return;
+ }
+ if (bookmarkCheckBox.isChecked()) {
+ if (account.hasBookmarkFor(conferenceJid)) {
+ jid.setError(getString(R.string.bookmark_already_exists));
} else {
- Conversation conversation = xmppConnectionService
+ final Bookmark bookmark = new Bookmark(account,
+ conferenceJid);
+ bookmark.setAutojoin(true);
+ account.getBookmarks().add(bookmark);
+ xmppConnectionService
+ .pushBookmarks(account);
+ final Conversation conversation = xmppConnectionService
.findOrCreateConversation(account,
conferenceJid, true);
+ conversation.setBookmark(bookmark);
if (!conversation.getMucOptions().online()) {
- xmppConnectionService.joinMuc(conversation);
+ xmppConnectionService
+ .joinMuc(conversation);
}
dialog.dismiss();
switchToConversation(conversation);
}
} else {
- jid.setError(getString(R.string.invalid_jid));
+ final Conversation conversation = xmppConnectionService
+ .findOrCreateConversation(account,
+ conferenceJid, true);
+ if (!conversation.getMucOptions().online()) {
+ xmppConnectionService.joinMuc(conversation);
+ }
+ dialog.dismiss();
+ switchToConversation(conversation);
}
}
});
diff --git a/src/main/java/eu/siacs/conversations/utils/Validator.java b/src/main/java/eu/siacs/conversations/utils/Validator.java
deleted file mode 100644
index 00130fa2..00000000
--- a/src/main/java/eu/siacs/conversations/utils/Validator.java
+++ /dev/null
@@ -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();
- }
-}