From 2df1aaaed2728a0c3cff26df630f13a47bc11c57 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 18 Feb 2018 19:09:36 +0100 Subject: [PATCH] use data binder for contact key item --- .../siacs/conversations/ui/OmemoActivity.java | 97 +++++++++---------- src/main/res/layout/contact_key.xml | 80 +++++++-------- 2 files changed, 82 insertions(+), 95 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java b/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java index 0d8b69ee6..50ce5ae21 100644 --- a/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.ui; +import android.databinding.DataBindingUtil; import android.support.v7.app.AlertDialog; import android.content.Intent; import android.os.Bundle; @@ -22,6 +23,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; +import eu.siacs.conversations.databinding.ContactKeyBinding; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.XmppUri; @@ -128,88 +130,79 @@ public abstract class OmemoActivity extends XmppActivity { boolean undecidedNeedEnablement, CompoundButton.OnCheckedChangeListener onCheckedChangeListener) { - View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false); - TextView key = view.findViewById(R.id.key); - TextView keyType = view.findViewById(R.id.key_type); - ImageButton enableUndecided = view.findViewById(R.id.button_enable_device); + ContactKeyBinding binding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.contact_key,keys,true); if (Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509) { - key.setOnClickListener(v -> showX509Certificate(account,fingerprint)); - keyType.setOnClickListener(v -> showX509Certificate(account,fingerprint)); + binding.key.setOnClickListener(v -> showX509Certificate(account,fingerprint)); + binding.keyType.setOnClickListener(v -> showX509Certificate(account,fingerprint)); } - SwitchCompat trustToggle = view.findViewById(R.id.tgl_trust); - ImageView verifiedFingerprintSymbol = view.findViewById(R.id.verified_fingerprint); - trustToggle.setVisibility(View.VISIBLE); - registerForContextMenu(view); - view.setTag(R.id.TAG_ACCOUNT,account); - view.setTag(R.id.TAG_FINGERPRINT,fingerprint); - view.setTag(R.id.TAG_FINGERPRINT_STATUS,status); + binding.tglTrust.setVisibility(View.VISIBLE); + registerForContextMenu(binding.getRoot()); + binding.getRoot().setTag(R.id.TAG_ACCOUNT,account); + binding.getRoot().setTag(R.id.TAG_FINGERPRINT,fingerprint); + binding.getRoot().setTag(R.id.TAG_FINGERPRINT_STATUS,status); boolean x509 = Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509; final View.OnClickListener toast; - trustToggle.setChecked(status.isTrusted()); + binding.tglTrust.setChecked(status.isTrusted()); if (status.isActive()){ - key.setTextColor(getPrimaryTextColor()); - keyType.setTextColor(getSecondaryTextColor()); + binding.key.setTextColor(getPrimaryTextColor()); + binding.keyType.setTextColor(getSecondaryTextColor()); if (status.isVerified()) { - verifiedFingerprintSymbol.setVisibility(View.VISIBLE); - verifiedFingerprintSymbol.setAlpha(1.0f); - trustToggle.setVisibility(View.GONE); - verifiedFingerprintSymbol.setOnClickListener(v -> replaceToast(getString(R.string.this_device_has_been_verified), false)); + binding.verifiedFingerprint.setVisibility(View.VISIBLE); + binding.verifiedFingerprint.setAlpha(1.0f); + binding.tglTrust.setVisibility(View.GONE); + binding.verifiedFingerprint.setOnClickListener(v -> replaceToast(getString(R.string.this_device_has_been_verified), false)); toast = null; } else { - verifiedFingerprintSymbol.setVisibility(View.GONE); - trustToggle.setVisibility(View.VISIBLE); - trustToggle.setOnCheckedChangeListener(onCheckedChangeListener); + binding.verifiedFingerprint.setVisibility(View.GONE); + binding.tglTrust.setVisibility(View.VISIBLE); + binding.tglTrust.setOnCheckedChangeListener(onCheckedChangeListener); if (status.getTrust() == FingerprintStatus.Trust.UNDECIDED && undecidedNeedEnablement) { - enableUndecided.setVisibility(View.VISIBLE); - enableUndecided.setOnClickListener(v -> { + binding.buttonEnableDevice.setVisibility(View.VISIBLE); + binding.buttonEnableDevice.setOnClickListener(v -> { account.getAxolotlService().setFingerprintTrust(fingerprint,FingerprintStatus.createActive(false)); - enableUndecided.setVisibility(View.GONE); - trustToggle.setVisibility(View.VISIBLE); + binding.buttonEnableDevice.setVisibility(View.GONE); + binding.tglTrust.setVisibility(View.VISIBLE); }); - trustToggle.setVisibility(View.GONE); + binding.tglTrust.setVisibility(View.GONE); } else { - trustToggle.setOnClickListener(null); - trustToggle.setEnabled(true); + binding.tglTrust.setOnClickListener(null); + binding.tglTrust.setEnabled(true); } toast = v -> hideToast(); } } else { - key.setTextColor(getTertiaryTextColor()); - keyType.setTextColor(getTertiaryTextColor()); + binding.key.setTextColor(getTertiaryTextColor()); + binding.keyType.setTextColor(getTertiaryTextColor()); toast = v -> replaceToast(getString(R.string.this_device_is_no_longer_in_use), false); if (status.isVerified()) { - trustToggle.setVisibility(View.GONE); - verifiedFingerprintSymbol.setVisibility(View.VISIBLE); - verifiedFingerprintSymbol.setAlpha(0.4368f); - verifiedFingerprintSymbol.setOnClickListener(toast); + binding.tglTrust.setVisibility(View.GONE); + binding.verifiedFingerprint.setVisibility(View.VISIBLE); + binding.verifiedFingerprint.setAlpha(0.4368f); + binding.verifiedFingerprint.setOnClickListener(toast); } else { - trustToggle.setVisibility(View.VISIBLE); - verifiedFingerprintSymbol.setVisibility(View.GONE); - trustToggle.setOnClickListener(null); - trustToggle.setEnabled(false); - trustToggle.setOnClickListener(toast); + binding.tglTrust.setVisibility(View.VISIBLE); + binding.verifiedFingerprint.setVisibility(View.GONE); + binding.tglTrust.setEnabled(false); } } - view.setOnClickListener(toast); - key.setOnClickListener(toast); - keyType.setOnClickListener(toast); + binding.getRoot().setOnClickListener(toast); + binding.key.setOnClickListener(toast); + binding.keyType.setOnClickListener(toast); if (showTag) { - keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509 : R.string.omemo_fingerprint)); + binding.keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509 : R.string.omemo_fingerprint)); } else { - keyType.setVisibility(View.GONE); + binding.keyType.setVisibility(View.GONE); } if (highlight) { - keyType.setTextColor(ContextCompat.getColor(this, R.color.accent)); - keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509_selected_message : R.string.omemo_fingerprint_selected_message)); + binding.keyType.setTextColor(ContextCompat.getColor(this, R.color.accent)); + binding.keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509_selected_message : R.string.omemo_fingerprint_selected_message)); } else { - keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509 : R.string.omemo_fingerprint)); + binding.keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509 : R.string.omemo_fingerprint)); } - key.setText(CryptoHelper.prettifyFingerprint(fingerprint.substring(2))); - - keys.addView(view); + binding.key.setText(CryptoHelper.prettifyFingerprint(fingerprint.substring(2))); } public void showPurgeKeyDialog(final Account account, final String fingerprint) { diff --git a/src/main/res/layout/contact_key.xml b/src/main/res/layout/contact_key.xml index a194f9e18..c2d5648fd 100644 --- a/src/main/res/layout/contact_key.xml +++ b/src/main/res/layout/contact_key.xml @@ -1,59 +1,52 @@ - + - + android:orientation="vertical"> - + + + + - + android:orientation="vertical"> + + android:visibility="gone"/> + + android:visibility="gone"/> + android:src="@drawable/ic_verified_fingerprint" + android:visibility="gone"/> + android:visibility="gone"/> - \ No newline at end of file + \ No newline at end of file