Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import java.util.List;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.PorterDuff.Mode;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -16,14 +13,11 @@
import android.widget.BaseAdapter;
import android.widget.ImageView;

import androidx.annotation.AttrRes;
import androidx.annotation.DrawableRes;
import androidx.appcompat.widget.TooltipCompat;
import com.fsck.k9.activity.compose.RecipientAdapter;
import com.fsck.k9.ui.ContactBadge;
import com.fsck.k9.ui.R;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import com.fsck.k9.view.ThemeUtils;
import com.google.android.material.textview.MaterialTextView;


Expand All @@ -37,7 +31,6 @@ public class AlternateRecipientAdapter extends BaseAdapter {
private final AlternateRecipientListener listener;
private List<Recipient> recipients;
private Recipient currentRecipient;
private boolean showAdvancedInfo;


public AlternateRecipientAdapter(Context context, AlternateRecipientListener listener) {
Expand Down Expand Up @@ -171,69 +164,20 @@ public void onClick(View v) {
}

private void configureCryptoStatusView(RecipientTokenHolder holder, Recipient recipient) {
if (showAdvancedInfo) {
configureCryptoStatusViewAdvanced(holder, recipient);
} else {
bindCryptoSimple(holder, recipient);
}
}

private void configureCryptoStatusViewAdvanced(RecipientTokenHolder holder, Recipient recipient) {
switch (recipient.getCryptoStatus()) {
case AVAILABLE_TRUSTED: {
setCryptoStatusView(holder, R.drawable.status_lock_dots_3, R.attr.openpgp_green);
break;
}
case AVAILABLE_UNTRUSTED: {
setCryptoStatusView(holder, R.drawable.status_lock_dots_2, R.attr.openpgp_orange);
break;
}
case UNAVAILABLE: {
setCryptoStatusView(holder, R.drawable.status_lock_disabled_dots_1, R.attr.openpgp_red);
break;
}
case UNDEFINED: {
holder.itemCryptoStatus.setVisibility(View.GONE);
break;
}
}
}

private void setCryptoStatusView(RecipientTokenHolder holder, @DrawableRes int cryptoStatusRes,
@AttrRes int cryptoStatusColorAttr) {
Resources resources = context.getResources();

Drawable drawable = resources.getDrawable(cryptoStatusRes);
// noinspection ConstantConditions, we know the resource exists!
drawable.mutate();

int cryptoStatusColor = ThemeUtils.getStyledColor(context, cryptoStatusColorAttr);
drawable.setColorFilter(cryptoStatusColor, Mode.SRC_ATOP);

holder.itemCryptoStatusIcon.setImageDrawable(drawable);
holder.itemCryptoStatus.setVisibility(View.VISIBLE);
}

private void bindCryptoSimple(RecipientTokenHolder holder, Recipient recipient) {
holder.itemCryptoStatus.setVisibility(View.GONE);
switch (recipient.getCryptoStatus()) {
case AVAILABLE_TRUSTED:
case AVAILABLE_UNTRUSTED: {
holder.itemCryptoStatusSimple.setVisibility(View.VISIBLE);
holder.itemCryptoStatus.setVisibility(View.VISIBLE);
break;
}
case UNAVAILABLE:
case UNDEFINED: {
holder.itemCryptoStatusSimple.setVisibility(View.GONE);
holder.itemCryptoStatus.setVisibility(View.GONE);
break;
}
}
}

public void setShowAdvancedInfo(boolean showAdvancedInfo) {
this.showAdvancedInfo = showAdvancedInfo;
}

private static class RecipientTokenHolder {
public final View layoutHeader, layoutItem;
public final MaterialTextView headerName;
Expand All @@ -243,9 +187,7 @@ private static class RecipientTokenHolder {
public final View copyEmailAddress;
public final MaterialTextView itemAddress;
public final MaterialTextView itemAddressLabel;
public final View itemCryptoStatus;
public final ImageView itemCryptoStatusIcon;
public final ImageView itemCryptoStatusSimple;
public final ImageView itemCryptoStatus;


public RecipientTokenHolder(View view) {
Expand All @@ -261,10 +203,8 @@ public RecipientTokenHolder(View view) {
TooltipCompat.setTooltipText(copyEmailAddress, copyEmailAddress.getContext().getString(R.string.copy_action));
itemAddress = view.findViewById(R.id.alternate_address);
itemAddressLabel = view.findViewById(R.id.alternate_address_label);
itemCryptoStatus = view.findViewById(R.id.alternate_crypto_status);
itemCryptoStatusIcon = view.findViewById(R.id.alternate_crypto_status_icon);

itemCryptoStatusSimple = view.findViewById(R.id.alternate_crypto_status_simple);
itemCryptoStatus = view.findViewById(R.id.alternate_crypto_status);
}

public void setShowAsHeader(boolean isHeader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.regex.Pattern;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
Expand All @@ -17,21 +16,17 @@
import android.widget.Filterable;
import android.widget.ImageView;

import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import com.fsck.k9.activity.misc.ContactPicture;
import com.fsck.k9.ui.R;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import com.fsck.k9.view.RecipientSelectView.RecipientCryptoStatus;
import com.fsck.k9.view.ThemeUtils;
import com.google.android.material.textview.MaterialTextView;


public class RecipientAdapter extends BaseAdapter implements Filterable {
private final Context context;
private List<Recipient> recipients;
private String highlight;
private boolean showAdvancedInfo;


public RecipientAdapter(Context context) {
Expand Down Expand Up @@ -94,59 +89,19 @@ private void bindView(View view, Recipient recipient) {

setContactPhotoOrPlaceholder(context, holder.photo, recipient);

if (showAdvancedInfo) {
bindCryptoAdvanced(recipient, holder);
} else {
bindCryptoSimple(recipient, holder);
}
}

private void bindCryptoAdvanced(Recipient recipient, RecipientTokenHolder holder) {
holder.cryptoStatusSimple.setVisibility(View.GONE);

Integer cryptoStatusRes = null, cryptoStatusColor = null;
RecipientCryptoStatus cryptoStatus = recipient.getCryptoStatus();
switch (cryptoStatus) {
case AVAILABLE_TRUSTED: {
cryptoStatusRes = R.drawable.status_lock_dots_3;
cryptoStatusColor = ThemeUtils.getStyledColor(context, R.attr.openpgp_green);
break;
}
case AVAILABLE_UNTRUSTED: {
cryptoStatusRes = R.drawable.status_lock_dots_2;
cryptoStatusColor = ThemeUtils.getStyledColor(context, R.attr.openpgp_orange);
break;
}
case UNAVAILABLE: {
cryptoStatusRes = R.drawable.status_lock_disabled_dots_1;
cryptoStatusColor = ThemeUtils.getStyledColor(context, R.attr.openpgp_red);
break;
}
}

if (cryptoStatusRes != null) {
Drawable drawable = ContextCompat.getDrawable(context, cryptoStatusRes);
DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), cryptoStatusColor);
holder.cryptoStatusIcon.setImageDrawable(drawable);
holder.cryptoStatus.setVisibility(View.VISIBLE);
} else {
holder.cryptoStatus.setVisibility(View.GONE);
}
bindCryptoStatus(recipient, holder);
}

private void bindCryptoSimple(Recipient recipient, RecipientTokenHolder holder) {
holder.cryptoStatus.setVisibility(View.GONE);

private void bindCryptoStatus(Recipient recipient, RecipientTokenHolder holder) {
RecipientCryptoStatus cryptoStatus = recipient.getCryptoStatus();
switch (cryptoStatus) {
case AVAILABLE_TRUSTED:
case AVAILABLE_UNTRUSTED: {
holder.cryptoStatusSimple.setVisibility(View.VISIBLE);
holder.cryptoStatus.setVisibility(View.VISIBLE);
break;
}
case UNAVAILABLE: {
holder.cryptoStatusSimple.setVisibility(View.GONE);
holder.cryptoStatus.setVisibility(View.GONE);
break;
}
}
Expand Down Expand Up @@ -179,27 +134,19 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
};
}

public void setShowAdvancedInfo(boolean showAdvancedInfo) {
this.showAdvancedInfo = showAdvancedInfo;
}


private static class RecipientTokenHolder {
public final MaterialTextView name;
public final MaterialTextView email;
final ImageView photo;
final View cryptoStatus;
final ImageView cryptoStatusIcon;
final ImageView cryptoStatusSimple;
final ImageView cryptoStatus;


RecipientTokenHolder(View view) {
name = view.findViewById(R.id.text1);
email = view.findViewById(R.id.text2);
photo = view.findViewById(R.id.contact_photo);
cryptoStatus = view.findViewById(R.id.contact_crypto_status);
cryptoStatusIcon = view.findViewById(R.id.contact_crypto_status_icon);
cryptoStatusSimple = view.findViewById(R.id.contact_crypto_status_icon_simple);
cryptoStatus = view.findViewById(R.id.contact_crypto_status_icon);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ class RecipientMvpView(private val activity: MessageCompose) : View.OnFocusChang
}

fun setCryptoProvider(openPgpProvider: String?) {
// TODO move "show advanced" into settings, or somewhere?
toView.setCryptoProvider(openPgpProvider, false)
ccView.setCryptoProvider(openPgpProvider, false)
bccView.setCryptoProvider(openPgpProvider, false)
toView.setCryptoProvider(openPgpProvider)
ccView.setCryptoProvider(openPgpProvider)
bccView.setCryptoProvider(openPgpProvider)
}

fun requestFocusOnToField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
private RecipientAdapter adapter;
@Nullable
private String cryptoProvider;
private boolean showAdvancedInfo;
private boolean showCryptoEnabled;
@Nullable
private LoaderManager loaderManager;
Expand Down Expand Up @@ -164,12 +163,8 @@ private void bindObjectView(Recipient recipient, View view) {

boolean isAvailable = recipient.cryptoStatus == RecipientCryptoStatus.AVAILABLE_TRUSTED ||
recipient.cryptoStatus == RecipientCryptoStatus.AVAILABLE_UNTRUSTED;
if (!showAdvancedInfo) {
holder.showSimpleCryptoState(isAvailable, showCryptoEnabled);
} else {
boolean isVerified = recipient.cryptoStatus == RecipientCryptoStatus.AVAILABLE_TRUSTED;
holder.showAdvancedCryptoState(isAvailable, isVerified);
}

holder.showCryptoState(isAvailable, showCryptoEnabled);
}

@Override
Expand Down Expand Up @@ -276,11 +271,8 @@ protected void performFiltering(@NonNull CharSequence text, int keyCode) {
loaderManager.restartLoader(LOADER_ID_FILTERING, args, this);
}

public void setCryptoProvider(@Nullable String cryptoProvider, boolean showAdvancedInfo) {
public void setCryptoProvider(@Nullable String cryptoProvider) {
this.cryptoProvider = cryptoProvider;
this.showAdvancedInfo = showAdvancedInfo;
adapter.setShowAdvancedInfo(showAdvancedInfo);
alternatesAdapter.setShowAdvancedInfo(showAdvancedInfo);
}

public void setShowCryptoEnabled(boolean showCryptoEnabled) {
Expand Down Expand Up @@ -595,54 +587,30 @@ public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end,
private static class RecipientTokenViewHolder {
final MaterialTextView vName;
final CircleImageView vContactPhoto;
final View cryptoStatusRed;
final View cryptoStatusOrange;
final View cryptoStatusGreen;
final View cryptoStatusSimple;
final View cryptoStatusSimpleEnabled;
final View cryptoStatusSimpleError;
final View cryptoStatus;
final View cryptoStatusEnabled;
final View cryptoStatusError;


RecipientTokenViewHolder(View view) {
vName = view.findViewById(android.R.id.text1);
vContactPhoto = view.findViewById(R.id.contact_photo);
cryptoStatusRed = view.findViewById(R.id.contact_crypto_status_red);
cryptoStatusOrange = view.findViewById(R.id.contact_crypto_status_orange);
cryptoStatusGreen = view.findViewById(R.id.contact_crypto_status_green);

cryptoStatusSimple = view.findViewById(R.id.contact_crypto_status_icon_simple);
cryptoStatusSimpleEnabled = view.findViewById(R.id.contact_crypto_status_icon_simple_enabled);
cryptoStatusSimpleError = view.findViewById(R.id.contact_crypto_status_icon_simple_error);
}

void showSimpleCryptoState(boolean isAvailable, boolean isShowEnabled) {
cryptoStatusRed.setVisibility(View.GONE);
cryptoStatusOrange.setVisibility(View.GONE);
cryptoStatusGreen.setVisibility(View.GONE);

cryptoStatusSimple.setVisibility(!isShowEnabled && isAvailable ? View.VISIBLE : View.GONE);
cryptoStatusSimpleEnabled.setVisibility(isShowEnabled && isAvailable ? View.VISIBLE : View.GONE);
cryptoStatusSimpleError.setVisibility(isShowEnabled && !isAvailable ? View.VISIBLE : View.GONE);
cryptoStatus = view.findViewById(R.id.contact_crypto_status_icon);
cryptoStatusEnabled = view.findViewById(R.id.contact_crypto_status_icon_enabled);
cryptoStatusError = view.findViewById(R.id.contact_crypto_status_icon_error);
}

void showAdvancedCryptoState(boolean isAvailable, boolean isVerified) {
cryptoStatusRed.setVisibility(!isAvailable ? View.VISIBLE : View.GONE);
cryptoStatusOrange.setVisibility(isAvailable && !isVerified ? View.VISIBLE : View.GONE);
cryptoStatusGreen.setVisibility(isAvailable && isVerified ? View.VISIBLE : View.GONE);

cryptoStatusSimple.setVisibility(View.GONE);
cryptoStatusSimpleEnabled.setVisibility(View.GONE);
cryptoStatusSimpleError.setVisibility(View.GONE);
void showCryptoState(boolean isAvailable, boolean isShowEnabled) {
cryptoStatus.setVisibility(!isShowEnabled && isAvailable ? View.VISIBLE : View.GONE);
cryptoStatusEnabled.setVisibility(isShowEnabled && isAvailable ? View.VISIBLE : View.GONE);
cryptoStatusError.setVisibility(isShowEnabled && !isAvailable ? View.VISIBLE : View.GONE);
}

void hideCryptoState() {
cryptoStatusRed.setVisibility(View.GONE);
cryptoStatusOrange.setVisibility(View.GONE);
cryptoStatusGreen.setVisibility(View.GONE);

cryptoStatusSimple.setVisibility(View.GONE);
cryptoStatusSimpleEnabled.setVisibility(View.GONE);
cryptoStatusSimpleError.setVisibility(View.GONE);
cryptoStatus.setVisibility(View.GONE);
cryptoStatusEnabled.setVisibility(View.GONE);
cryptoStatusError.setVisibility(View.GONE);
}
}

Expand Down
Loading
Loading