be more OO
This commit is contained in:
parent
32396b3bde
commit
fb24bf98c9
|
@ -533,13 +533,9 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
||||||
if (scanResult != null && scanResult.getFormatName() != null) {
|
if (scanResult != null && scanResult.getFormatName() != null) {
|
||||||
String data = scanResult.getContents();
|
String data = scanResult.getContents();
|
||||||
Invite invite = parseInviteUri(data);
|
Invite invite = new Invite(data);
|
||||||
if (xmppConnectionServiceBound) {
|
if (xmppConnectionServiceBound) {
|
||||||
if (invite.muc) {
|
invite.invite();
|
||||||
showJoinConferenceDialog(invite.jid);
|
|
||||||
} else {
|
|
||||||
handleJid(invite.jid);
|
|
||||||
}
|
|
||||||
} else if (invite.jid != null) {
|
} else if (invite.jid != null) {
|
||||||
this.mPendingInvite = invite;
|
this.mPendingInvite = invite;
|
||||||
} else {
|
} else {
|
||||||
|
@ -563,11 +559,7 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
this.mKnownConferenceHosts = xmppConnectionService
|
this.mKnownConferenceHosts = xmppConnectionService
|
||||||
.getKnownConferenceHosts();
|
.getKnownConferenceHosts();
|
||||||
if (this.mPendingInvite != null) {
|
if (this.mPendingInvite != null) {
|
||||||
if (this.mPendingInvite.muc) {
|
mPendingInvite.invite();
|
||||||
showJoinConferenceDialog(this.mPendingInvite.jid);
|
|
||||||
} else {
|
|
||||||
handleJid(this.mPendingInvite.jid);
|
|
||||||
}
|
|
||||||
this.mPendingInvite = null;
|
this.mPendingInvite = null;
|
||||||
} else if (!handleIntent(getIntent())) {
|
} else if (!handleIntent(getIntent())) {
|
||||||
if (mSearchEditText != null) {
|
if (mSearchEditText != null) {
|
||||||
|
@ -583,13 +575,12 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
if (intent == null || intent.getAction() == null) {
|
if (intent == null || intent.getAction() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String jid = null;
|
|
||||||
Uri uri = null;
|
|
||||||
Invite invite = null;
|
Invite invite = null;
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case Intent.ACTION_SENDTO:
|
case Intent.ACTION_SENDTO:
|
||||||
try {
|
try {
|
||||||
jid = URLDecoder.decode(
|
// TODO use Intent.parse ?!?
|
||||||
|
String jid = URLDecoder.decode(
|
||||||
intent.getData().getEncodedPath(), "UTF-8").split(
|
intent.getData().getEncodedPath(), "UTF-8").split(
|
||||||
"/")[1];
|
"/")[1];
|
||||||
return handleJid(jid);
|
return handleJid(jid);
|
||||||
|
@ -597,34 +588,23 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case Intent.ACTION_VIEW:
|
case Intent.ACTION_VIEW:
|
||||||
uri = intent.getData();
|
invite = new Invite(intent.getData());
|
||||||
invite = parseInviteUri(uri);
|
invite.invite();
|
||||||
if (invite.muc) {
|
|
||||||
showJoinConferenceDialog(invite.jid);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return handleJid(invite.jid);
|
|
||||||
}
|
|
||||||
case NfcAdapter.ACTION_NDEF_DISCOVERED:
|
case NfcAdapter.ACTION_NDEF_DISCOVERED:
|
||||||
Parcelable[] messages = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
|
Parcelable[] messages = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
|
||||||
NdefMessage message = (NdefMessage) messages[0];
|
NdefMessage message = (NdefMessage) messages[0];
|
||||||
NdefRecord record = message.getRecords()[0];
|
NdefRecord record = message.getRecords()[0];
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
invite = parseInviteUri(record.toUri());
|
invite = new Invite(record.toUri());
|
||||||
} else {
|
} else {
|
||||||
byte[] mPayload = record.getPayload();
|
byte[] mPayload = record.getPayload();
|
||||||
if (mPayload[0] == 0) {
|
if (mPayload[0] == 0) {
|
||||||
invite = parseInviteUri(Uri.parse(new String(Arrays.copyOfRange(
|
invite = new Invite(Uri.parse(new String(Arrays.copyOfRange(
|
||||||
mPayload, 1, mPayload.length), StandardCharsets.UTF_8)));
|
mPayload, 1, mPayload.length), StandardCharsets.UTF_8)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (invite != null) {
|
if (invite != null) {
|
||||||
if (invite.muc) {
|
return invite.invite();
|
||||||
showJoinConferenceDialog(invite.jid);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return handleJid(invite.jid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -632,25 +612,6 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Invite parseInviteUri(String uri) {
|
|
||||||
try {
|
|
||||||
return parseInviteUri(Uri.parse(uri));
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Invite parseInviteUri(Uri uri) {
|
|
||||||
Invite invite = new Invite();
|
|
||||||
invite.muc = uri.getQuery() != null && uri.getQuery().equalsIgnoreCase("join");
|
|
||||||
if (uri.getAuthority() != null) {
|
|
||||||
invite.jid = uri.getAuthority();
|
|
||||||
} else {
|
|
||||||
invite.jid = uri.getSchemeSpecificPart().split("\\?")[0];
|
|
||||||
}
|
|
||||||
return invite;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean handleJid(String jid) {
|
private boolean handleJid(String jid) {
|
||||||
List<Contact> contacts = xmppConnectionService.findContacts(jid);
|
List<Contact> contacts = xmppConnectionService.findContacts(jid);
|
||||||
if (contacts.size() == 0) {
|
if (contacts.size() == 0) {
|
||||||
|
@ -777,7 +738,39 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Invite {
|
private class Invite {
|
||||||
public String jid;
|
private String jid;
|
||||||
public boolean muc;
|
private boolean muc;
|
||||||
|
|
||||||
|
Invite(Uri uri) {
|
||||||
|
parse(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
Invite(String uri) {
|
||||||
|
try {
|
||||||
|
parse(Uri.parse(uri));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
jid = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean invite() {
|
||||||
|
if (jid != null) {
|
||||||
|
if (muc) {
|
||||||
|
showJoinConferenceDialog(jid);
|
||||||
|
} else {
|
||||||
|
return handleJid(jid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse(Uri uri) {
|
||||||
|
muc = uri.getQuery() != null && uri.getQuery().equalsIgnoreCase("join");
|
||||||
|
if (uri.getAuthority() != null) {
|
||||||
|
jid = uri.getAuthority();
|
||||||
|
} else {
|
||||||
|
jid = uri.getSchemeSpecificPart().split("\\?")[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue