remove NFC handling + let edit account handle own jids
This commit is contained in:
parent
6a9abd0e49
commit
cc6a001ac2
|
@ -59,7 +59,8 @@
|
|||
<activity
|
||||
android:name=".ui.UriHandlerActivity"
|
||||
android:label="@string/title_activity_start_conversation"
|
||||
android:launchMode="singleTop">
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
|
@ -80,7 +81,6 @@
|
|||
<data android:pathPrefix="/j/" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
|
||||
<action android:name="android.intent.action.SENDTO" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
|
|
@ -746,7 +746,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
return getAccounts(db);
|
||||
}
|
||||
|
||||
public Collection<Jid> getAccountJids() {
|
||||
public List<Jid> getAccountJids() {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
final List<Jid> jids = new ArrayList<>();
|
||||
final String[] columns = new String[]{Account.USERNAME, Account.SERVER};
|
||||
|
|
|
@ -271,6 +271,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
private String mSavedInstanceAccount;
|
||||
private boolean mSavedInstanceInit = false;
|
||||
private Button mClearDevicesButton;
|
||||
private XmppUri pendingUri = null;
|
||||
|
||||
public void refreshUiReal() {
|
||||
invalidateOptionsMenu();
|
||||
|
@ -403,11 +404,16 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
|
||||
@Override
|
||||
protected void processFingerprintVerification(XmppUri uri) {
|
||||
processFingerprintVerification(uri,true);
|
||||
}
|
||||
|
||||
|
||||
protected void processFingerprintVerification(XmppUri uri, boolean showWarningToast) {
|
||||
if (mAccount != null && mAccount.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) {
|
||||
if (xmppConnectionService.verifyFingerprints(mAccount,uri.getFingerprints())) {
|
||||
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
} else if (showWarningToast) {
|
||||
Toast.makeText(this,R.string.invalid_barcode,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
@ -635,6 +641,14 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
} catch (final InvalidJidException | NullPointerException ignored) {
|
||||
this.jidToEdit = null;
|
||||
}
|
||||
if (jidToEdit != null && getIntent().getData() != null) {
|
||||
final XmppUri uri = new XmppUri(getIntent().getData());
|
||||
if (xmppConnectionServiceBound) {
|
||||
processFingerprintVerification(uri, false);
|
||||
} else {
|
||||
this.pendingUri = uri;
|
||||
}
|
||||
}
|
||||
boolean init = getIntent().getBooleanExtra("init", false);
|
||||
this.mInitMode = init || this.jidToEdit == null;
|
||||
this.messageFingerprint = getIntent().getStringExtra("fingerprint");
|
||||
|
@ -662,6 +676,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
if (intent != null && intent.getData() != null) {
|
||||
final XmppUri uri = new XmppUri(intent.getData());
|
||||
if (xmppConnectionServiceBound) {
|
||||
processFingerprintVerification(uri, false);
|
||||
} else {
|
||||
this.pendingUri = uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
||||
if (mAccount != null) {
|
||||
|
@ -697,7 +723,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
}
|
||||
}
|
||||
if (mPendingFingerprintVerificationUri != null) {
|
||||
processFingerprintVerification(mPendingFingerprintVerificationUri);
|
||||
processFingerprintVerification(mPendingFingerprintVerificationUri, false);
|
||||
mPendingFingerprintVerificationUri = null;
|
||||
}
|
||||
updateAccountInformation(init);
|
||||
|
@ -717,6 +743,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
|||
xmppConnectionService.getKnownHosts());
|
||||
this.mAccountJid.setAdapter(mKnownHostsAdapter);
|
||||
}
|
||||
|
||||
if (pendingUri != null) {
|
||||
processFingerprintVerification(pendingUri, false);
|
||||
pendingUri = null;
|
||||
}
|
||||
|
||||
updateSaveButton();
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
|
|
@ -821,15 +821,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
}
|
||||
|
||||
private boolean handleJid(Invite invite) {
|
||||
Account account = xmppConnectionService.findAccountByJid(invite.getJid());
|
||||
if (account != null && account.isEnabled()) {
|
||||
if (invite.hasFingerprints() && xmppConnectionService.verifyFingerprints(account,invite.getFingerprints())) {
|
||||
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
switchToAccount(account);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account);
|
||||
if (invite.isAction(XmppUri.ACTION_JOIN)) {
|
||||
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.Build;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.persistance.DatabaseBackend;
|
||||
import eu.siacs.conversations.utils.XmppUri;
|
||||
|
@ -33,17 +28,12 @@ public class UriHandlerActivity extends Activity {
|
|||
handleIntent(intent);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
Uri getInviteJellyBean(NdefRecord record) {
|
||||
return record.toUri();
|
||||
}
|
||||
|
||||
private void handleUri(Uri uri) {
|
||||
final Intent intent;
|
||||
final XmppUri xmppUri = new XmppUri(uri);
|
||||
final int numAccounts = DatabaseBackend.getInstance(this).getAccountJids().size();
|
||||
final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids();
|
||||
|
||||
if (numAccounts == 0) {
|
||||
if (accounts.size() == 0) {
|
||||
intent = new Intent(getApplicationContext(), WelcomeActivity.class);
|
||||
startActivity(intent);
|
||||
return;
|
||||
|
@ -63,6 +53,11 @@ public class UriHandlerActivity extends Activity {
|
|||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, body);
|
||||
}
|
||||
} 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);
|
||||
} else {
|
||||
intent = new Intent(getApplicationContext(), StartConversationActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
|
@ -73,32 +68,8 @@ public class UriHandlerActivity extends Activity {
|
|||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void handleNfcIntent(Intent data) {
|
||||
for (Parcelable message : data.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
|
||||
if (message instanceof NdefMessage) {
|
||||
for (NdefRecord record : ((NdefMessage) message).getRecords()) {
|
||||
switch (record.getTnf()) {
|
||||
case NdefRecord.TNF_WELL_KNOWN:
|
||||
if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
handleUri(getInviteJellyBean(record));
|
||||
} else {
|
||||
byte[] payload = record.getPayload();
|
||||
if (payload[0] == 0) {
|
||||
Uri uri = Uri.parse(new String(Arrays.copyOfRange(
|
||||
payload, 1, payload.length)));
|
||||
handleUri(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleIntent(Intent data) {
|
||||
if (data == null) {
|
||||
if (data == null || data.getAction() == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
@ -111,8 +82,6 @@ public class UriHandlerActivity extends Activity {
|
|||
case ACTION_SCAN_QR_CODE:
|
||||
new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC", "QR_CODE"));
|
||||
return;
|
||||
case NfcAdapter.ACTION_NDEF_DISCOVERED:
|
||||
handleNfcIntent(data);
|
||||
}
|
||||
|
||||
finish();
|
||||
|
|
Loading…
Reference in New Issue