change key activities to cards

This commit is contained in:
Daniel Gultsch 2018-02-17 20:41:46 +01:00
parent 58ec5ced8a
commit 30776a86c4
3 changed files with 208 additions and 208 deletions

View File

@ -1,6 +1,7 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.content.Intent; import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.util.Log; import android.util.Log;
@ -29,6 +30,8 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
import eu.siacs.conversations.databinding.ActivityTrustKeysBinding;
import eu.siacs.conversations.databinding.KeysCardBinding;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
@ -38,19 +41,13 @@ import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
import static android.databinding.DataBindingUtil.inflate;
public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdated { public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdated {
private List<Jid> contactJids; private List<Jid> contactJids;
private Account mAccount; private Account mAccount;
private Conversation mConversation; private Conversation mConversation;
private TextView keyErrorMessage;
private LinearLayout keyErrorMessageCard;
private TextView ownKeysTitle;
private LinearLayout ownKeys;
private LinearLayout ownKeysCard;
private LinearLayout foreignKeys;
private Button mSaveButton;
private Button mCancelButton;
private AtomicBoolean mUseCameraHintShown = new AtomicBoolean(false); private AtomicBoolean mUseCameraHintShown = new AtomicBoolean(false);
@ -75,6 +72,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
} }
}; };
private Toast mUseCameraHintToast = null; private Toast mUseCameraHintToast = null;
private ActivityTrustKeysBinding binding;
@Override @Override
protected void refreshUiReal() { protected void refreshUiReal() {
@ -85,7 +83,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trust_keys); this.binding = DataBindingUtil.setContentView(this,R.layout.activity_trust_keys);
this.contactJids = new ArrayList<>(); this.contactJids = new ArrayList<>();
for(String jid : getIntent().getStringArrayExtra("contacts")) { for(String jid : getIntent().getStringArrayExtra("contacts")) {
try { try {
@ -95,16 +93,8 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
} }
} }
keyErrorMessageCard = (LinearLayout) findViewById(R.id.key_error_message_card); binding.cancelButton.setOnClickListener(mCancelButtonListener);
keyErrorMessage = (TextView) findViewById(R.id.key_error_message); binding.saveButton.setOnClickListener(mSaveButtonListener);
ownKeysTitle = (TextView) findViewById(R.id.own_keys_title);
ownKeys = (LinearLayout) findViewById(R.id.own_keys_details);
ownKeysCard = (LinearLayout) findViewById(R.id.own_keys_card);
foreignKeys = (LinearLayout) findViewById(R.id.foreign_keys);
mCancelButton = (Button) findViewById(R.id.cancel_button);
mCancelButton.setOnClickListener(mCancelButtonListener);
mSaveButton = (Button) findViewById(R.id.save_button);
mSaveButton.setOnClickListener(mSaveButtonListener);
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
@ -185,13 +175,13 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
private void populateView() { private void populateView() {
setTitle(getString(R.string.trust_omemo_fingerprints)); setTitle(getString(R.string.trust_omemo_fingerprints));
ownKeys.removeAllViews(); binding.ownKeysDetails.removeAllViews();
foreignKeys.removeAllViews(); binding.foreignKeys.removeAllViews();
boolean hasOwnKeys = false; boolean hasOwnKeys = false;
boolean hasForeignKeys = false; boolean hasForeignKeys = false;
for(final String fingerprint : ownKeysToTrust.keySet()) { for(final String fingerprint : ownKeysToTrust.keySet()) {
hasOwnKeys = true; hasOwnKeys = true;
addFingerprintRowWithListeners(ownKeys, mAccount, fingerprint, false, addFingerprintRowWithListeners(binding.ownKeysDetails, mAccount, fingerprint, false,
FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)), false, false, FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)), false, false,
new CompoundButton.OnCheckedChangeListener() { new CompoundButton.OnCheckedChangeListener() {
@Override @Override
@ -206,46 +196,36 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
synchronized (this.foreignKeysToTrust) { synchronized (this.foreignKeysToTrust) {
for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) { for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
hasForeignKeys = true; hasForeignKeys = true;
final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.keys_card, foreignKeys, false); KeysCardBinding keysCardBinding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.keys_card, binding.foreignKeys,false);
//final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.keys_card, foreignKeys, false);
final Jid jid = entry.getKey(); final Jid jid = entry.getKey();
final TextView header = (TextView) layout.findViewById(R.id.foreign_keys_title); keysCardBinding.foreignKeysTitle.setText(jid.toString());
final LinearLayout keysContainer = (LinearLayout) layout.findViewById(R.id.foreign_keys_details); keysCardBinding.foreignKeysTitle.setOnClickListener(v -> switchToContactDetails(mAccount.getRoster().getContact(jid)));
final TextView informNoKeys = (TextView) layout.findViewById(R.id.no_keys_to_accept);
header.setText(jid.toString());
header.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
switchToContactDetails(mAccount.getRoster().getContact(jid));
}
});
final Map<String, Boolean> fingerprints = entry.getValue(); final Map<String, Boolean> fingerprints = entry.getValue();
for (final String fingerprint : fingerprints.keySet()) { for (final String fingerprint : fingerprints.keySet()) {
addFingerprintRowWithListeners(keysContainer, mAccount, fingerprint, false, addFingerprintRowWithListeners(keysCardBinding.foreignKeysDetails, mAccount, fingerprint, false,
FingerprintStatus.createActive(fingerprints.get(fingerprint)), false, false, FingerprintStatus.createActive(fingerprints.get(fingerprint)), false, false,
new CompoundButton.OnCheckedChangeListener() { (buttonView, isChecked) -> {
@Override fingerprints.put(fingerprint, isChecked);
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { lockOrUnlockAsNeeded();
fingerprints.put(fingerprint, isChecked);
lockOrUnlockAsNeeded();
}
} }
); );
} }
if (fingerprints.size() == 0) { if (fingerprints.size() == 0) {
informNoKeys.setVisibility(View.VISIBLE); keysCardBinding.noKeysToAccept.setVisibility(View.VISIBLE);
if (hasNoOtherTrustedKeys(jid)) { if (hasNoOtherTrustedKeys(jid)) {
if (!mAccount.getRoster().getContact(jid).mutualPresenceSubscription()) { if (!mAccount.getRoster().getContact(jid).mutualPresenceSubscription()) {
informNoKeys.setText(R.string.error_no_keys_to_trust_presence); keysCardBinding.noKeysToAccept.setText(R.string.error_no_keys_to_trust_presence);
} else { } else {
informNoKeys.setText(R.string.error_no_keys_to_trust_server_error); keysCardBinding.noKeysToAccept.setText(R.string.error_no_keys_to_trust_server_error);
} }
} else { } else {
informNoKeys.setText(getString(R.string.no_keys_just_confirm, mAccount.getRoster().getContact(jid).getDisplayName())); keysCardBinding.noKeysToAccept.setText(getString(R.string.no_keys_just_confirm, mAccount.getRoster().getContact(jid).getDisplayName()));
} }
} else { } else {
informNoKeys.setVisibility(View.GONE); keysCardBinding.noKeysToAccept.setVisibility(View.GONE);
} }
foreignKeys.addView(layout); binding.foreignKeys.addView(keysCardBinding.foreignKeysCard);
} }
} }
@ -253,29 +233,29 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
showCameraToast(); showCameraToast();
} }
ownKeysTitle.setText(mAccount.getJid().toBareJid().toString()); binding.ownKeysTitle.setText(mAccount.getJid().toBareJid().toString());
ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE); binding.ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE);
foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE); binding.foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE);
if(hasPendingKeyFetches()) { if(hasPendingKeyFetches()) {
setFetching(); setFetching();
lock(); lock();
} else { } else {
if (!hasForeignKeys && hasNoOtherTrustedKeys()) { if (!hasForeignKeys && hasNoOtherTrustedKeys()) {
keyErrorMessageCard.setVisibility(View.VISIBLE); binding.keyErrorMessageCard.setVisibility(View.VISIBLE);
if (lastFetchReport == AxolotlService.FetchStatus.ERROR if (lastFetchReport == AxolotlService.FetchStatus.ERROR
|| mAccount.getAxolotlService().fetchMapHasErrors(contactJids)) { || mAccount.getAxolotlService().fetchMapHasErrors(contactJids)) {
if (anyWithoutMutualPresenceSubscription(contactJids)) { if (anyWithoutMutualPresenceSubscription(contactJids)) {
keyErrorMessage.setText(R.string.error_no_keys_to_trust_presence); binding.keyErrorMessage.setText(R.string.error_no_keys_to_trust_presence);
} else { } else {
keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error); binding.keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error);
} }
} else { } else {
keyErrorMessage.setText(R.string.error_no_keys_to_trust); binding.keyErrorMessage.setText(R.string.error_no_keys_to_trust);
} }
ownKeys.removeAllViews(); binding.ownKeysDetails.removeAllViews();
ownKeysCard.setVisibility(View.GONE); binding.ownKeysCard.setVisibility(View.GONE);
foreignKeys.removeAllViews(); binding.foreignKeys.removeAllViews();
foreignKeys.setVisibility(View.GONE); binding.foreignKeys.setVisibility(View.GONE);
} }
lockOrUnlockAsNeeded(); lockOrUnlockAsNeeded();
setDone(); setDone();
@ -441,13 +421,13 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
} }
private void unlock() { private void unlock() {
mSaveButton.setEnabled(true); binding.saveButton.setEnabled(true);
mSaveButton.setTextColor(getPrimaryTextColor()); binding.saveButton.setTextColor(getPrimaryTextColor());
} }
private void lock() { private void lock() {
mSaveButton.setEnabled(false); binding.saveButton.setEnabled(false);
mSaveButton.setTextColor(getSecondaryTextColor()); binding.saveButton.setTextColor(getSecondaryTextColor());
} }
private void lockOrUnlockAsNeeded() { private void lockOrUnlockAsNeeded() {
@ -465,10 +445,10 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat
} }
private void setDone() { private void setDone() {
mSaveButton.setText(getString(R.string.done)); binding.saveButton.setText(getString(R.string.done));
} }
private void setFetching() { private void setFetching() {
mSaveButton.setText(getString(R.string.fetching_keys)); binding.saveButton.setText(getString(R.string.fetching_keys));
} }
} }

