better chips for keys with emails only

This commit is contained in:
Dominik Schürmann
2018-07-03 21:21:07 +02:00
committed by Vincent Breitmoser
parent b350fd62f2
commit 2a7688e3c7

View File

@@ -13,7 +13,9 @@ import com.pchmn.materialchips.adapter.ChipsAdapter;
import com.pchmn.materialchips.simple.SimpleChip; import com.pchmn.materialchips.simple.SimpleChip;
import com.pchmn.materialchips.util.ViewUtil; import com.pchmn.materialchips.util.ViewUtil;
import com.pchmn.materialchips.views.DetailedChipView; import com.pchmn.materialchips.views.DetailedChipView;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.model.SubKey;
import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipAdapter.ItemViewHolder; import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipAdapter.ItemViewHolder;
import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput.EncryptRecipientChip; import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput.EncryptRecipientChip;
@@ -40,14 +42,14 @@ public class EncryptRecipientChipAdapter extends ChipsAdapter<EncryptRecipientCh
@Override @Override
public void onBindChipViewHolder(ItemViewHolder holder, int position) { public void onBindChipViewHolder(ItemViewHolder holder, int position) {
EncryptRecipientChip chip = getItem(position); EncryptRecipientChip chip = getItem(position);
holder.chipView.inflate(new SimpleChip(chip.keyInfo.name(), chip.keyInfo.email())); holder.chipView.inflate(simpleChipFromKeyInfo(chip.keyInfo));
handleClickOnEditText(holder.chipView, position); handleClickOnEditText(holder.chipView, position);
} }
@Override @Override
public DetailedChipView getDetailedChipView(EncryptRecipientChip chip) { public DetailedChipView getDetailedChipView(EncryptRecipientChip chip) {
return new DetailedChipView.Builder(context) return new DetailedChipView.Builder(context)
.chip(new SimpleChip(chip.keyInfo.name(), chip.keyInfo.email())) .chip(simpleChipFromKeyInfo(chip.keyInfo))
.backgroundColor(ContextCompat.getColorStateList(context, R.color.cardview_light_background)) .backgroundColor(ContextCompat.getColorStateList(context, R.color.cardview_light_background))
.build(); .build();
} }
@@ -60,4 +62,27 @@ public class EncryptRecipientChipAdapter extends ChipsAdapter<EncryptRecipientCh
chipView = (ChipView) view; chipView = (ChipView) view;
} }
} }
private SimpleChip simpleChipFromKeyInfo(SubKey.UnifiedKeyInfo keyInfo) {
String name;
String email;
if (keyInfo.name() == null) {
if (keyInfo.email() != null) {
name = keyInfo.email();
email = null;
} else {
name = context.getString(R.string.user_id_no_name);
email = null;
}
} else {
name = keyInfo.name();
if (keyInfo.email() != null) {
email = keyInfo.email();
} else {
email = null;
}
}
return new SimpleChip(name, email);
}
} }