aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
diff options
context:
space:
mode:
authorAndreas Straub <andy@strb.org>2015-07-19 14:09:49 +0200
committerAndreas Straub <andy@strb.org>2015-07-19 22:24:03 +0200
commit6f67469bda0ffe97cb8cd8d400affed5a17c34c5 (patch)
tree613d1076eff9802f4cdb47b8998db69ec688cb14 /src/main/java/eu/siacs/conversations/ui/XmppActivity.java
parent9c4d55f82ce50391ac09b4f7d7a0f3576c014e56 (diff)
Refactor trust key ui and show in account details
Refactored the trust key row UI element so it can be used in multiple places. It now also uses a slider to toggle the trust state, and the redundant trust state description was removed. EditAccountActivity now shows the keys of other devices associated with that account.
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/XmppActivity.java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index 7c994c31..9dfece2f 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -43,8 +43,11 @@ import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
+import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.BarcodeFormat;
@@ -53,9 +56,12 @@ import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+import com.kyleduo.switchbutton.SwitchButton;
import net.java.otr4j.session.SessionID;
+import org.whispersystems.libaxolotl.IdentityKey;
+
import java.io.FileNotFoundException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -65,6 +71,7 @@ import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
@@ -74,6 +81,8 @@ import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
+import eu.siacs.conversations.ui.widget.Switch;
+import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
@@ -588,6 +597,76 @@ public abstract class XmppActivity extends Activity {
builder.create().show();
}
+ protected void addFingerprintRow(LinearLayout keys, final Account account, IdentityKey identityKey) {
+ final String fingerprint = identityKey.getFingerprint().replaceAll("\\s", "");
+ final AxolotlService.SQLiteAxolotlStore.Trust trust = account.getAxolotlService()
+ .getFingerprintTrust(fingerprint);
+ addFingerprintRowWithListeners(keys, account, identityKey, trust, true,
+ new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked != (trust == AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED)) {
+ account.getAxolotlService().setFingerprintTrust(fingerprint,
+ (isChecked) ? AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED :
+ AxolotlService.SQLiteAxolotlStore.Trust.UNTRUSTED);
+ }
+ refreshUi();
+ xmppConnectionService.updateAccountUi();
+ xmppConnectionService.updateConversationUi();
+ }
+ },
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ account.getAxolotlService().setFingerprintTrust(fingerprint,
+ AxolotlService.SQLiteAxolotlStore.Trust.UNTRUSTED);
+ refreshUi();
+ xmppConnectionService.updateAccountUi();
+ xmppConnectionService.updateConversationUi();
+ }
+ }
+
+ );
+ }
+
+ protected void addFingerprintRowWithListeners(LinearLayout keys, final Account account,
+ IdentityKey identityKey,
+ AxolotlService.SQLiteAxolotlStore.Trust trust,
+ boolean showTag,
+ CompoundButton.OnCheckedChangeListener
+ onCheckedChangeListener,
+ View.OnClickListener onClickListener) {
+ View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
+ TextView key = (TextView) view.findViewById(R.id.key);
+ TextView keyType = (TextView) view.findViewById(R.id.key_type);
+ Switch trustToggle = (Switch) view.findViewById(R.id.tgl_trust);
+ trustToggle.setVisibility(View.VISIBLE);
+ trustToggle.setOnCheckedChangeListener(onCheckedChangeListener);
+ trustToggle.setOnClickListener(onClickListener);
+
+ switch (trust) {
+ case UNTRUSTED:
+ case TRUSTED:
+ trustToggle.setChecked(trust == AxolotlService.SQLiteAxolotlStore.Trust.TRUSTED, false);
+ trustToggle.setEnabled(true);
+ break;
+ case UNDECIDED:
+ trustToggle.setChecked(false, false);
+ trustToggle.setEnabled(false);
+ break;
+ }
+
+ if (showTag) {
+ keyType.setText(getString(R.string.axolotl_fingerprint));
+ } else {
+ keyType.setVisibility(View.GONE);
+ }
+
+ key.setText(CryptoHelper.prettifyFingerprint(identityKey.getFingerprint()));
+ keys.addView(view);
+
+ }
+
public void selectPresence(final Conversation conversation,
final OnPresenceSelected listener) {
final Contact contact = conversation.getContact();