fixed two rare npe

This commit is contained in:
iNPUTmice 2014-06-25 17:32:58 +02:00
parent 31657974bf
commit 5db04a37bd
2 changed files with 49 additions and 44 deletions

View File

@ -37,7 +37,10 @@ public class PresenceParser extends AbstractParser {
} }
public void parseContactPresence(PresencePacket packet, Account account) { public void parseContactPresence(PresencePacket packet, Account account) {
String[] fromParts = packet.getAttribute("from").split("/"); if (packet.getFrom()==null) {
return;
}
String[] fromParts = packet.getFrom().split("/");
String type = packet.getAttribute("type"); String type = packet.getAttribute("type");
if (fromParts[0].equals(account.getJid())) { if (fromParts[0].equals(account.getJid())) {
if (fromParts.length == 2) { if (fromParts.length == 2) {

View File

@ -305,68 +305,70 @@ public class ContactDetailsActivity extends XmppActivity {
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
boolean updated = false; boolean updated = false;
boolean online = contact.getAccount().getStatus() == Account.STATUS_ONLINE; if (contact!=null) {
if (contact.getOption(Contact.Options.FROM)) { boolean online = contact.getAccount().getStatus() == Account.STATUS_ONLINE;
if (!send.isChecked()) { if (contact.getOption(Contact.Options.FROM)) {
if (online) {
contact.resetOption(Contact.Options.FROM);
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
activity.xmppConnectionService.stopPresenceUpdatesTo(contact);
}
updated = true;
}
} else {
if (contact
.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
if (!send.isChecked()) { if (!send.isChecked()) {
if (online) { if (online) {
contact.resetOption(Contact.Options.FROM);
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT); contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
activity.xmppConnectionService.stopPresenceUpdatesTo(contact);
} }
updated = true; updated = true;
} }
} else { } else {
if (send.isChecked()) { if (contact
if (online) { .getOption(Contact.Options.PREEMPTIVE_GRANT)) {
contact.setOption(Contact.Options.PREEMPTIVE_GRANT); if (!send.isChecked()) {
if (online) {
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
}
updated = true;
}
} else {
if (send.isChecked()) {
if (online) {
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
}
updated = true;
} }
updated = true;
} }
} }
} if (contact.getOption(Contact.Options.TO)) {
if (contact.getOption(Contact.Options.TO)) {
if (!receive.isChecked()) {
if (online) {
contact.resetOption(Contact.Options.TO);
activity.xmppConnectionService.stopPresenceUpdatesFrom(contact);
}
updated = true;
}
} else {
if (contact.getOption(Contact.Options.ASKING)) {
if (!receive.isChecked()) { if (!receive.isChecked()) {
if (online) { if (online) {
contact.resetOption(Contact.Options.ASKING); contact.resetOption(Contact.Options.TO);
activity.xmppConnectionService activity.xmppConnectionService.stopPresenceUpdatesFrom(contact);
.stopPresenceUpdatesFrom(contact);
} }
updated = true; updated = true;
} }
} else { } else {
if (receive.isChecked()) { if (contact.getOption(Contact.Options.ASKING)) {
if (online) { if (!receive.isChecked()) {
contact.setOption(Contact.Options.ASKING); if (online) {
activity.xmppConnectionService contact.resetOption(Contact.Options.ASKING);
.requestPresenceUpdatesFrom(contact); activity.xmppConnectionService
.stopPresenceUpdatesFrom(contact);
}
updated = true;
}
} else {
if (receive.isChecked()) {
if (online) {
contact.setOption(Contact.Options.ASKING);
activity.xmppConnectionService
.requestPresenceUpdatesFrom(contact);
}
updated = true;
} }
updated = true;
} }
} }
} if (updated) {
if (updated) { if (online) {
if (online) { Toast.makeText(getApplicationContext(), getString(R.string.subscription_updated), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), getString(R.string.subscription_updated), Toast.LENGTH_SHORT).show(); } else {
} else { Toast.makeText(getApplicationContext(), getString(R.string.subscription_not_updated_offline), Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), getString(R.string.subscription_not_updated_offline), Toast.LENGTH_SHORT).show(); }
} }
} }
} }