show status icon etc in chip dropdown

This commit is contained in:
Dominik Schürmann
2018-07-03 20:08:19 +02:00
committed by Vincent Breitmoser
parent f8eb6275f5
commit 1c7a2b1db1
4 changed files with 86 additions and 26 deletions

View File

@@ -35,9 +35,6 @@ import android.view.ViewGroup;
import android.widget.ViewAnimator;
import com.pchmn.materialchips.ChipsInput.SimpleChipsListener;
import com.pchmn.materialchips.model.ChipInterface;
import com.pchmn.materialchips.simple.SimpleChip;
import com.pchmn.materialchips.simple.SimpleChipsInput;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.daos.KeyRepository;
@@ -50,13 +47,14 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
import org.sufficientlysecure.keychain.ui.widget.KeySpinner;
import org.sufficientlysecure.keychain.util.Passphrase;
import timber.log.Timber;
public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
KeyRepository keyRepository;
private KeySpinner mSignKeySpinner;
private SimpleChipsInput mEncryptKeyView;
private EncryptRecipientChipsInput mEncryptKeyView;
public static final String ARG_SINGATURE_KEY_ID = "signature_key_id";
public static final String ARG_ENCRYPTION_KEY_IDS = "encryption_key_ids";
@@ -103,16 +101,16 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
mSignKeySpinner.setShowNone(R.string.cert_none);
final ViewAnimator vEncryptionIcon = view.findViewById(R.id.result_encryption_icon);
mEncryptKeyView.addChipsListener(new SimpleChipsListener<SimpleChip>() {
mEncryptKeyView.addChipsListener(new SimpleChipsListener<EncryptRecipientChip>() {
@Override
public void onChipAdded(SimpleChip chipInterface, int newSize) {
public void onChipAdded(EncryptRecipientChip chipInterface, int newSize) {
if (vEncryptionIcon.getDisplayedChild() != 1) {
vEncryptionIcon.setDisplayedChild(1);
}
}
@Override
public void onChipRemoved(SimpleChip chipInterface, int newSize) {
public void onChipRemoved(EncryptRecipientChip chipInterface, int newSize) {
int child = newSize == 0 ? 0 : 1;
if (vEncryptionIcon.getDisplayedChild() != child) {
vEncryptionIcon.setDisplayedChild(child);
@@ -129,13 +127,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
EncryptModeViewModel viewModel = ViewModelProviders.of(this).get(EncryptModeViewModel.class);
viewModel.getSignKeyLiveData(requireContext()).observe(this, mSignKeySpinner::setData);
viewModel.getEncryptRecipientLiveData(requireContext()).observe(this, (keyUnifiedData) -> {
ArrayList<SimpleChip> simpleChips = new ArrayList<>();
for (EncryptRecipientChip chip : keyUnifiedData) {
simpleChips.add(new SimpleChip(chip.keyInfo.master_key_id(), chip.keyInfo.name(), chip.keyInfo.email(), chip.keyInfo.user_id_list()));
}
mEncryptKeyView.setData(simpleChips);
});
viewModel.getEncryptRecipientLiveData(requireContext()).observe(this, mEncryptKeyView::setData);
// preselect keys given, from state or arguments
if (savedInstanceState == null) {
@@ -196,12 +188,16 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
if (encryptionKeyIds != null) {
for (long preselectedId : encryptionKeyIds) {
UnifiedKeyInfo keyInfo = keyRepository.getUnifiedKeyInfo(preselectedId);
EncryptRecipientChip recipientChip = EncryptRecipientChipsInput.chipFromUnifiedKeyInfo(keyInfo);
// mEncryptKeyView.addChip(recipientChip);
// EncryptRecipientChip infooo =
// new EncryptRecipientChip(ring.getMasterKeyId(), ring.getPrimaryUserIdWithFallback(), "infooo", null);
// mEncryptKeyView.addChip(infooo);
if (keyInfo == null) {
Timber.e("key not found for encryption!");
Notify.create(getActivity(), getString(R.string.error_preselect_encrypt_key,
KeyFormattingUtils.beautifyKeyId(preselectedId)),
Style.ERROR).show();
} else {
mEncryptKeyView.addChip(EncryptRecipientChipsInput.chipFromUnifiedKeyInfo(keyInfo));
}
}
// This is to work-around a rendering bug in TokenCompleteTextView
mEncryptKeyView.requestFocus();
}
@@ -220,8 +216,8 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
@Override
public long[] getAsymmetricEncryptionKeyIds() {
List<Long> keyIds = new ArrayList<>();
for (ChipInterface chip : mEncryptKeyView.getSelectedChipList()) {
keyIds.add((long) chip.getId());
for (EncryptRecipientChip chip : mEncryptKeyView.getSelectedChipList()) {
keyIds.add(chip.keyInfo.master_key_id());
}
long[] keyIdsArr = new long[keyIds.size()];
@@ -236,8 +232,8 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
@Override
public String[] getAsymmetricEncryptionUserIds() {
List<String> userIds = new ArrayList<>();
for (ChipInterface chip : mEncryptKeyView.getSelectedChipList()) {
userIds.add(chip.getInfo());
for (EncryptRecipientChip chip : mEncryptKeyView.getSelectedChipList()) {
userIds.add(chip.keyInfo.user_id());
}
return userIds.toArray(new String[userIds.size()]);

View File

@@ -0,0 +1,63 @@
package org.sufficientlysecure.keychain.ui.adapter;
import java.util.List;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.pchmn.materialchips.ChipsInput;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.adapter.EncryptRecipientDropdownAdapter.ItemViewHolder;
import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput.EncryptRecipientChip;
import org.sufficientlysecure.keychain.ui.util.KeyInfoFormatter;
public class EncryptRecipientDropdownAdapter extends ChipsInput.ChipDropdownAdapter<EncryptRecipientChip, ItemViewHolder> {
private final LayoutInflater layoutInflater;
public EncryptRecipientDropdownAdapter(Context context, List<EncryptRecipientChip> keyInfoChips) {
super(keyInfoChips);
layoutInflater = LayoutInflater.from(context);
}
class ItemViewHolder extends RecyclerView.ViewHolder {
private final TextView vMainUserId;
private final TextView vMainUserIdRest;
private final TextView vCreationDate;
private final ImageView vStatusIcon;
ItemViewHolder(View view) {
super(view);
vMainUserId = itemView.findViewById(R.id.key_list_item_name);
vMainUserIdRest = itemView.findViewById(R.id.key_list_item_email);
vStatusIcon = itemView.findViewById(R.id.key_list_item_status_icon);
vCreationDate = itemView.findViewById(R.id.key_list_item_creation);
}
}
@NonNull
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = layoutInflater.inflate(R.layout.key_list_item, parent, false);
return new ItemViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
EncryptRecipientChip chip = getItem(position);
KeyInfoFormatter keyInfoFormatter = new KeyInfoFormatter(layoutInflater.getContext(), chip.keyInfo, null);
keyInfoFormatter.formatUserId(holder.vMainUserId, holder.vMainUserIdRest);
keyInfoFormatter.formatCreationDate(holder.vCreationDate);
keyInfoFormatter.formatStatusIcon(holder.vStatusIcon);
}
}

View File

@@ -9,6 +9,7 @@ import android.util.AttributeSet;
import com.pchmn.materialchips.ChipsInput;
import com.pchmn.materialchips.adapter.FilterableAdapter.FilterableItem;
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
import org.sufficientlysecure.keychain.ui.adapter.EncryptRecipientDropdownAdapter;
import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput.EncryptRecipientChip;
@@ -29,8 +30,8 @@ public class EncryptRecipientChipsInput extends ChipsInput<EncryptRecipientChip>
}
public void setData(List<EncryptRecipientChip> keyInfoChips) {
// SimpleChipDropdownAdapter chipDropdownAdapter = new SimpleChipDropdownAdapter(getContext(), simpleChips);
// setChipDropdownAdapter(chipDropdownAdapter);
EncryptRecipientDropdownAdapter chipDropdownAdapter = new EncryptRecipientDropdownAdapter(getContext(), keyInfoChips);
setChipDropdownAdapter(chipDropdownAdapter);
}
public static class EncryptRecipientChip implements FilterableItem {

View File

@@ -38,7 +38,7 @@
</ViewAnimator>
<com.pchmn.materialchips.simple.SimpleChipsInput
<org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput
android:id="@+id/recipient_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"