View File

@ -1,129 +1,141 @@
<?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">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_secondary" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button_bar"
android:layout_alignParentTop="true" >
<LinearLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_secondary">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:layout_above="@+id/button_bar"
android:layout_alignParentTop="true">
<LinearLayout <LinearLayout
android:id="@+id/key_error_message_card" android:layout_width="match_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:orientation="vertical">
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding"
android:visibility="gone">
<TextView <android.support.v7.widget.CardView
android:id="@+id/key_error_message_title" android:id="@+id/key_error_message_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold"
android:text="@string/error_trustkeys_title"/>
<TextView
android:id="@+id/key_error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"
android:padding="8dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/own_keys_card"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding"
android:visibility="gone">
<TextView
android:id="@+id/own_keys_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold"/>
<LinearLayout
android:id="@+id/own_keys_details"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal" android:layout_marginBottom="@dimen/activity_vertical_margin"
android:showDividers="middle" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:orientation="vertical"> android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<TextView
android:id="@+id/key_error_message_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/error_trustkeys_title"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold"/>
<TextView
android:id="@+id/key_error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/own_keys_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<TextView
android:id="@+id/own_keys_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold"/>
<LinearLayout
android:id="@+id/own_keys_details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal"
android:orientation="vertical"
android:showDividers="middle">
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:id="@+id/foreign_keys"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView>
<LinearLayout <LinearLayout
android:id="@+id/foreign_keys" android:id="@+id/button_bar"
android:layout_width="fill_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true">
<Button
android:id="@+id/cancel_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" android:layout_weight="1"
android:orientation="vertical"> android:text="@string/cancel"
android:textColor="?attr/color_text_primary"/>
</LinearLayout> <View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginBottom="7dp"
android:layout_marginTop="7dp"
android:background="?attr/divider"/>
<Button
android:id="@+id/save_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="true"
android:text="@string/done"
android:textColor="?attr/color_text_secondary"/>
</LinearLayout> </LinearLayout>
</ScrollView> </RelativeLayout>
<LinearLayout </layout>
android:id="@+id/button_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="@+id/cancel_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"
android:textColor="?attr/color_text_primary" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginBottom="7dp"
android:layout_marginTop="7dp"
android:background="?attr/divider" />
<Button
android:id="@+id/save_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="true"
android:textColor="?attr/color_text_secondary"
android:text="@string/done"/>
</LinearLayout>
</RelativeLayout>

