aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-12-16 23:35:06 +0100
committerChristian Schneppe <christian@pix-art.de>2017-12-16 23:35:06 +0100
commit8f0a1c8cd8593fa4288e849886aa253dea7e8eb6 (patch)
tree285eb012d2bdcf2d0b49e7a429779698492e2b8a /src/main/java/de
parent20f15c02a630d7abb6935418136bd5c6ab109231 (diff)
remove NFC handling + let edit account handle own jids
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java34
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java40
-rw-r--r--src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java12
4 files changed, 42 insertions, 47 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
index ea7f00c87..09a018d3d 100644
--- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
@@ -28,7 +28,6 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -757,7 +756,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};
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 655f83514..3f9c6c48d 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -287,6 +287,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();
@@ -419,11 +420,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();
}
}
@@ -672,6 +678,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");
@@ -700,6 +714,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
@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) {
savedInstanceState.putString("account", mAccount.getJid().toBareJid().toString());
@@ -734,7 +760,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
}
if (mPendingFingerprintVerificationUri != null) {
- processFingerprintVerification(mPendingFingerprintVerificationUri);
+ processFingerprintVerification(mPendingFingerprintVerificationUri, false);
mPendingFingerprintVerificationUri = null;
}
updateAccountInformation(init);
@@ -754,6 +780,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
xmppConnectionService.getKnownHosts());
this.mAccountJid.setAdapter(mKnownHostsAdapter);
}
+ if (pendingUri != null) {
+ processFingerprintVerification(pendingUri, false);
+ pendingUri = null;
+ }
updateSaveButton();
invalidateOptionsMenu();
}
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index 23bdc056b..b5c2e9b5e 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -2,7 +2,6 @@ package de.pixart.messenger.ui;
import android.Manifest;
import android.annotation.SuppressLint;
-import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
@@ -20,12 +19,8 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
-import android.nfc.NdefMessage;
-import android.nfc.NdefRecord;
-import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
-import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Editable;
@@ -809,11 +804,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
setIntent(null);
}
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- Invite getInviteJellyBean(NdefRecord record) {
- return new Invite(record.toUri());
- }
-
protected boolean handleIntent(Intent intent) {
if (intent == null || intent.getAction() == null) {
return false;
@@ -829,41 +819,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else {
return false;
}
- case NfcAdapter.ACTION_NDEF_DISCOVERED:
- for (Parcelable message : getIntent().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) {
- return getInviteJellyBean(record).invite();
- } else {
- byte[] payload = record.getPayload();
- if (payload[0] == 0) {
- return new Invite(Uri.parse(new String(Arrays.copyOfRange(
- payload, 1, payload.length)))).invite();
- }
- }
- }
- }
- }
- }
- }
}
return false;
}
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());
diff --git a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
index e43e1ccd7..c5c2bcffe 100644
--- a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
@@ -8,6 +8,7 @@ import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import java.util.Arrays;
+import java.util.List;
import de.pixart.messenger.persistance.DatabaseBackend;
import de.pixart.messenger.utils.XmppUri;
@@ -30,9 +31,9 @@ public class UriHandlerActivity extends Activity {
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;
@@ -52,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);
@@ -63,7 +69,7 @@ public class UriHandlerActivity extends Activity {
}
private void handleIntent(Intent data) {
- if (data == null) {
+ if (data == null || data.getAction() == null) {
finish();
return;
}