use data binder for contact key item

This commit is contained in:
Daniel Gultsch 2018-02-18 19:09:36 +01:00
parent 1b8a437b1e
commit 2df1aaaed2
2 changed files with 82 additions and 95 deletions

View File

@ -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) {

View File

@ -1,59 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:longClickable="true">
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/key_data"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="@dimen/list_padding">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/action_container"
android:orientation="vertical">
<TextView
android:id="@+id/key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/action_container"
android:clickable="true"
android:fontFamily="monospace"
android:longClickable="true"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"
android:typeface="monospace"
android:longClickable="true"
android:clickable="true"/>
android:typeface="monospace"/>
<TextView
android:id="@+id/key_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/key"
android:clickable="true"
android:longClickable="true"
android:maxLines="1"
android:textColor="?attr/color_text_secondary"
android:textSize="?attr/TextSizeInfo"
android:longClickable="true"
android:clickable="true"/>
android:textSize="?attr/TextSizeInfo"/>
</LinearLayout>
<TextView
android:id="@+id/key_trust"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/key"
android:textColor="?attr/color_text_secondary"
android:textSize="?attr/TextSizeInfo"
android:visibility="gone"
android:longClickable="true"/>
<LinearLayout
android:id="@+id/action_container"
android:layout_width="@dimen/key_action_width"
android:layout_height="48dp"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:layout_centerVertical="true">
android:orientation="vertical">
<ImageButton
android:id="@+id/button_remove"
android:layout_width="wrap_content"
@ -62,7 +55,8 @@
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/image_button_padding"
android:src="?attr/icon_remove"
android:visibility="gone" />
android:visibility="gone"/>
<ImageButton
android:id="@+id/button_enable_device"
android:layout_width="wrap_content"
@ -71,21 +65,21 @@
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/image_button_padding"
android:src="?attr/icon_enable_undecided_device"
android:visibility="gone" />
android:visibility="gone"/>
<ImageView
android:visibility="gone"
android:id="@+id/verified_fingerprint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_verified_fingerprint" />
android:src="@drawable/ic_verified_fingerprint"
android:visibility="gone"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/tgl_trust"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</layout>