made qr code scanner work in choose contact
This commit is contained in:
parent
69374f3e5f
commit
7e963820a5
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
|
@ -28,6 +29,9 @@ import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
import eu.siacs.conversations.entities.ListItem;
|
import eu.siacs.conversations.entities.ListItem;
|
||||||
import eu.siacs.conversations.entities.MucOptions;
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
|
import eu.siacs.conversations.ui.util.ActivityResult;
|
||||||
|
import eu.siacs.conversations.ui.util.PendingItem;
|
||||||
|
import eu.siacs.conversations.utils.XmppUri;
|
||||||
import rocks.xmpp.addr.Jid;
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
|
@ -37,6 +41,8 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
private Set<Contact> selected;
|
private Set<Contact> selected;
|
||||||
private Set<String> filterContacts;
|
private Set<String> filterContacts;
|
||||||
|
|
||||||
|
private PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
|
||||||
|
|
||||||
public static Intent create(Activity activity, Conversation conversation) {
|
public static Intent create(Activity activity, Conversation conversation) {
|
||||||
final Intent intent = new Intent(activity, ChooseContactActivity.class);
|
final Intent intent = new Intent(activity, ChooseContactActivity.class);
|
||||||
List<String> contacts = new ArrayList<>();
|
List<String> contacts = new ArrayList<>();
|
||||||
|
@ -148,7 +154,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
final Intent i = getIntent();
|
final Intent i = getIntent();
|
||||||
boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
|
boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
|
||||||
if (showEnterJid) {
|
if (showEnterJid) {
|
||||||
this.binding.fab.setOnClickListener((v) -> showEnterJidDialog());
|
this.binding.fab.setOnClickListener((v) -> showEnterJidDialog(null));
|
||||||
} else {
|
} else {
|
||||||
this.binding.fab.setVisibility(View.GONE);
|
this.binding.fab.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -222,11 +228,17 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showEnterJidDialog() {
|
protected void showEnterJidDialog(XmppUri uri) {
|
||||||
|
Jid jid = uri == null ? null : uri.getJid();
|
||||||
EnterJidDialog dialog = new EnterJidDialog(
|
EnterJidDialog dialog = new EnterJidDialog(
|
||||||
this, mKnownHosts, mActivatedAccounts,
|
this,
|
||||||
getString(R.string.enter_contact), getString(R.string.select),
|
mKnownHosts,
|
||||||
null, getIntent().getStringExtra(EXTRA_ACCOUNT), true
|
mActivatedAccounts,
|
||||||
|
getString(R.string.enter_contact),
|
||||||
|
getString(R.string.select),
|
||||||
|
jid == null ? null : jid.asBareJid().toString(),
|
||||||
|
getIntent().getStringExtra(EXTRA_ACCOUNT),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
|
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
|
||||||
|
@ -247,6 +259,27 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
filterContacts();
|
filterContacts();
|
||||||
|
@ -261,5 +294,14 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.mKnownHosts = xmppConnectionService.getKnownHosts();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue