use data binder for contact key item
This commit is contained in:
parent
1b8a437b1e
commit
2df1aaaed2
|
@ -1,5 +1,6 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
|
import android.databinding.DataBindingUtil;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -22,6 +23,7 @@ import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
||||||
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
|
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
|
||||||
|
import eu.siacs.conversations.databinding.ContactKeyBinding;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
import eu.siacs.conversations.utils.XmppUri;
|
import eu.siacs.conversations.utils.XmppUri;
|
||||||
|
@ -128,88 +130,79 @@ public abstract class OmemoActivity extends XmppActivity {
|
||||||
boolean undecidedNeedEnablement,
|
boolean undecidedNeedEnablement,
|
||||||
CompoundButton.OnCheckedChangeListener
|
CompoundButton.OnCheckedChangeListener
|
||||||
onCheckedChangeListener) {
|
onCheckedChangeListener) {
|
||||||
View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
|
ContactKeyBinding binding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.contact_key,keys,true);
|
||||||
TextView key = view.findViewById(R.id.key);
|
|
||||||
TextView keyType = view.findViewById(R.id.key_type);
|
|
||||||
ImageButton enableUndecided = view.findViewById(R.id.button_enable_device);
|
|
||||||
if (Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509) {
|
if (Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509) {
|
||||||
key.setOnClickListener(v -> showX509Certificate(account,fingerprint));
|
binding.key.setOnClickListener(v -> showX509Certificate(account,fingerprint));
|
||||||
keyType.setOnClickListener(v -> showX509Certificate(account,fingerprint));
|
binding.keyType.setOnClickListener(v -> showX509Certificate(account,fingerprint));
|
||||||
}
|
}
|
||||||
SwitchCompat trustToggle = view.findViewById(R.id.tgl_trust);
|
binding.tglTrust.setVisibility(View.VISIBLE);
|
||||||
ImageView verifiedFingerprintSymbol = view.findViewById(R.id.verified_fingerprint);
|
registerForContextMenu(binding.getRoot());
|
||||||
trustToggle.setVisibility(View.VISIBLE);
|
binding.getRoot().setTag(R.id.TAG_ACCOUNT,account);
|
||||||
registerForContextMenu(view);
|
binding.getRoot().setTag(R.id.TAG_FINGERPRINT,fingerprint);
|
||||||
view.setTag(R.id.TAG_ACCOUNT,account);
|
binding.getRoot().setTag(R.id.TAG_FINGERPRINT_STATUS,status);
|
||||||
view.setTag(R.id.TAG_FINGERPRINT,fingerprint);
|
|
||||||
view.setTag(R.id.TAG_FINGERPRINT_STATUS,status);
|
|
||||||
boolean x509 = Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509;
|
boolean x509 = Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509;
|
||||||
final View.OnClickListener toast;
|
final View.OnClickListener toast;
|
||||||
trustToggle.setChecked(status.isTrusted());
|
binding.tglTrust.setChecked(status.isTrusted());
|
||||||
|
|
||||||
if (status.isActive()){
|
if (status.isActive()){
|
||||||
key.setTextColor(getPrimaryTextColor());
|
binding.key.setTextColor(getPrimaryTextColor());
|
||||||
keyType.setTextColor(getSecondaryTextColor());
|
binding.keyType.setTextColor(getSecondaryTextColor());
|
||||||
if (status.isVerified()) {
|
if (status.isVerified()) {
|
||||||
verifiedFingerprintSymbol.setVisibility(View.VISIBLE);
|
binding.verifiedFingerprint.setVisibility(View.VISIBLE);
|
||||||
verifiedFingerprintSymbol.setAlpha(1.0f);
|
binding.verifiedFingerprint.setAlpha(1.0f);
|
||||||
trustToggle.setVisibility(View.GONE);
|
binding.tglTrust.setVisibility(View.GONE);
|
||||||
verifiedFingerprintSymbol.setOnClickListener(v -> replaceToast(getString(R.string.this_device_has_been_verified), false));
|
binding.verifiedFingerprint.setOnClickListener(v -> replaceToast(getString(R.string.this_device_has_been_verified), false));
|
||||||
toast = null;
|
toast = null;
|
||||||
} else {
|
} else {
|
||||||
verifiedFingerprintSymbol.setVisibility(View.GONE);
|
binding.verifiedFingerprint.setVisibility(View.GONE);
|
||||||
trustToggle.setVisibility(View.VISIBLE);
|
binding.tglTrust.setVisibility(View.VISIBLE);
|
||||||
trustToggle.setOnCheckedChangeListener(onCheckedChangeListener);
|
binding.tglTrust.setOnCheckedChangeListener(onCheckedChangeListener);
|
||||||
if (status.getTrust() == FingerprintStatus.Trust.UNDECIDED && undecidedNeedEnablement) {
|
if (status.getTrust() == FingerprintStatus.Trust.UNDECIDED && undecidedNeedEnablement) {
|
||||||
enableUndecided.setVisibility(View.VISIBLE);
|
binding.buttonEnableDevice.setVisibility(View.VISIBLE);
|
||||||
enableUndecided.setOnClickListener(v -> {
|
binding.buttonEnableDevice.setOnClickListener(v -> {
|
||||||
account.getAxolotlService().setFingerprintTrust(fingerprint,FingerprintStatus.createActive(false));
|
account.getAxolotlService().setFingerprintTrust(fingerprint,FingerprintStatus.createActive(false));
|
||||||
enableUndecided.setVisibility(View.GONE);
|
binding.buttonEnableDevice.setVisibility(View.GONE);
|
||||||
trustToggle.setVisibility(View.VISIBLE);
|
binding.tglTrust.setVisibility(View.VISIBLE);
|
||||||
});
|
});
|
||||||
trustToggle.setVisibility(View.GONE);
|
binding.tglTrust.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
trustToggle.setOnClickListener(null);
|
binding.tglTrust.setOnClickListener(null);
|
||||||
trustToggle.setEnabled(true);
|
binding.tglTrust.setEnabled(true);
|
||||||
}
|
}
|
||||||
toast = v -> hideToast();
|
toast = v -> hideToast();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
key.setTextColor(getTertiaryTextColor());
|
binding.key.setTextColor(getTertiaryTextColor());
|
||||||
keyType.setTextColor(getTertiaryTextColor());
|
binding.keyType.setTextColor(getTertiaryTextColor());
|
||||||
toast = v -> replaceToast(getString(R.string.this_device_is_no_longer_in_use), false);
|
toast = v -> replaceToast(getString(R.string.this_device_is_no_longer_in_use), false);
|
||||||
if (status.isVerified()) {
|
if (status.isVerified()) {
|
||||||
trustToggle.setVisibility(View.GONE);
|
binding.tglTrust.setVisibility(View.GONE);
|
||||||
verifiedFingerprintSymbol.setVisibility(View.VISIBLE);
|
binding.verifiedFingerprint.setVisibility(View.VISIBLE);
|
||||||
verifiedFingerprintSymbol.setAlpha(0.4368f);
|
binding.verifiedFingerprint.setAlpha(0.4368f);
|
||||||
verifiedFingerprintSymbol.setOnClickListener(toast);
|
binding.verifiedFingerprint.setOnClickListener(toast);
|
||||||
} else {
|
} else {
|
||||||
trustToggle.setVisibility(View.VISIBLE);
|
binding.tglTrust.setVisibility(View.VISIBLE);
|
||||||
verifiedFingerprintSymbol.setVisibility(View.GONE);
|
binding.verifiedFingerprint.setVisibility(View.GONE);
|
||||||
trustToggle.setOnClickListener(null);
|
binding.tglTrust.setEnabled(false);
|
||||||
trustToggle.setEnabled(false);
|
|
||||||
trustToggle.setOnClickListener(toast);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
view.setOnClickListener(toast);
|
binding.getRoot().setOnClickListener(toast);
|
||||||
key.setOnClickListener(toast);
|
binding.key.setOnClickListener(toast);
|
||||||
keyType.setOnClickListener(toast);
|
binding.keyType.setOnClickListener(toast);
|
||||||
if (showTag) {
|
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 {
|
} else {
|
||||||
keyType.setVisibility(View.GONE);
|
binding.keyType.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (highlight) {
|
if (highlight) {
|
||||||
keyType.setTextColor(ContextCompat.getColor(this, R.color.accent));
|
binding.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.setText(getString(x509 ? R.string.omemo_fingerprint_x509_selected_message : R.string.omemo_fingerprint_selected_message));
|
||||||
} else {
|
} 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)));
|
binding.key.setText(CryptoHelper.prettifyFingerprint(fingerprint.substring(2)));
|
||||||
|
|
||||||
keys.addView(view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPurgeKeyDialog(final Account account, final String fingerprint) {
|
public void showPurgeKeyDialog(final Account account, final String fingerprint) {
|
||||||
|
|
|
@ -1,59 +1,52 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:longClickable="true">
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/key_data"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:padding="@dimen/list_padding">
|
android:padding="@dimen/list_padding">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/key"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
android:layout_toLeftOf="@+id/action_container"
|
android:layout_toLeftOf="@+id/action_container"
|
||||||
android:fontFamily="monospace"
|
android:orientation="vertical">
|
||||||
android:textColor="?attr/color_text_primary"
|
|
||||||
android:textSize="?attr/TextSizeBody"
|
|
||||||
android:typeface="monospace"
|
|
||||||
android:longClickable="true"
|
|
||||||
android:clickable="true"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/key_type"
|
android:id="@+id/key"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_below="@+id/key"
|
android:clickable="true"
|
||||||
android:maxLines="1"
|
android:fontFamily="monospace"
|
||||||
android:textColor="?attr/color_text_secondary"
|
android:longClickable="true"
|
||||||
android:textSize="?attr/TextSizeInfo"
|
android:textColor="?attr/color_text_primary"
|
||||||
android:longClickable="true"
|
android:textSize="?attr/TextSizeBody"
|
||||||
android:clickable="true"/>
|
android:typeface="monospace"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/key_type"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="true"
|
||||||
|
android:longClickable="true"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="?attr/color_text_secondary"
|
||||||
|
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
|
<LinearLayout
|
||||||
android:id="@+id/action_container"
|
android:id="@+id/action_container"
|
||||||
android:layout_width="@dimen/key_action_width"
|
android:layout_width="@dimen/key_action_width"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_centerVertical="true">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_remove"
|
android:id="@+id/button_remove"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -62,7 +55,8 @@
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:padding="@dimen/image_button_padding"
|
android:padding="@dimen/image_button_padding"
|
||||||
android:src="?attr/icon_remove"
|
android:src="?attr/icon_remove"
|
||||||
android:visibility="gone" />
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_enable_device"
|
android:id="@+id/button_enable_device"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -71,21 +65,21 @@
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
android:padding="@dimen/image_button_padding"
|
android:padding="@dimen/image_button_padding"
|
||||||
android:src="?attr/icon_enable_undecided_device"
|
android:src="?attr/icon_enable_undecided_device"
|
||||||
android:visibility="gone" />
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:visibility="gone"
|
|
||||||
android:id="@+id/verified_fingerprint"
|
android:id="@+id/verified_fingerprint"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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.support.v7.widget.SwitchCompat
|
||||||
android:id="@+id/tgl_trust"
|
android:id="@+id/tgl_trust"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone" />
|
android:visibility="gone"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</RelativeLayout>
|
</layout>
|
Loading…
Reference in a new issue