Update more files to use JID objects

This commit is contained in:
Sam Whited 2014-11-06 14:45:38 -05:00
parent bf9207456e
commit f108fc5a5c
14 changed files with 102 additions and 54 deletions

View file

@ -336,9 +336,9 @@ public class Account extends AbstractEntity {
return this.bookmarks; return this.bookmarks;
} }
public boolean hasBookmarkFor(String conferenceJid) { public boolean hasBookmarkFor(final Jid conferenceJid) {
for (Bookmark bmark : this.bookmarks) { for (Bookmark bmark : this.bookmarks) {
if (bmark.getJid().equals(conferenceJid)) { if (bmark.getJid().equals(conferenceJid.toBareJid())) {
return true; return true;
} }
} }

View file

@ -173,7 +173,7 @@ public class AvatarService {
avatar = mXmppConnectionService.getFileBackend().getAvatar( avatar = mXmppConnectionService.getFileBackend().getAvatar(
account.getAvatar(), size); account.getAvatar(), size);
if (avatar == null) { if (avatar == null) {
avatar = get(account.getJid(), size); avatar = get(account.getJid().toString(), size);
} }
mXmppConnectionService.getBitmapCache().put(KEY, avatar); mXmppConnectionService.getBitmapCache().put(KEY, avatar);
return avatar; return avatar;

View file

@ -566,7 +566,7 @@ public class XmppConnectionService extends Service {
if (message.getEncryption() == Message.ENCRYPTION_OTR) { if (message.getEncryption() == Message.ENCRYPTION_OTR) {
if (!conv.hasValidOtrSession() if (!conv.hasValidOtrSession()
&& (message.getPresence() != null)) { && (message.getPresence() != null)) {
conv.startOtrSession(this, message.getPresence(), conv.startOtrSession(this, message.getPresence().toString(),
true); true);
message.setStatus(Message.STATUS_WAITING); message.setStatus(Message.STATUS_WAITING);
} else if (conv.hasValidOtrSession() } else if (conv.hasValidOtrSession()
@ -587,7 +587,7 @@ public class XmppConnectionService extends Service {
if (message.getEncryption() == Message.ENCRYPTION_OTR) { if (message.getEncryption() == Message.ENCRYPTION_OTR) {
if (!conv.hasValidOtrSession() if (!conv.hasValidOtrSession()
&& (message.getPresence() != null)) { && (message.getPresence() != null)) {
conv.startOtrSession(this, message.getPresence(), true); conv.startOtrSession(this, message.getPresence().toString(), true);
message.setStatus(Message.STATUS_WAITING); message.setStatus(Message.STATUS_WAITING);
} else if (conv.hasValidOtrSession() } else if (conv.hasValidOtrSession()
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) { && conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
@ -634,7 +634,7 @@ public class XmppConnectionService extends Service {
.getUserID()); .getUserID());
} else if (!conv.hasValidOtrSession() } else if (!conv.hasValidOtrSession()
&& message.getPresence() != null) { && message.getPresence() != null) {
conv.startOtrSession(this, message.getPresence(), false); conv.startOtrSession(this, message.getPresence().toString(), false);
} }
} }
} }
@ -670,9 +670,9 @@ public class XmppConnectionService extends Service {
.getPresences(); .getPresences();
if (!message.getConversation().hasValidOtrSession()) { if (!message.getConversation().hasValidOtrSession()) {
if ((message.getPresence() != null) if ((message.getPresence() != null)
&& (presences.has(message.getPresence()))) { && (presences.has(message.getPresence().toString()))) {
message.getConversation().startOtrSession(this, message.getConversation().startOtrSession(this,
message.getPresence(), true); message.getPresence().toString(), true);
} else { } else {
if (presences.size() == 1) { if (presences.size() == 1) {
String presence = presences.asStringArray()[0]; String presence = presences.asStringArray()[0];
@ -702,7 +702,7 @@ public class XmppConnectionService extends Service {
Presences presences = message.getConversation().getContact() Presences presences = message.getConversation().getContact()
.getPresences(); .getPresences();
if ((message.getPresence() != null) if ((message.getPresence() != null)
&& (presences.has(message.getPresence()))) { && (presences.has(message.getPresence().toString()))) {
markMessage(message, Message.STATUS_OFFERED); markMessage(message, Message.STATUS_OFFERED);
mJingleConnectionManager.createNewConnection(message); mJingleConnectionManager.createNewConnection(message);
} else { } else {

View file

@ -25,7 +25,7 @@ import eu.siacs.conversations.ui.adapter.ListItemAdapter;
public class ChooseContactActivity extends XmppActivity { public class ChooseContactActivity extends XmppActivity {
private ListView mListView; private ListView mListView;
private ArrayList<ListItem> contacts = new ArrayList<ListItem>(); private ArrayList<ListItem> contacts = new ArrayList<>();
private ArrayAdapter<ListItem> mContactsAdapter; private ArrayAdapter<ListItem> mContactsAdapter;
private EditText mSearchEditText; private EditText mSearchEditText;
@ -96,10 +96,10 @@ public class ChooseContactActivity extends XmppActivity {
Intent request = getIntent(); Intent request = getIntent();
Intent data = new Intent(); Intent data = new Intent();
ListItem mListItem = contacts.get(position); ListItem mListItem = contacts.get(position);
data.putExtra("contact", mListItem.getJid()); data.putExtra("contact", mListItem.getJid().toString());
String account = request.getStringExtra("account"); String account = request.getStringExtra("account");
if (account == null && mListItem instanceof Contact) { if (account == null && mListItem instanceof Contact) {
account = ((Contact) mListItem).getAccount().getJid(); account = ((Contact) mListItem).getAccount().getJid().toString();
} }
data.putExtra("account", account); data.putExtra("account", account);
data.putExtra("conversation", data.putExtra("conversation",

View file

@ -228,8 +228,7 @@ public class ConversationActivity extends XmppActivity implements
.useSubjectToIdentifyConference()) { .useSubjectToIdentifyConference()) {
ab.setTitle(getSelectedConversation().getName()); ab.setTitle(getSelectedConversation().getName());
} else { } else {
ab.setTitle(getSelectedConversation().getContactJid() ab.setTitle(getSelectedConversation().getContactJid().toBareJid().toString());
.split("/")[0]);
} }
} }
invalidateOptionsMenu(); invalidateOptionsMenu();

View file

@ -81,7 +81,7 @@ public class ManageAccountActivity extends XmppActivity {
} else { } else {
menu.findItem(R.id.mgmt_account_enable).setVisible(false); menu.findItem(R.id.mgmt_account_enable).setVisible(false);
} }
menu.setHeaderTitle(this.selectedAccount.getJid()); menu.setHeaderTitle(this.selectedAccount.getJid().toString());
} }
@Override @Override
@ -166,7 +166,7 @@ public class ManageAccountActivity extends XmppActivity {
private void publishAvatar(Account account) { private void publishAvatar(Account account) {
Intent intent = new Intent(getApplicationContext(), Intent intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class); PublishProfilePictureActivity.class);
intent.putExtra("account", account.getJid()); intent.putExtra("account", account.getJid().toString());
startActivity(intent); startActivity(intent);
} }

View file

@ -9,6 +9,9 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.adapter.ConversationAdapter; 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.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
@ -150,12 +153,22 @@ public class ShareWithActivity extends XmppActivity {
} }
private void share() { private void share() {
Account account = xmppConnectionService.findAccountByJid(share.account); Account account;
try {
account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account));
} catch (final InvalidJidException e) {
account = null;
}
if (account == null) { if (account == null) {
return; return;
} }
Conversation conversation = xmppConnectionService final Conversation conversation;
.findOrCreateConversation(account, share.contact, false); try {
conversation = xmppConnectionService
.findOrCreateConversation(account, Jid.fromString(share.contact), false);
} catch (final InvalidJidException e) {
return;
}
share(conversation); share(conversation);
} }

View file

@ -63,6 +63,8 @@ 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.Validator;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
public class StartConversationActivity extends XmppActivity { public class StartConversationActivity extends XmppActivity {
@ -71,7 +73,7 @@ public class StartConversationActivity extends XmppActivity {
private ViewPager mViewPager; private ViewPager mViewPager;
private MyListFragment mContactsListFragment = new MyListFragment(); private MyListFragment mContactsListFragment = new MyListFragment();
private List<ListItem> contacts = new ArrayList<ListItem>(); private List<ListItem> contacts = new ArrayList<>();
private ArrayAdapter<ListItem> mContactsAdapter; private ArrayAdapter<ListItem> mContactsAdapter;
private MyListFragment mConferenceListFragment = new MyListFragment(); private MyListFragment mConferenceListFragment = new MyListFragment();
@ -359,17 +361,26 @@ public class StartConversationActivity extends XmppActivity {
return; return;
} }
if (Validator.isValidJid(jid.getText().toString())) { if (Validator.isValidJid(jid.getText().toString())) {
String accountJid = (String) spinner final Jid accountJid;
.getSelectedItem(); try {
String contactJid = jid.getText().toString(); 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 Account account = xmppConnectionService
.findAccountByJid(accountJid); .findAccountByJid(accountJid);
if (account == null) { if (account == null) {
dialog.dismiss(); dialog.dismiss();
return; return;
} }
Contact contact = account.getRoster().getContact( Contact contact = account.getRoster().getContact(contactJid);
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 {
@ -416,9 +427,18 @@ public class StartConversationActivity extends XmppActivity {
return; return;
} }
if (Validator.isValidJid(jid.getText().toString())) { if (Validator.isValidJid(jid.getText().toString())) {
String accountJid = (String) spinner final Jid accountJid;
.getSelectedItem(); try {
String conferenceJid = jid.getText().toString(); 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 Account account = xmppConnectionService
.findAccountByJid(accountJid); .findAccountByJid(accountJid);
if (account == null) { if (account == null) {
@ -471,7 +491,7 @@ public class StartConversationActivity extends XmppActivity {
} }
private void populateAccountSpinner(Spinner spinner) { 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); android.R.layout.simple_spinner_item, mActivatedAccounts);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter); spinner.setAdapter(adapter);
@ -554,7 +574,7 @@ public class StartConversationActivity extends XmppActivity {
this.mActivatedAccounts.clear(); this.mActivatedAccounts.clear();
for (Account account : xmppConnectionService.getAccounts()) { for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.STATUS_DISABLED) { if (account.getStatus() != Account.STATUS_DISABLED) {
this.mActivatedAccounts.add(account.getJid()); this.mActivatedAccounts.add(account.getJid().toString());
} }
} }
this.mKnownHosts = xmppConnectionService.getKnownHosts(); this.mKnownHosts = xmppConnectionService.getKnownHosts();
@ -779,7 +799,7 @@ public class StartConversationActivity extends XmppActivity {
// sample: imto://xmpp/jid@foo.com // sample: imto://xmpp/jid@foo.com
try { try {
jid = URLDecoder.decode(uri.getEncodedPath(), "UTF-8").split("/")[1]; jid = URLDecoder.decode(uri.getEncodedPath(), "UTF-8").split("/")[1];
} catch (UnsupportedEncodingException e) { } catch (final UnsupportedEncodingException ignored) {
} }
} }
} }

View file

@ -31,7 +31,7 @@ public class AccountAdapter extends ArrayAdapter<Account> {
view = inflater.inflate(R.layout.account_row, parent, false); view = inflater.inflate(R.layout.account_row, parent, false);
} }
TextView jid = (TextView) view.findViewById(R.id.account_jid); 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); TextView statusView = (TextView) view.findViewById(R.id.account_status);
ImageView imageView = (ImageView) view.findViewById(R.id.account_image); ImageView imageView = (ImageView) view.findViewById(R.id.account_image);
imageView.setImageBitmap(activity.avatarService().get(account, imageView.setImageBitmap(activity.avatarService().get(account,

View file

@ -58,7 +58,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|| activity.useSubjectToIdentifyConference()) { || activity.useSubjectToIdentifyConference()) {
convName.setText(conversation.getName()); convName.setText(conversation.getName());
} else { } else {
convName.setText(conversation.getContactJid().split("/")[0]); convName.setText(conversation.getContactJid().toBareJid().toString());
} }
TextView mLastMessage = (TextView) view TextView mLastMessage = (TextView) view
.findViewById(R.id.conversation_lastmsg); .findViewById(R.id.conversation_lastmsg);

View file

@ -34,7 +34,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
TextView jid = (TextView) view.findViewById(R.id.contact_jid); TextView jid = (TextView) view.findViewById(R.id.contact_jid);
ImageView picture = (ImageView) view.findViewById(R.id.contact_photo); ImageView picture = (ImageView) view.findViewById(R.id.contact_photo);
jid.setText(item.getJid()); jid.setText(item.getJid().toString());
name.setText(item.getDisplayName()); name.setText(item.getDisplayName());
picture.setImageBitmap(activity.avatarService().get(item, picture.setImageBitmap(activity.avatarService().get(item,
activity.getPixel(48))); activity.getPixel(48)));

View file

@ -1,5 +1,18 @@
package eu.siacs.conversations.ui.adapter; 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.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.text.Spannable; import android.text.Spannable;
@ -136,9 +149,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
info = contact.getDisplayName(); info = contact.getDisplayName();
} else { } else {
if (message.getPresence() != null) { if (message.getPresence() != null) {
info = message.getPresence(); info = message.getPresence().toString();
} else { } else {
info = message.getCounterpart(); info = message.getCounterpart().toString();
} }
} }
} }
@ -227,7 +240,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
privateMarker = activity privateMarker = activity
.getString(R.string.private_message); .getString(R.string.private_message);
} else { } else {
String to; final Jid to;
if (message.getPresence() != null) { if (message.getPresence() != null) {
to = message.getPresence(); to = message.getPresence();
} else { } else {

View file

@ -13,6 +13,9 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -89,9 +92,12 @@ public class ExceptionHelper {
Log.d(Config.LOGTAG, "using account=" Log.d(Config.LOGTAG, "using account="
+ finalAccount.getJid() + finalAccount.getJid()
+ " to send in stack trace"); + " to send in stack trace");
Conversation conversation = service Conversation conversation = null;
.findOrCreateConversation(finalAccount, try {
"bugs@siacs.eu", false); conversation = service.findOrCreateConversation(finalAccount,
Jid.fromString("bugs@siacs.eu"), false);
} catch (final InvalidJidException ignored) {
}
Message message = new Message(conversation, report Message message = new Message(conversation, report
.toString(), Message.ENCRYPTION_NONE); .toString(), Message.ENCRYPTION_NONE);
service.sendMessage(message); service.sendMessage(message);
@ -103,14 +109,11 @@ public class ExceptionHelper {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
preferences.edit().putBoolean("never_send", true) preferences.edit().putBoolean("never_send", true)
.commit(); .apply();
} }
}); });
builder.create().show(); builder.create().show();
} catch (FileNotFoundException e) { } catch (final IOException ignored) {
return;
} catch (IOException e) {
return;
} }
} }

View file

@ -110,7 +110,7 @@ public class UIHelper {
List<Account> accounts) { List<Account> accounts) {
NotificationManager mNotificationManager = (NotificationManager) context NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
List<Account> accountsWproblems = new ArrayList<Account>(); List<Account> accountsWproblems = new ArrayList<>();
for (Account account : accounts) { for (Account account : accounts) {
if (account.hasErrorStatus()) { if (account.hasErrorStatus()) {
accountsWproblems.add(account); accountsWproblems.add(account);
@ -124,7 +124,7 @@ public class UIHelper {
} else if (accountsWproblems.size() == 1) { } else if (accountsWproblems.size() == 1) {
mBuilder.setContentTitle(context mBuilder.setContentTitle(context
.getString(R.string.problem_connecting_to_account)); .getString(R.string.problem_connecting_to_account));
mBuilder.setContentText(accountsWproblems.get(0).getJid()); mBuilder.setContentText(accountsWproblems.get(0).getJid().toString());
} else { } else {
mBuilder.setContentTitle(context mBuilder.setContentTitle(context
.getString(R.string.problem_connecting_to_accounts)); .getString(R.string.problem_connecting_to_accounts));
@ -165,7 +165,7 @@ public class UIHelper {
TextView yourprint = (TextView) view TextView yourprint = (TextView) view
.findViewById(R.id.verify_otr_yourprint); .findViewById(R.id.verify_otr_yourprint);
jid.setText(contact.getJid()); jid.setText(contact.getJid().toString());
fingerprint.setText(conversation.getOtrFingerprint()); fingerprint.setText(conversation.getOtrFingerprint());
yourprint.setText(account.getOtrFingerprint()); yourprint.setText(account.getOtrFingerprint());
builder.setNegativeButton("Cancel", null); builder.setNegativeButton("Cancel", null);