show status icon etc in chip dropdown
This commit is contained in:
committed by
Vincent Breitmoser
parent
f8eb6275f5
commit
1c7a2b1db1
@@ -35,9 +35,6 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ViewAnimator;
|
import android.widget.ViewAnimator;
|
||||||
|
|
||||||
import com.pchmn.materialchips.ChipsInput.SimpleChipsListener;
|
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.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.daos.KeyRepository;
|
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.util.Notify.Style;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.KeySpinner;
|
import org.sufficientlysecure.keychain.ui.widget.KeySpinner;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
||||||
public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
||||||
KeyRepository keyRepository;
|
KeyRepository keyRepository;
|
||||||
|
|
||||||
private KeySpinner mSignKeySpinner;
|
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_SINGATURE_KEY_ID = "signature_key_id";
|
||||||
public static final String ARG_ENCRYPTION_KEY_IDS = "encryption_key_ids";
|
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);
|
mSignKeySpinner.setShowNone(R.string.cert_none);
|
||||||
|
|
||||||
final ViewAnimator vEncryptionIcon = view.findViewById(R.id.result_encryption_icon);
|
final ViewAnimator vEncryptionIcon = view.findViewById(R.id.result_encryption_icon);
|
||||||
mEncryptKeyView.addChipsListener(new SimpleChipsListener<SimpleChip>() {
|
mEncryptKeyView.addChipsListener(new SimpleChipsListener<EncryptRecipientChip>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChipAdded(SimpleChip chipInterface, int newSize) {
|
public void onChipAdded(EncryptRecipientChip chipInterface, int newSize) {
|
||||||
if (vEncryptionIcon.getDisplayedChild() != 1) {
|
if (vEncryptionIcon.getDisplayedChild() != 1) {
|
||||||
vEncryptionIcon.setDisplayedChild(1);
|
vEncryptionIcon.setDisplayedChild(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChipRemoved(SimpleChip chipInterface, int newSize) {
|
public void onChipRemoved(EncryptRecipientChip chipInterface, int newSize) {
|
||||||
int child = newSize == 0 ? 0 : 1;
|
int child = newSize == 0 ? 0 : 1;
|
||||||
if (vEncryptionIcon.getDisplayedChild() != child) {
|
if (vEncryptionIcon.getDisplayedChild() != child) {
|
||||||
vEncryptionIcon.setDisplayedChild(child);
|
vEncryptionIcon.setDisplayedChild(child);
|
||||||
@@ -129,13 +127,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
|||||||
|
|
||||||
EncryptModeViewModel viewModel = ViewModelProviders.of(this).get(EncryptModeViewModel.class);
|
EncryptModeViewModel viewModel = ViewModelProviders.of(this).get(EncryptModeViewModel.class);
|
||||||
viewModel.getSignKeyLiveData(requireContext()).observe(this, mSignKeySpinner::setData);
|
viewModel.getSignKeyLiveData(requireContext()).observe(this, mSignKeySpinner::setData);
|
||||||
viewModel.getEncryptRecipientLiveData(requireContext()).observe(this, (keyUnifiedData) -> {
|
viewModel.getEncryptRecipientLiveData(requireContext()).observe(this, mEncryptKeyView::setData);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
// preselect keys given, from state or arguments
|
// preselect keys given, from state or arguments
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@@ -196,12 +188,16 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
|||||||
if (encryptionKeyIds != null) {
|
if (encryptionKeyIds != null) {
|
||||||
for (long preselectedId : encryptionKeyIds) {
|
for (long preselectedId : encryptionKeyIds) {
|
||||||
UnifiedKeyInfo keyInfo = keyRepository.getUnifiedKeyInfo(preselectedId);
|
UnifiedKeyInfo keyInfo = keyRepository.getUnifiedKeyInfo(preselectedId);
|
||||||
EncryptRecipientChip recipientChip = EncryptRecipientChipsInput.chipFromUnifiedKeyInfo(keyInfo);
|
if (keyInfo == null) {
|
||||||
// mEncryptKeyView.addChip(recipientChip);
|
Timber.e("key not found for encryption!");
|
||||||
// EncryptRecipientChip infooo =
|
Notify.create(getActivity(), getString(R.string.error_preselect_encrypt_key,
|
||||||
// new EncryptRecipientChip(ring.getMasterKeyId(), ring.getPrimaryUserIdWithFallback(), "infooo", null);
|
KeyFormattingUtils.beautifyKeyId(preselectedId)),
|
||||||
// mEncryptKeyView.addChip(infooo);
|
Style.ERROR).show();
|
||||||
|
} else {
|
||||||
|
mEncryptKeyView.addChip(EncryptRecipientChipsInput.chipFromUnifiedKeyInfo(keyInfo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is to work-around a rendering bug in TokenCompleteTextView
|
// This is to work-around a rendering bug in TokenCompleteTextView
|
||||||
mEncryptKeyView.requestFocus();
|
mEncryptKeyView.requestFocus();
|
||||||
}
|
}
|
||||||
@@ -220,8 +216,8 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
|||||||
@Override
|
@Override
|
||||||
public long[] getAsymmetricEncryptionKeyIds() {
|
public long[] getAsymmetricEncryptionKeyIds() {
|
||||||
List<Long> keyIds = new ArrayList<>();
|
List<Long> keyIds = new ArrayList<>();
|
||||||
for (ChipInterface chip : mEncryptKeyView.getSelectedChipList()) {
|
for (EncryptRecipientChip chip : mEncryptKeyView.getSelectedChipList()) {
|
||||||
keyIds.add((long) chip.getId());
|
keyIds.add(chip.keyInfo.master_key_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
long[] keyIdsArr = new long[keyIds.size()];
|
long[] keyIdsArr = new long[keyIds.size()];
|
||||||
@@ -236,8 +232,8 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
|||||||
@Override
|
@Override
|
||||||
public String[] getAsymmetricEncryptionUserIds() {
|
public String[] getAsymmetricEncryptionUserIds() {
|
||||||
List<String> userIds = new ArrayList<>();
|
List<String> userIds = new ArrayList<>();
|
||||||
for (ChipInterface chip : mEncryptKeyView.getSelectedChipList()) {
|
for (EncryptRecipientChip chip : mEncryptKeyView.getSelectedChipList()) {
|
||||||
userIds.add(chip.getInfo());
|
userIds.add(chip.keyInfo.user_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
return userIds.toArray(new String[userIds.size()]);
|
return userIds.toArray(new String[userIds.size()]);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import android.util.AttributeSet;
|
|||||||
import com.pchmn.materialchips.ChipsInput;
|
import com.pchmn.materialchips.ChipsInput;
|
||||||
import com.pchmn.materialchips.adapter.FilterableAdapter.FilterableItem;
|
import com.pchmn.materialchips.adapter.FilterableAdapter.FilterableItem;
|
||||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||||
|
import org.sufficientlysecure.keychain.ui.adapter.EncryptRecipientDropdownAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput.EncryptRecipientChip;
|
import org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput.EncryptRecipientChip;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,8 +30,8 @@ public class EncryptRecipientChipsInput extends ChipsInput<EncryptRecipientChip>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setData(List<EncryptRecipientChip> keyInfoChips) {
|
public void setData(List<EncryptRecipientChip> keyInfoChips) {
|
||||||
// SimpleChipDropdownAdapter chipDropdownAdapter = new SimpleChipDropdownAdapter(getContext(), simpleChips);
|
EncryptRecipientDropdownAdapter chipDropdownAdapter = new EncryptRecipientDropdownAdapter(getContext(), keyInfoChips);
|
||||||
// setChipDropdownAdapter(chipDropdownAdapter);
|
setChipDropdownAdapter(chipDropdownAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EncryptRecipientChip implements FilterableItem {
|
public static class EncryptRecipientChip implements FilterableItem {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
</ViewAnimator>
|
</ViewAnimator>
|
||||||
|
|
||||||
<com.pchmn.materialchips.simple.SimpleChipsInput
|
<org.sufficientlysecure.keychain.ui.chips.EncryptRecipientChipsInput
|
||||||
android:id="@+id/recipient_list"
|
android:id="@+id/recipient_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user