optimize code abit

This commit is contained in:
M. Dietrich 2014-11-04 13:27:54 +01:00
parent b6c20d9260
commit 2ce95b19a9
1 changed files with 23 additions and 29 deletions

View File

@ -576,22 +576,11 @@ public class StartConversationActivity extends XmppActivity {
if (intent == null || intent.getAction() == null) {
return false;
}
Invite invite = null;
switch (intent.getAction()) {
case Intent.ACTION_SENDTO:
try {
// TODO use Intent.parse ?!?
// sample: imto://xmpp/jid@foo.com
String jid = URLDecoder.decode(
intent.getData().getEncodedPath(), "UTF-8").split(
"/")[1];
return handleJid(jid);
} catch (UnsupportedEncodingException e) {
return false;
}
case Intent.ACTION_VIEW:
invite = new Invite(intent.getData());
return invite.invite();
Log.d(Config.LOGTAG, "received uri=" + intent.getData());
return new Invite(intent.getData()).invite();
case NfcAdapter.ACTION_NDEF_DISCOVERED:
for (Parcelable message : getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
if (message instanceof NdefMessage) {
@ -601,16 +590,14 @@ public class StartConversationActivity extends XmppActivity {
case NdefRecord.TNF_WELL_KNOWN:
if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
invite = new Invite(record.toUri());
return new Invite(record.toUri()).invite();
} else {
byte[] mPayload = record.getPayload();
if (mPayload[0] == 0) {
invite = new Invite(Uri.parse(new String(Arrays.copyOfRange(
mPayload, 1, mPayload.length))));
byte[] payload = record.getPayload();
if (payload[0] == 0) {
return new Invite(Uri.parse(new String(Arrays.copyOfRange(
payload, 1, payload.length)))).invite();
}
}
if (invite != null) {
return invite.invite();
}
}
}
@ -618,9 +605,6 @@ public class StartConversationActivity extends XmppActivity {
}
}
return false;
default:
return false;
}
}
private boolean handleJid(String jid) {
@ -776,12 +760,22 @@ public class StartConversationActivity extends XmppActivity {
}
void parse(Uri uri) {
muc = uri.getQuery() != null && uri.getQuery().equalsIgnoreCase("join");
String scheme = uri.getScheme();
if ("xmpp".equals(scheme)) {
// sample: xmpp:jid@foo.com
muc = "join".equalsIgnoreCase(uri.getQuery());
if (uri.getAuthority() != null) {
jid = uri.getAuthority();
} else {
jid = uri.getSchemeSpecificPart().split("\\?")[0];
}
} else if ("imto".equals(scheme)) {
// sample: imto://xmpp/jid@foo.com
try {
jid = URLDecoder.decode(uri.getEncodedPath(), "UTF-8").split("/")[1];
} catch (UnsupportedEncodingException e) {
}
}
}
}
}