aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-16 00:20:20 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-16 00:20:20 +0100
commit88c3537b6869996098da25954985fcb0c6971635 (patch)
tree07e407896b951de710ec9027468d98022ae40241 /src/main/java/eu/siacs/conversations/ui
parent0fb1772f18e71755ce72a97f18ea2c28cc771aba (diff)
parse otr-fingerprint in qr codes and nfc. include otr fingerprint in shareable uri where ever possible
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java6
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java8
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java51
-rw-r--r--src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java5
5 files changed, 51 insertions, 21 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
index 96fb7b618..788244e36 100644
--- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
@@ -154,7 +154,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
protected String getShareableUri() {
if (contact != null) {
- return "xmpp:" + contact.getJid();
+ return contact.getShareableUri();
} else {
return "";
}
@@ -326,10 +326,8 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
keys.removeAllViews();
boolean hasKeys = false;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- for (Iterator<String> iterator = contact.getOtrFingerprints()
- .iterator(); iterator.hasNext(); ) {
+ for(final String otrFingerprint : contact.getOtrFingerprints()) {
hasKeys = true;
- final String otrFingerprint = iterator.next();
View view = inflater.inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type);
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index 7e28cc6c3..5dccde184 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -108,7 +108,7 @@ public class ConversationActivity extends XmppActivity implements
protected String getShareableUri() {
Conversation conversation = getSelectedConversation();
if (conversation != null) {
- return "xmpp:" + conversation.getAccount().getJid().toBareJid();
+ return conversation.getAccount().getShareableUri();
} else {
return "";
}
diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
index dc8185994..b9772bd7a 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
@@ -26,6 +26,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
+import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.Validator;
import eu.siacs.conversations.xmpp.XmppConnection.Features;
@@ -270,7 +271,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override
protected String getShareableUri() {
if (mAccount!=null) {
- return "xmpp:"+mAccount.getJid().toBareJid();
+ return mAccount.getShareableUri();
} else {
return "";
}
@@ -402,11 +403,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} else {
this.mServerInfoPep.setText(R.string.server_info_unavailable);
}
- final String fingerprint = this.mAccount
- .getOtrFingerprint(xmppConnectionService);
+ final String fingerprint = this.mAccount.getOtrFingerprint();
if (fingerprint != null) {
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
- this.mOtrFingerprint.setText(fingerprint);
+ this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(fingerprint));
this.mOtrFingerprintToClipboardButton
.setVisibility(View.VISIBLE);
this.mOtrFingerprintToClipboardButton
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index 766b39619..fe188737f 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -62,6 +62,7 @@ import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.ui.adapter.ListItemAdapter;
+import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.Validator;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -316,7 +317,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
@SuppressLint("InflateParams")
- protected void showCreateContactDialog(String prefilledJid) {
+ protected void showCreateContactDialog(final String prefilledJid, final String fingerprint) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.create_contact);
View dialogView = getLayoutInflater().inflate(
@@ -328,6 +329,12 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
android.R.layout.simple_list_item_1, mKnownHosts));
if (prefilledJid != null) {
jid.append(prefilledJid);
+ if (fingerprint!=null) {
+ jid.setFocusable(false);
+ jid.setFocusableInTouchMode(false);
+ jid.setClickable(false);
+ jid.setCursorVisible(false);
+ }
}
populateAccountSpinner(spinner);
builder.setView(dialogView);
@@ -367,6 +374,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (contact.showInRoster()) {
jid.setError(getString(R.string.contact_already_exists));
} else {
+ contact.addOtrFingerprint(fingerprint);
xmppConnectionService.createContact(contact);
dialog.dismiss();
switchToConversation(contact);
@@ -511,7 +519,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_create_contact:
- showCreateContactDialog(null);
+ showCreateContactDialog(null,null);
return true;
case R.id.action_join_conference:
showJoinConferenceDialog(null);
@@ -615,22 +623,29 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
return false;
}
- private boolean handleJid(String jid) {
- List<Contact> contacts = xmppConnectionService.findContacts(jid);
+ private boolean handleJid(Invite invite) {
+ List<Contact> contacts = xmppConnectionService.findContacts(invite.jid);
if (contacts.size() == 0) {
- showCreateContactDialog(jid);
+ showCreateContactDialog(invite.jid,invite.fingerprint);
return false;
} else if (contacts.size() == 1) {
- switchToConversation(contacts.get(0));
+ Contact contact = contacts.get(0);
+ if (invite.fingerprint != null) {
+ if (contact.addOtrFingerprint(invite.fingerprint)) {
+ Log.d(Config.LOGTAG,"added new fingerprint");
+ xmppConnectionService.syncRosterToDisk(contact.getAccount());
+ }
+ }
+ switchToConversation(contact);
return true;
} else {
if (mMenuSearchView != null) {
mMenuSearchView.expandActionView();
mSearchEditText.setText("");
- mSearchEditText.append(jid);
- filter(jid);
+ mSearchEditText.append(invite.jid);
+ filter(invite.jid);
} else {
- mInitialJid = jid;
+ mInitialJid = invite.jid;
}
return true;
}
@@ -743,6 +758,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private class Invite {
private String jid;
private boolean muc;
+ private String fingerprint;
Invite(Uri uri) {
parse(uri);
@@ -761,7 +777,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (muc) {
showJoinConferenceDialog(jid);
} else {
- return handleJid(jid);
+ return handleJid(this);
}
}
return false;
@@ -777,6 +793,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} else {
jid = uri.getSchemeSpecificPart().split("\\?")[0];
}
+ fingerprint = parseFingerprint(uri.getQuery());
} else if ("imto".equals(scheme)) {
// sample: imto://xmpp/jid@foo.com
try {
@@ -785,5 +802,19 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
}
}
+
+ String parseFingerprint(String query) {
+ if (query == null) {
+ return null;
+ } else {
+ final String NEEDLE = "otr-fingerprint=";
+ int index = query.indexOf(NEEDLE);
+ if (index >= 0 && query.length() >= (NEEDLE.length() + index + 40)) {
+ return CryptoHelper.prettifyFingerprint(query.substring(index + NEEDLE.length(), index + NEEDLE.length() + 40));
+ } else {
+ return null;
+ }
+ }
+ }
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java
index af3194e9f..bffc97433 100644
--- a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java
@@ -16,6 +16,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -184,7 +185,7 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
this.mVerificationAreaOne.setVisibility(View.VISIBLE);
this.mVerificationAreaTwo.setVisibility(View.VISIBLE);
this.mErrorNoSession.setVisibility(View.GONE);
- this.mYourFingerprint.setText(this.mAccount.getOtrFingerprint(xmppConnectionService));
+ this.mYourFingerprint.setText(CryptoHelper.prettifyFingerprint(this.mAccount.getOtrFingerprint()));
this.mRemoteFingerprint.setText(this.mConversation.getOtrFingerprint());
this.mRemoteJid.setText(this.mConversation.getContact().getJid().toBareJid().toString());
Conversation.Smp smp = mConversation.smp();
@@ -279,7 +280,7 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
@Override
protected String getShareableUri() {
if (mAccount!=null) {
- return "xmpp:"+mAccount.getJid().toBareJid();
+ return mAccount.getShareableUri();
} else {
return "";
}