aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java117
1 files changed, 59 insertions, 58 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index aa19ff0e..87670f78 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -16,6 +16,7 @@ import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
+import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v13.app.FragmentPagerAdapter;
@@ -44,7 +45,9 @@ import com.google.zxing.integration.android.IntentResult;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -530,13 +533,9 @@ public class StartConversationActivity extends XmppActivity {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null && scanResult.getFormatName() != null) {
String data = scanResult.getContents();
- Invite invite = parseInviteUri(data);
+ Invite invite = new Invite(data);
if (xmppConnectionServiceBound) {
- if (invite.muc) {
- showJoinConferenceDialog(invite.jid);
- } else {
- handleJid(invite.jid);
- }
+ invite.invite();
} else if (invite.jid != null) {
this.mPendingInvite = invite;
} else {
@@ -560,11 +559,7 @@ public class StartConversationActivity extends XmppActivity {
this.mKnownConferenceHosts = xmppConnectionService
.getKnownConferenceHosts();
if (this.mPendingInvite != null) {
- if (this.mPendingInvite.muc) {
- showJoinConferenceDialog(this.mPendingInvite.jid);
- } else {
- handleJid(this.mPendingInvite.jid);
- }
+ mPendingInvite.invite();
this.mPendingInvite = null;
} else if (!handleIntent(getIntent())) {
if (mSearchEditText != null) {
@@ -580,13 +575,12 @@ public class StartConversationActivity extends XmppActivity {
if (intent == null || intent.getAction() == null) {
return false;
}
- String jid;
- Uri uri;
- Invite invite;
+ Invite invite = null;
switch (intent.getAction()) {
case Intent.ACTION_SENDTO:
try {
- jid = URLDecoder.decode(
+ // TODO use Intent.parse ?!?
+ String jid = URLDecoder.decode(
intent.getData().getEncodedPath(), "UTF-8").split(
"/")[1];
return handleJid(jid);
@@ -594,55 +588,30 @@ public class StartConversationActivity extends XmppActivity {
return false;
}
case Intent.ACTION_VIEW:
- uri = intent.getData();
- invite = parseInviteUri(uri);
- if (invite.muc) {
- showJoinConferenceDialog(invite.jid);
- return false;
- } else {
- return handleJid(invite.jid);
- }
+ invite = new Invite(intent.getData());
+ invite.invite();
case NfcAdapter.ACTION_NDEF_DISCOVERED:
- if (android.os.Build.VERSION.SDK_INT >= 16) {
- Parcelable[] messages = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
- NdefMessage message = (NdefMessage) messages[0];
- NdefRecord record = message.getRecords()[0];
- invite = parseInviteUri(record.toUri());
- if (invite != null) {
- if (invite.muc) {
- showJoinConferenceDialog(invite.jid);
- return false;
- } else {
- return handleJid(invite.jid);
- }
- }
+ Parcelable[] messages = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
+ NdefMessage message = (NdefMessage) messages[0];
+ NdefRecord record = message.getRecords()[0];
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ invite = new Invite(record.toUri());
} else {
- return false;
+ byte[] mPayload = record.getPayload();
+ if (mPayload[0] == 0) {
+ invite = new Invite(Uri.parse(new String(Arrays.copyOfRange(
+ mPayload, 1, mPayload.length), StandardCharsets.UTF_8)));
+ }
+ }
+ if (invite != null) {
+ return invite.invite();
}
+ return false;
default:
return false;
}
}
- 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) {
List<Contact> contacts = xmppConnectionService.findContacts(jid);
if (contacts.size() == 0) {
@@ -769,7 +738,39 @@ public class StartConversationActivity extends XmppActivity {
}
private class Invite {
- public String jid;
- public boolean muc;
+ private String jid;
+ 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];
+ }
+ }
}
}