Update another chunk of stuff to use JID objects

This commit is contained in:
Sam Whited 2014-11-06 14:33:13 -05:00
parent f15900426d
commit bf9207456e
9 changed files with 104 additions and 83 deletions

View file

@ -248,13 +248,8 @@ public class Message extends AbstractEntity {
this.trueCounterpart = trueCounterpart; this.trueCounterpart = trueCounterpart;
} }
public String getPresence() { public Jid getPresence() {
if (!counterpart.getResourcepart().isEmpty()) { return counterpart;
return counterpart.getResourcepart();
} else {
// TODO: Return empty string or null?
return null;
}
} }
public void setDownloadable(Downloadable downloadable) { public void setDownloadable(Downloadable downloadable) {

View file

@ -114,7 +114,7 @@ public class MessageGenerator extends AbstractGenerator {
private MessagePacket generateError(MessagePacket origin) { private MessagePacket generateError(MessagePacket origin) {
MessagePacket packet = new MessagePacket(); MessagePacket packet = new MessagePacket();
packet.setId(origin.getId()); packet.setId(origin.getId());
packet.setAttribute("to", origin.getFrom()); packet.setTo(origin.getFrom());
packet.setBody(origin.getBody()); packet.setBody(origin.getBody());
packet.setType(MessagePacket.TYPE_ERROR); packet.setType(MessagePacket.TYPE_ERROR);
return packet; return packet;
@ -170,7 +170,7 @@ public class MessageGenerator extends AbstractGenerator {
MessagePacket originalMessage, String namespace) { MessagePacket originalMessage, String namespace) {
MessagePacket receivedPacket = new MessagePacket(); MessagePacket receivedPacket = new MessagePacket();
receivedPacket.setType(MessagePacket.TYPE_NORMAL); receivedPacket.setType(MessagePacket.TYPE_NORMAL);
receivedPacket.setAttribute("to", originalMessage.getFrom()); receivedPacket.setTo(originalMessage.getFrom());
receivedPacket.setFrom(account.getFullJid()); receivedPacket.setFrom(account.getFullJid());
Element received = receivedPacket.addChild("received", namespace); Element received = receivedPacket.addChild("received", namespace);
received.setAttribute("id", originalMessage.getId()); received.setAttribute("id", originalMessage.getId());

View file

@ -53,7 +53,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
} }
}; };
private List<User> users = new ArrayList<MucOptions.User>(); private List<User> users = new ArrayList<>();
private OnConversationUpdate onConvChanged = new OnConversationUpdate() { private OnConversationUpdate onConvChanged = new OnConversationUpdate() {
@Override @Override
@ -142,7 +142,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
@Override @Override
protected String getShareableUri() { protected String getShareableUri() {
if (conversation!=null) { if (conversation!=null) {
return "xmpp:"+conversation.getContactJid().split("/")[0]+"?join"; return "xmpp:"+conversation.getContactJid().toBareJid().toString()+"?join";
} else { } else {
return ""; return "";
} }
@ -211,7 +211,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
mYourPhoto.setImageBitmap(avatarService().get( mYourPhoto.setImageBitmap(avatarService().get(
conversation.getAccount(), getPixel(48))); conversation.getAccount(), getPixel(48)));
setTitle(conversation.getName()); setTitle(conversation.getName());
mFullJid.setText(conversation.getContactJid().split("/", 2)[0]); mFullJid.setText(conversation.getContactJid().toBareJid().toString());
mYourNick.setText(conversation.getMucOptions().getActualNick()); mYourNick.setText(conversation.getMucOptions().getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
if (conversation.getMucOptions().online()) { if (conversation.getMucOptions().online()) {

View file

@ -35,14 +35,16 @@ import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
public class ContactDetailsActivity extends XmppActivity { public class ContactDetailsActivity extends XmppActivity {
public static final String ACTION_VIEW_CONTACT = "view_contact"; public static final String ACTION_VIEW_CONTACT = "view_contact";
private Contact contact; private Contact contact;
private String accountJid; private Jid accountJid;
private String contactJid; private Jid contactJid;
private TextView contactJidTv; private TextView contactJidTv;
private TextView accountJidTv; private TextView accountJidTv;
@ -68,7 +70,7 @@ public class ContactDetailsActivity extends XmppActivity {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(Contacts.CONTENT_ITEM_TYPE); intent.setType(Contacts.CONTENT_ITEM_TYPE);
intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid()); intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid().toString());
intent.putExtra(Intents.Insert.IM_PROTOCOL, intent.putExtra(Intents.Insert.IM_PROTOCOL,
CommonDataKinds.Im.PROTOCOL_JABBER); CommonDataKinds.Im.PROTOCOL_JABBER);
intent.putExtra("finishActivityOnSaveCompleted", true); intent.putExtra("finishActivityOnSaveCompleted", true);
@ -174,8 +176,14 @@ public class ContactDetailsActivity extends XmppActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) { if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
this.accountJid = getIntent().getExtras().getString("account"); try {
this.contactJid = getIntent().getExtras().getString("contact"); this.accountJid = Jid.fromString(getIntent().getExtras().getString("account"));
} catch (final InvalidJidException ignored) {
}
try {
this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
} catch (final InvalidJidException ignored) {
}
} }
setContentView(R.layout.activity_contact_details); setContentView(R.layout.activity_contact_details);
@ -318,7 +326,7 @@ public class ContactDetailsActivity extends XmppActivity {
contactJidTv.setText(contact.getJid() + " (" contactJidTv.setText(contact.getJid() + " ("
+ contact.getPresences().size() + ")"); + contact.getPresences().size() + ")");
} else { } else {
contactJidTv.setText(contact.getJid()); contactJidTv.setText(contact.getJid().toString());
} }
accountJidTv.setText(getString(R.string.using_account, contact accountJidTv.setText(getString(R.string.using_account, contact
.getAccount().getJid())); .getAccount().getJid()));

View file

@ -54,6 +54,7 @@ import eu.siacs.conversations.ui.adapter.MessageAdapter;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jid.Jid;
public class ConversationFragment extends Fragment { public class ConversationFragment extends Fragment {
@ -92,11 +93,9 @@ public class ConversationFragment extends Fragment {
} }
}; };
protected ListView messagesView; protected ListView messagesView;
protected LayoutInflater inflater; protected List<Message> messageList = new ArrayList<>();
protected List<Message> messageList = new ArrayList<Message>();
protected MessageAdapter messageListAdapter; protected MessageAdapter messageListAdapter;
protected Contact contact; protected Contact contact;
protected String queuedPqpMessage = null;
private EditMessage mEditMessage; private EditMessage mEditMessage;
private ImageButton mSendButton; private ImageButton mSendButton;
private RelativeLayout snackbar; private RelativeLayout snackbar;
@ -147,7 +146,7 @@ public class ConversationFragment extends Fragment {
} }
} }
}; };
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<Message>(); private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<>();
private boolean mDecryptJobRunning = false; private boolean mDecryptJobRunning = false;
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() { private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@ -281,10 +280,10 @@ public class ConversationFragment extends Fragment {
if (message.getStatus() <= Message.STATUS_RECEIVED) { if (message.getStatus() <= Message.STATUS_RECEIVED) {
if (message.getConversation().getMode() == Conversation.MODE_MULTI) { if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
if (message.getPresence() != null) { if (message.getPresence() != null) {
highlightInConference(message.getPresence()); highlightInConference(message.getPresence().toString());
} else { } else {
highlightInConference(message highlightInConference(message
.getCounterpart()); .getCounterpart().toString());
} }
} else { } else {
Contact contact = message.getConversation() Contact contact = message.getConversation()
@ -299,7 +298,7 @@ public class ConversationFragment extends Fragment {
} else { } else {
Account account = message.getConversation().getAccount(); Account account = message.getConversation().getAccount();
Intent intent = new Intent(activity, EditAccountActivity.class); Intent intent = new Intent(activity, EditAccountActivity.class);
intent.putExtra("jid", account.getJid()); intent.putExtra("jid", account.getJid().toString());
startActivity(intent); startActivity(intent);
} }
} }
@ -430,9 +429,9 @@ public class ConversationFragment extends Fragment {
.createNewConnection(message); .createNewConnection(message);
} }
protected void privateMessageWith(String counterpart) { protected void privateMessageWith(final Jid counterpart) {
this.mEditMessage.setText(""); this.mEditMessage.setText("");
this.conversation.setNextPresence(counterpart); this.conversation.setNextPresence(counterpart.toString());
updateChatMsgHint(); updateChatMsgHint();
} }

View file

@ -47,6 +47,8 @@ import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.Validator; 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.Jid;
import eu.siacs.conversations.xmpp.pep.Avatar; import eu.siacs.conversations.xmpp.pep.Avatar;
public class EditAccountActivity extends XmppActivity { public class EditAccountActivity extends XmppActivity {
@ -68,7 +70,7 @@ public class EditAccountActivity extends XmppActivity {
private RelativeLayout mOtrFingerprintBox; private RelativeLayout mOtrFingerprintBox;
private ImageButton mOtrFingerprintToClipboardButton; private ImageButton mOtrFingerprintToClipboardButton;
private String jidToEdit; private Jid jidToEdit;
private Account mAccount; private Account mAccount;
private boolean mFetchingAvatar = false; private boolean mFetchingAvatar = false;
@ -89,13 +91,12 @@ public class EditAccountActivity extends XmppActivity {
return; return;
} }
boolean registerNewAccount = mRegisterNew.isChecked(); boolean registerNewAccount = mRegisterNew.isChecked();
String[] jidParts = mAccountJid.getText().toString().split("@"); final Jid jid;
String username = jidParts[0]; try {
String server; jid = Jid.fromString(mAccountJid.getText().toString());
if (jidParts.length >= 2) { } catch (final InvalidJidException e) {
server = jidParts[1]; // TODO: Handle this error?
} else { return;
server = "";
} }
String password = mPassword.getText().toString(); String password = mPassword.getText().toString();
String passwordConfirm = mPasswordConfirm.getText().toString(); String passwordConfirm = mPasswordConfirm.getText().toString();
@ -109,19 +110,25 @@ public class EditAccountActivity extends XmppActivity {
} }
if (mAccount != null) { if (mAccount != null) {
mAccount.setPassword(password); mAccount.setPassword(password);
mAccount.setUsername(username); try {
mAccount.setServer(server); mAccount.setUsername(jid.hasLocalPart() ? jid.getLocalpart() : "");
mAccount.setServer(jid.getDomainpart());
} catch (final InvalidJidException ignored) {
}
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
xmppConnectionService.updateAccount(mAccount); xmppConnectionService.updateAccount(mAccount);
} else { } else {
if (xmppConnectionService.findAccountByJid(mAccountJid try {
.getText().toString()) != null) { if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) {
mAccountJid mAccountJid
.setError(getString(R.string.account_already_exists)); .setError(getString(R.string.account_already_exists));
mAccountJid.requestFocus(); mAccountJid.requestFocus();
return; return;
} }
mAccount = new Account(username, server, password); } catch (InvalidJidException e) {
return;
}
mAccount = new Account(jid.toBareJid(), password);
mAccount.setOption(Account.OPTION_USETLS, true); mAccount.setOption(Account.OPTION_USETLS, true);
mAccount.setOption(Account.OPTION_USECOMPRESSION, true); mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
@ -191,7 +198,6 @@ public class EditAccountActivity extends XmppActivity {
finishInitialSetup(avatar); finishInitialSetup(avatar);
} }
}; };
private KnownHostsAdapter mKnownHostsAdapter;
private TextWatcher mTextWatcher = new TextWatcher() { private TextWatcher mTextWatcher = new TextWatcher() {
@Override @Override
@ -217,7 +223,7 @@ public class EditAccountActivity extends XmppActivity {
if (mAccount!=null) { if (mAccount!=null) {
Intent intent = new Intent(getApplicationContext(), Intent intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class); PublishProfilePictureActivity.class);
intent.putExtra("account", mAccount.getJid()); intent.putExtra("account", mAccount.getJid().toString());
startActivity(intent); startActivity(intent);
} }
} }
@ -235,7 +241,7 @@ public class EditAccountActivity extends XmppActivity {
} else { } else {
intent = new Intent(getApplicationContext(), intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class); PublishProfilePictureActivity.class);
intent.putExtra("account", mAccount.getJid()); intent.putExtra("account", mAccount.getJid().toString());
intent.putExtra("setup", true); intent.putExtra("setup", true);
} }
startActivity(intent); startActivity(intent);
@ -358,7 +364,10 @@ public class EditAccountActivity extends XmppActivity {
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
if (getIntent() != null) { if (getIntent() != null) {
this.jidToEdit = getIntent().getStringExtra("jid"); try {
this.jidToEdit = Jid.fromString(getIntent().getStringExtra("jid"));
} catch (final InvalidJidException ignored) {
}
if (this.jidToEdit != null) { if (this.jidToEdit != null) {
this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setVisibility(View.GONE);
getActionBar().setTitle(getString(R.string.account_details)); getActionBar().setTitle(getString(R.string.account_details));
@ -379,7 +388,7 @@ public class EditAccountActivity extends XmppActivity {
@Override @Override
protected void onBackendConnected() { protected void onBackendConnected() {
this.mKnownHostsAdapter = new KnownHostsAdapter(this, KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
android.R.layout.simple_list_item_1, android.R.layout.simple_list_item_1,
xmppConnectionService.getKnownHosts()); xmppConnectionService.getKnownHosts());
this.xmppConnectionService this.xmppConnectionService
@ -393,12 +402,12 @@ public class EditAccountActivity extends XmppActivity {
this.mCancelButton.setEnabled(false); this.mCancelButton.setEnabled(false);
this.mCancelButton.setTextColor(getSecondaryTextColor()); this.mCancelButton.setTextColor(getSecondaryTextColor());
} }
this.mAccountJid.setAdapter(this.mKnownHostsAdapter); this.mAccountJid.setAdapter(mKnownHostsAdapter);
updateSaveButton(); updateSaveButton();
} }
private void updateAccountInformation() { private void updateAccountInformation() {
this.mAccountJid.setText(this.mAccount.getJid()); this.mAccountJid.setText(this.mAccount.getJid().toString());
this.mPassword.setText(this.mAccount.getPassword()); this.mPassword.setText(this.mAccount.getPassword());
if (this.jidToEdit != null) { if (this.jidToEdit != null) {
this.mAvatar.setVisibility(View.VISIBLE); this.mAvatar.setVisibility(View.VISIBLE);

View file

@ -14,6 +14,8 @@ import android.widget.TextView;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.pep.Avatar; import eu.siacs.conversations.xmpp.pep.Avatar;
public class PublishProfilePictureActivity extends XmppActivity { public class PublishProfilePictureActivity extends XmppActivity {
@ -148,7 +150,12 @@ public class PublishProfilePictureActivity extends XmppActivity {
@Override @Override
protected void onBackendConnected() { protected void onBackendConnected() {
if (getIntent() != null) { if (getIntent() != null) {
String jid = getIntent().getStringExtra("account"); Jid jid;
try {
jid = Jid.fromString(getIntent().getStringExtra("account"));
} catch (InvalidJidException e) {
jid = null;
}
if (jid != null) { if (jid != null) {
this.account = xmppConnectionService.findAccountByJid(jid); this.account = xmppConnectionService.findAccountByJid(jid);
if (this.account.getXmppConnection() != null) { if (this.account.getXmppConnection() != null) {
@ -180,7 +187,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
} else { } else {
loadImageIntoPreview(avatarUri); loadImageIntoPreview(avatarUri);
} }
this.accountTextView.setText(this.account.getJid()); this.accountTextView.setText(this.account.getJid().toString());
} }
} }

View file

@ -65,6 +65,7 @@ import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.xmpp.jid.Jid;
public abstract class XmppActivity extends Activity { public abstract class XmppActivity extends Activity {
@ -275,14 +276,14 @@ public abstract class XmppActivity extends Activity {
public void switchToContactDetails(Contact contact) { public void switchToContactDetails(Contact contact) {
Intent intent = new Intent(this, ContactDetailsActivity.class); Intent intent = new Intent(this, ContactDetailsActivity.class);
intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
intent.putExtra("account", contact.getAccount().getJid()); intent.putExtra("account", contact.getAccount().getJid().toString());
intent.putExtra("contact", contact.getJid()); intent.putExtra("contact", contact.getJid().toString());
startActivity(intent); startActivity(intent);
} }
public void switchToAccount(Account account) { public void switchToAccount(Account account) {
Intent intent = new Intent(this, EditAccountActivity.class); Intent intent = new Intent(this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid()); intent.putExtra("jid", account.getJid().toString());
startActivity(intent); startActivity(intent);
} }
@ -303,7 +304,7 @@ public abstract class XmppActivity extends Activity {
try { try {
startIntentSenderForResult(pi.getIntentSender(), startIntentSenderForResult(pi.getIntentSender(),
REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
} catch (SendIntentException e) { } catch (final SendIntentException ignored) {
} }
} }
@ -347,9 +348,9 @@ public abstract class XmppActivity extends Activity {
} }
protected void showAddToRosterDialog(final Conversation conversation) { protected void showAddToRosterDialog(final Conversation conversation) {
String jid = conversation.getContactJid(); final Jid jid = conversation.getContactJid();
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(jid); builder.setTitle(jid.toString());
builder.setMessage(getString(R.string.not_in_roster)); builder.setMessage(getString(R.string.not_in_roster));
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add_contact), builder.setPositiveButton(getString(R.string.add_contact),
@ -357,7 +358,7 @@ public abstract class XmppActivity extends Activity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String jid = conversation.getContactJid(); final Jid jid = conversation.getContactJid();
Account account = conversation.getAccount(); Account account = conversation.getAccount();
Contact contact = account.getRoster().getContact(jid); Contact contact = account.getRoster().getContact(jid);
xmppConnectionService.createContact(contact); xmppConnectionService.createContact(contact);
@ -369,7 +370,7 @@ public abstract class XmppActivity extends Activity {
private void showAskForPresenceDialog(final Contact contact) { private void showAskForPresenceDialog(final Contact contact) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(contact.getJid()); builder.setTitle(contact.getJid().toString());
builder.setMessage(R.string.request_presence_updates); builder.setMessage(R.string.request_presence_updates);
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.request_now, builder.setPositiveButton(R.string.request_now,
@ -391,7 +392,7 @@ public abstract class XmppActivity extends Activity {
private void warnMutalPresenceSubscription(final Conversation conversation, private void warnMutalPresenceSubscription(final Conversation conversation,
final OnPresenceSelected listener) { final OnPresenceSelected listener) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(conversation.getContact().getJid()); builder.setTitle(conversation.getContact().getJid().toString());
builder.setMessage(R.string.without_mutual_presence_updates); builder.setMessage(R.string.without_mutual_presence_updates);
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.ignore, new OnClickListener() { builder.setPositiveButton(R.string.ignore, new OnClickListener() {
@ -567,11 +568,10 @@ public abstract class XmppActivity extends Activity {
nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() { nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
@Override @Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) { public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
NdefMessage msg = new NdefMessage(new NdefRecord[]{ return new NdefMessage(new NdefRecord[]{
NdefRecord.createUri(getShareableUri()), NdefRecord.createUri(getShareableUri()),
NdefRecord.createApplicationRecord("eu.siacs.conversations") NdefRecord.createApplicationRecord("eu.siacs.conversations")
}); });
return msg;
} }
}, this); }, this);
} }
@ -620,7 +620,7 @@ public abstract class XmppActivity extends Activity {
protected Bitmap createQrCodeBitmap(String input, int size) { protected Bitmap createQrCodeBitmap(String input, int size) {
try { try {
final QRCodeWriter QR_CODE_WRITER = new QRCodeWriter(); final QRCodeWriter QR_CODE_WRITER = new QRCodeWriter();
final Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); final Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
final BitMatrix result = QR_CODE_WRITER.encode(input, BarcodeFormat.QR_CODE, size, size, hints); final BitMatrix result = QR_CODE_WRITER.encode(input, BarcodeFormat.QR_CODE, size, size, hints);
final int width = result.getWidth(); final int width = result.getWidth();
@ -649,7 +649,7 @@ public abstract class XmppActivity extends Activity {
private Message message = null; private Message message = null;
public BitmapWorkerTask(ImageView imageView) { public BitmapWorkerTask(ImageView imageView) {
imageViewReference = new WeakReference<ImageView>(imageView); imageViewReference = new WeakReference<>(imageView);
} }
@Override @Override
@ -665,7 +665,7 @@ public abstract class XmppActivity extends Activity {
@Override @Override
protected void onPostExecute(Bitmap bitmap) { protected void onPostExecute(Bitmap bitmap) {
if (imageViewReference != null && bitmap != null) { if (bitmap != null) {
final ImageView imageView = imageViewReference.get(); final ImageView imageView = imageViewReference.get();
if (imageView != null) { if (imageView != null) {
imageView.setImageBitmap(bitmap); imageView.setImageBitmap(bitmap);
@ -695,8 +695,7 @@ public abstract class XmppActivity extends Activity {
imageView.setImageDrawable(asyncDrawable); imageView.setImageDrawable(asyncDrawable);
try { try {
task.execute(message); task.execute(message);
} catch (RejectedExecutionException e) { } catch (final RejectedExecutionException ignored) {
return;
} }
} }
} }
@ -734,7 +733,7 @@ public abstract class XmppActivity extends Activity {
public AsyncDrawable(Resources res, Bitmap bitmap, public AsyncDrawable(Resources res, Bitmap bitmap,
BitmapWorkerTask bitmapWorkerTask) { BitmapWorkerTask bitmapWorkerTask) {
super(res, bitmap); super(res, bitmap);
bitmapWorkerTaskReference = new WeakReference<BitmapWorkerTask>( bitmapWorkerTaskReference = new WeakReference<>(
bitmapWorkerTask); bitmapWorkerTask);
} }

View file

@ -162,6 +162,10 @@ public final class Jid {
return result; return result;
} }
public boolean hasLocalPart() {
return !localpart.isEmpty();
}
public boolean isBareJid() { public boolean isBareJid() {
return this.resourcepart.isEmpty(); return this.resourcepart.isEmpty();
} }