diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-12-16 23:09:28 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-12-16 23:09:28 +0100 |
commit | 37762ab5caec9aab35c3a3aeb79bc099535b2466 (patch) | |
tree | 434799c6f605eacf96ffabb17fcb9d2e339e4adc /src/main/java/de/pixart/messenger | |
parent | 6f55d00c2c248676896b81a8f189a9de6d7a4ad7 (diff) |
UriHandlerActivity: Handle 'message action' XMPP URI
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java index 1229aae2e..43d2d6db7 100644 --- a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java @@ -2,6 +2,11 @@ package de.pixart.messenger.ui; import android.app.Activity; import android.content.Intent; +import android.net.Uri; + +import de.pixart.messenger.persistance.DatabaseBackend; +import de.pixart.messenger.utils.XmppUri; +import de.pixart.messenger.xmpp.jid.Jid; public class UriHandlerActivity extends Activity { @@ -16,6 +21,41 @@ public class UriHandlerActivity extends Activity { handleIntent(intent); } + private void handleUri(Uri uri) { + final Intent intent; + final XmppUri xmppUri = new XmppUri(uri); + final int numAccounts = DatabaseBackend.getInstance(this).getAccountJids().size(); + + if (numAccounts == 0) { + intent = new Intent(getApplicationContext(), WelcomeActivity.class); + startActivity(intent); + return; + } + + if (xmppUri.isAction(XmppUri.ACTION_MESSAGE)) { + final Jid jid = xmppUri.getJid(); + final String body = xmppUri.getBody(); + + if (jid != null) { + intent = new Intent(getApplicationContext(), ShareViaAccountActivity.class); + intent.putExtra(ShareViaAccountActivity.EXTRA_CONTACT, jid.toString()); + intent.putExtra(ShareViaAccountActivity.EXTRA_BODY, body); + } else { + intent = new Intent(getApplicationContext(), ShareWithActivity.class); + intent.setAction(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, body); + } + } else { + intent = new Intent(getApplicationContext(), StartConversationActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + intent.setData(uri); + } + + startActivity(intent); + } + private void handleIntent(Intent data) { if (data == null) { finish(); @@ -25,12 +65,7 @@ public class UriHandlerActivity extends Activity { switch (data.getAction()) { case Intent.ACTION_VIEW: case Intent.ACTION_SENDTO: - final Intent intent = new Intent(getApplicationContext(), - StartConversationActivity.class); - intent.setAction(data.getAction()); - intent.setData(data.getData()); - intent.setAction(data.getAction()); - startActivity(intent); + handleUri(data.getData()); } finish(); |