diff options
author | Sam Whited <sam@samwhited.com> | 2014-11-06 14:45:38 -0500 |
---|---|---|
committer | Sam Whited <sam@samwhited.com> | 2014-11-09 07:00:40 -0500 |
commit | f108fc5a5c4542872a059c088aee503236e8b358 (patch) | |
tree | 8fabc1cfbd337a09807c0c996f763d9101e00a43 /src/main/java/eu/siacs/conversations/ui | |
parent | bf9207456e7523c2d18f1f9fa007542b5d0e10ea (diff) |
Update more files to use JID objects
Diffstat (limited to '')
9 files changed, 77 insertions, 32 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java index f14da352..aa6ed7b4 100644 --- a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java @@ -25,7 +25,7 @@ import eu.siacs.conversations.ui.adapter.ListItemAdapter; public class ChooseContactActivity extends XmppActivity { private ListView mListView; - private ArrayList<ListItem> contacts = new ArrayList<ListItem>(); + private ArrayList<ListItem> contacts = new ArrayList<>(); private ArrayAdapter<ListItem> mContactsAdapter; private EditText mSearchEditText; @@ -96,10 +96,10 @@ public class ChooseContactActivity extends XmppActivity { Intent request = getIntent(); Intent data = new Intent(); ListItem mListItem = contacts.get(position); - data.putExtra("contact", mListItem.getJid()); + data.putExtra("contact", mListItem.getJid().toString()); String account = request.getStringExtra("account"); if (account == null && mListItem instanceof Contact) { - account = ((Contact) mListItem).getAccount().getJid(); + account = ((Contact) mListItem).getAccount().getJid().toString(); } data.putExtra("account", account); data.putExtra("conversation", diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index d02a7c7b..443a73db 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -228,8 +228,7 @@ public class ConversationActivity extends XmppActivity implements .useSubjectToIdentifyConference()) { ab.setTitle(getSelectedConversation().getName()); } else { - ab.setTitle(getSelectedConversation().getContactJid() - .split("/")[0]); + ab.setTitle(getSelectedConversation().getContactJid().toBareJid().toString()); } } invalidateOptionsMenu(); diff --git a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java index 77f8b68a..1bde4dcb 100644 --- a/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -81,7 +81,7 @@ public class ManageAccountActivity extends XmppActivity { } else { menu.findItem(R.id.mgmt_account_enable).setVisible(false); } - menu.setHeaderTitle(this.selectedAccount.getJid()); + menu.setHeaderTitle(this.selectedAccount.getJid().toString()); } @Override @@ -166,7 +166,7 @@ public class ManageAccountActivity extends XmppActivity { private void publishAvatar(Account account) { Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class); - intent.putExtra("account", account.getJid()); + intent.putExtra("account", account.getJid().toString()); startActivity(intent); } diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index 9fbc3db1..609dc280 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -9,6 +9,9 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.ui.adapter.ConversationAdapter; +import eu.siacs.conversations.xmpp.jid.InvalidJidException; +import eu.siacs.conversations.xmpp.jid.Jid; + import android.app.PendingIntent; import android.content.Intent; import android.net.Uri; @@ -150,13 +153,23 @@ public class ShareWithActivity extends XmppActivity { } private void share() { - Account account = xmppConnectionService.findAccountByJid(share.account); - if (account == null) { + Account account; + try { + account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account)); + } catch (final InvalidJidException e) { + account = null; + } + if (account == null) { return; } - Conversation conversation = xmppConnectionService - .findOrCreateConversation(account, share.contact, false); - share(conversation); + final Conversation conversation; + try { + conversation = xmppConnectionService + .findOrCreateConversation(account, Jid.fromString(share.contact), false); + } catch (final InvalidJidException e) { + return; + } + share(conversation); } private void share(final Conversation conversation) { diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index ed6b2a85..4963d38d 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -63,6 +63,8 @@ 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.xmpp.jid.InvalidJidException; +import eu.siacs.conversations.xmpp.jid.Jid; public class StartConversationActivity extends XmppActivity { @@ -71,7 +73,7 @@ public class StartConversationActivity extends XmppActivity { private ViewPager mViewPager; private MyListFragment mContactsListFragment = new MyListFragment(); - private List<ListItem> contacts = new ArrayList<ListItem>(); + private List<ListItem> contacts = new ArrayList<>(); private ArrayAdapter<ListItem> mContactsAdapter; private MyListFragment mConferenceListFragment = new MyListFragment(); @@ -359,17 +361,26 @@ public class StartConversationActivity extends XmppActivity { return; } if (Validator.isValidJid(jid.getText().toString())) { - String accountJid = (String) spinner - .getSelectedItem(); - String contactJid = jid.getText().toString(); - Account account = xmppConnectionService + 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) { + return; + } + Account account = xmppConnectionService .findAccountByJid(accountJid); if (account == null) { dialog.dismiss(); return; } - Contact contact = account.getRoster().getContact( - contactJid); + Contact contact = account.getRoster().getContact(contactJid); if (contact.showInRoster()) { jid.setError(getString(R.string.contact_already_exists)); } else { @@ -416,10 +427,19 @@ public class StartConversationActivity extends XmppActivity { return; } if (Validator.isValidJid(jid.getText().toString())) { - String accountJid = (String) spinner - .getSelectedItem(); - String conferenceJid = jid.getText().toString(); - Account account = xmppConnectionService + 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) { + return; // TODO: Do some error handling... + } + Account account = xmppConnectionService .findAccountByJid(accountJid); if (account == null) { dialog.dismiss(); @@ -471,7 +491,7 @@ public class StartConversationActivity extends XmppActivity { } private void populateAccountSpinner(Spinner spinner) { - ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, + ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mActivatedAccounts); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); @@ -554,7 +574,7 @@ public class StartConversationActivity extends XmppActivity { this.mActivatedAccounts.clear(); for (Account account : xmppConnectionService.getAccounts()) { if (account.getStatus() != Account.STATUS_DISABLED) { - this.mActivatedAccounts.add(account.getJid()); + this.mActivatedAccounts.add(account.getJid().toString()); } } this.mKnownHosts = xmppConnectionService.getKnownHosts(); @@ -779,7 +799,7 @@ public class StartConversationActivity extends XmppActivity { // sample: imto://xmpp/jid@foo.com try { jid = URLDecoder.decode(uri.getEncodedPath(), "UTF-8").split("/")[1]; - } catch (UnsupportedEncodingException e) { + } catch (final UnsupportedEncodingException ignored) { } } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java index e13b3204..ea527360 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java @@ -31,7 +31,7 @@ public class AccountAdapter extends ArrayAdapter<Account> { view = inflater.inflate(R.layout.account_row, parent, false); } TextView jid = (TextView) view.findViewById(R.id.account_jid); - jid.setText(account.getJid()); + jid.setText(account.getJid().toString()); TextView statusView = (TextView) view.findViewById(R.id.account_status); ImageView imageView = (ImageView) view.findViewById(R.id.account_image); imageView.setImageBitmap(activity.avatarService().get(account, diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index b5c20dc5..b3df8d72 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -58,7 +58,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { || activity.useSubjectToIdentifyConference()) { convName.setText(conversation.getName()); } else { - convName.setText(conversation.getContactJid().split("/")[0]); + convName.setText(conversation.getContactJid().toBareJid().toString()); } TextView mLastMessage = (TextView) view .findViewById(R.id.conversation_lastmsg); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index efc6b4d9..d78dbd6a 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -34,7 +34,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> { TextView jid = (TextView) view.findViewById(R.id.contact_jid); ImageView picture = (ImageView) view.findViewById(R.id.contact_photo); - jid.setText(item.getJid()); + jid.setText(item.getJid().toString()); name.setText(item.getDisplayName()); picture.setImageBitmap(activity.avatarService().get(item, activity.getPixel(48))); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index f2227308..ffd0b4e9 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -1,5 +1,18 @@ package eu.siacs.conversations.ui.adapter; +import java.util.List; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Downloadable; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.Message.ImageParams; +import eu.siacs.conversations.ui.ConversationActivity; +import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.xmpp.jid.Jid; + import android.content.Intent; import android.graphics.Typeface; import android.text.Spannable; @@ -136,9 +149,9 @@ public class MessageAdapter extends ArrayAdapter<Message> { info = contact.getDisplayName(); } else { if (message.getPresence() != null) { - info = message.getPresence(); + info = message.getPresence().toString(); } else { - info = message.getCounterpart(); + info = message.getCounterpart().toString(); } } } @@ -227,7 +240,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { privateMarker = activity .getString(R.string.private_message); } else { - String to; + final Jid to; if (message.getPresence() != null) { to = message.getPresence(); } else { |