aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-03 21:19:15 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-03 21:19:15 +0200
commitbab6dc3ec06217b45675c15edf1ed7d9c9d431f6 (patch)
tree97a0821c5cc6d2a63d6393d8bec2b748a1807192 /src/main/java
parenta37b60a4bb5b2c4b862b84c27aa548f49483c8e0 (diff)
made qr code scanner work in choose contact
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
index 647330c71..a6203215a 100644
--- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.ActionBar;
import android.view.ActionMode;
@@ -28,6 +29,9 @@ import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.ListItem;
import de.pixart.messenger.entities.MucOptions;
+import de.pixart.messenger.ui.util.ActivityResult;
+import de.pixart.messenger.ui.util.PendingItem;
+import de.pixart.messenger.utils.XmppUri;
import rocks.xmpp.addr.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
@@ -37,6 +41,8 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
private Set<Contact> selected;
private Set<String> filterContacts;
+ private PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
+
public static Intent create(Activity activity, Conversation conversation) {
final Intent intent = new Intent(activity, ChooseContactActivity.class);
List<String> contacts = new ArrayList<>();
@@ -149,7 +155,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
final Intent i = getIntent();
boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
if (showEnterJid) {
- this.binding.fab.setOnClickListener((v) -> showEnterJidDialog());
+ this.binding.fab.setOnClickListener((v) -> showEnterJidDialog(null));
} else {
this.binding.fab.setVisibility(View.GONE);
}
@@ -223,11 +229,18 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
return super.onOptionsItemSelected(item);
}
- protected void showEnterJidDialog() {
+ protected void showEnterJidDialog(XmppUri uri) {
+ Jid jid = uri == null ? null : uri.getJid();
EnterJidDialog dialog = new EnterJidDialog(
- this, mKnownHosts, mActivatedAccounts,
- getString(R.string.enter_contact), getString(R.string.select),
- null, getIntent().getStringExtra(EXTRA_ACCOUNT), true, xmppConnectionService.multipleAccounts()
+ this,
+ mKnownHosts,
+ mActivatedAccounts,
+ getString(R.string.enter_contact),
+ getString(R.string.select),
+ jid == null ? null : jid.asBareJid().toString(),
+ getIntent().getStringExtra(EXTRA_ACCOUNT),
+ true,
+ xmppConnectionService.multipleAccounts()
);
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
@@ -249,6 +262,27 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
@Override
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+ super.onActivityResult(requestCode, requestCode, intent);
+ ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, intent);
+ if (xmppConnectionService != null) {
+ handleActivityResult(activityResult);
+ } else {
+ this.postponedActivityResult.push(activityResult);
+ }
+ }
+
+ private void handleActivityResult(ActivityResult activityResult) {
+ if (activityResult.resultCode == RESULT_OK && activityResult.requestCode == ScanActivity.REQUEST_SCAN_QR_CODE) {
+ String result = activityResult.data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
+ XmppUri uri = new XmppUri(result == null ? "" : result);
+ if (uri.isJidValid()) {
+ showEnterJidDialog(uri);
+ }
+ }
+ }
+
+ @Override
void onBackendConnected() {
filterContacts();
@@ -263,5 +297,14 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
}
this.mKnownHosts = xmppConnectionService.getKnownHosts();
+ ActivityResult activityResult = this.postponedActivityResult.pop();
+ if (activityResult != null) {
+ handleActivityResult(activityResult);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
+ ScanActivity.onRequestPermissionResult(this, requestCode, grantResults);
}
}