2017-12-07 20:59:13 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2018-02-17 08:21:50 +00:00
|
|
|
import android.support.v7.app.AppCompatActivity ;
|
2017-12-07 20:59:13 +00:00
|
|
|
import android.content.Intent;
|
2017-12-07 21:13:24 +00:00
|
|
|
import android.net.Uri;
|
2018-02-12 10:22:51 +00:00
|
|
|
import android.util.Log;
|
2017-12-10 10:44:10 +00:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
2017-12-15 17:25:21 +00:00
|
|
|
import java.util.List;
|
2017-12-10 10:44:10 +00:00
|
|
|
|
2018-02-12 10:22:51 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2017-12-07 21:13:24 +00:00
|
|
|
import eu.siacs.conversations.persistance.DatabaseBackend;
|
|
|
|
import eu.siacs.conversations.utils.XmppUri;
|
2018-02-12 10:22:51 +00:00
|
|
|
import eu.siacs.conversations.utils.zxing.IntentIntegrator;
|
|
|
|
import eu.siacs.conversations.utils.zxing.IntentResult;
|
2017-12-07 21:13:24 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2017-12-07 20:59:13 +00:00
|
|
|
|
2018-02-17 08:21:50 +00:00
|
|
|
public class UriHandlerActivity extends AppCompatActivity {
|
2017-12-10 10:44:10 +00:00
|
|
|
public static final String ACTION_SCAN_QR_CODE = "scan_qr_code";
|
2017-12-07 20:59:13 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
handleIntent(getIntent());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNewIntent(Intent intent) {
|
|
|
|
handleIntent(intent);
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:13:24 +00:00
|
|
|
private void handleUri(Uri uri) {
|
|
|
|
final Intent intent;
|
|
|
|
final XmppUri xmppUri = new XmppUri(uri);
|
2017-12-15 17:25:21 +00:00
|
|
|
final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids();
|
2017-12-07 21:13:24 +00:00
|
|
|
|
2017-12-15 17:25:21 +00:00
|
|
|
if (accounts.size() == 0) {
|
2017-12-07 21:13:24 +00:00
|
|
|
intent = new Intent(getApplicationContext(), WelcomeActivity.class);
|
2018-02-14 15:55:45 +00:00
|
|
|
WelcomeActivity.addInviteUri(intent, xmppUri);
|
2017-12-07 21:13:24 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-12-15 17:25:21 +00:00
|
|
|
} else if (accounts.contains(xmppUri.getJid())) {
|
|
|
|
intent = new Intent(getApplicationContext(), EditAccountActivity.class);
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.putExtra("jid", xmppUri.getJid().toBareJid().toString());
|
|
|
|
intent.setData(uri);
|
2017-12-07 21:13:24 +00:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
|
2017-12-07 20:59:13 +00:00
|
|
|
private void handleIntent(Intent data) {
|
2017-12-15 17:25:21 +00:00
|
|
|
if (data == null || data.getAction() == null) {
|
2017-12-07 20:59:13 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (data.getAction()) {
|
|
|
|
case Intent.ACTION_VIEW:
|
|
|
|
case Intent.ACTION_SENDTO:
|
2017-12-07 21:13:24 +00:00
|
|
|
handleUri(data.getData());
|
2017-12-10 10:44:10 +00:00
|
|
|
break;
|
|
|
|
case ACTION_SCAN_QR_CODE:
|
|
|
|
new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC", "QR_CODE"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) {
|
2018-02-12 10:22:51 +00:00
|
|
|
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
2017-12-10 10:44:10 +00:00
|
|
|
|
|
|
|
if (scanResult != null && scanResult.getFormatName() != null) {
|
|
|
|
String data = scanResult.getContents();
|
|
|
|
handleUri(Uri.parse(data));
|
|
|
|
}
|
2017-12-07 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
finish();
|
2017-12-10 10:44:10 +00:00
|
|
|
super.onActivityResult(requestCode, requestCode, intent);
|
2017-12-07 20:59:13 +00:00
|
|
|
}
|
|
|
|
}
|