View File

@ -1,39 +1,47 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/foreign_keys_card" <layout xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<TextView <android.support.v7.widget.CardView
android:id="@+id/foreign_keys_title" android:id="@+id/foreign_keys_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold"/>
<LinearLayout
android:id="@+id/foreign_keys_details"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal" android:layout_marginBottom="@dimen/activity_vertical_margin"
android:orientation="vertical" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:showDividers="middle"> android:layout_marginRight="@dimen/activity_horizontal_margin"
</LinearLayout> android:layout_marginTop="@dimen/activity_vertical_margin">
<TextView <LinearLayout
android:layout_marginTop="8dp" android:layout_width="match_parent"
android:id="@+id/no_keys_to_accept" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="wrap_content" android:padding="@dimen/infocard_padding">
android:textColor="?attr/color_text_primary"
android:text="@string/no_keys_just_confirm" <TextView
android:textSize="?attr/TextSizeBody"/> android:id="@+id/foreign_keys_title"
</LinearLayout> android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeHeadline"
android:textStyle="bold"/>
<LinearLayout
android:id="@+id/foreign_keys_details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="?android:dividerHorizontal"
android:orientation="vertical"
android:showDividers="middle">
</LinearLayout>
<TextView
android:id="@+id/no_keys_to_accept"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/no_keys_just_confirm"
android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</layout>