mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-05 08:45:08 -05:00
Fix flags UI in add subkey dialog
This commit is contained in:
parent
c1f9c5e4b5
commit
ccf58a92fa
@ -106,7 +106,7 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd
|
||||
holder.vKeyId.setText(R.string.edit_key_new_subkey);
|
||||
holder.vKeyDetails.setText(algorithmStr);
|
||||
|
||||
if (holder.mModel.mExpiry != null) {
|
||||
if (holder.mModel.mExpiry != 0L) {
|
||||
Date expiryDate = new Date(holder.mModel.mExpiry * 1000);
|
||||
|
||||
holder.vKeyExpiry.setText(getContext().getString(R.string.label_expiry) + ": "
|
||||
|
@ -76,6 +76,8 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
private CheckBox mFlagEncrypt;
|
||||
private CheckBox mFlagAuthenticate;
|
||||
|
||||
private boolean mWillBeMasterKey;
|
||||
|
||||
public void setOnAlgorithmSelectedListener(OnAlgorithmSelectedListener listener) {
|
||||
mAlgorithmSelectedListener = listener;
|
||||
}
|
||||
@ -96,7 +98,7 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
final FragmentActivity context = getActivity();
|
||||
final LayoutInflater mInflater;
|
||||
|
||||
final boolean willBeMasterKey = getArguments().getBoolean(ARG_WILL_BE_MASTER_KEY);
|
||||
mWillBeMasterKey = getArguments().getBoolean(ARG_WILL_BE_MASTER_KEY);
|
||||
mInflater = context.getLayoutInflater();
|
||||
|
||||
CustomAlertDialogBuilder dialog = new CustomAlertDialogBuilder(context);
|
||||
@ -136,7 +138,7 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
ArrayList<Choice> choices = new ArrayList<Choice>();
|
||||
choices.add(new Choice(PublicKeyAlgorithmTags.DSA, getResources().getString(
|
||||
R.string.dsa)));
|
||||
if (!willBeMasterKey) {
|
||||
if (!mWillBeMasterKey) {
|
||||
choices.add(new Choice(PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT, getResources().getString(
|
||||
R.string.elgamal)));
|
||||
}
|
||||
@ -246,7 +248,7 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
mAlgorithmSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
setKeyLengthSpinnerValuesForAlgorithm(((Choice) parent.getSelectedItem()).getId());
|
||||
updateUiForAlgorithm(((Choice) parent.getSelectedItem()).getId());
|
||||
|
||||
setCustomKeyVisibility();
|
||||
setOkButtonAvailability(alertDialog);
|
||||
@ -348,7 +350,7 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void setKeyLengthSpinnerValuesForAlgorithm(int algorithmId) {
|
||||
private void updateUiForAlgorithm(int algorithmId) {
|
||||
final ArrayAdapter<CharSequence> keySizeAdapter = (ArrayAdapter<CharSequence>) mKeySizeSpinner.getAdapter();
|
||||
final Object selectedItem = mKeySizeSpinner.getSelectedItem();
|
||||
keySizeAdapter.clear();
|
||||
@ -356,14 +358,51 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
case PublicKeyAlgorithmTags.RSA_GENERAL:
|
||||
replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values);
|
||||
mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_rsa));
|
||||
// allowed flags:
|
||||
mFlagSign.setEnabled(true);
|
||||
mFlagEncrypt.setEnabled(true);
|
||||
mFlagAuthenticate.setEnabled(true);
|
||||
|
||||
if (mWillBeMasterKey) {
|
||||
mFlagCertify.setEnabled(true);
|
||||
|
||||
mFlagCertify.setChecked(true);
|
||||
mFlagSign.setChecked(false);
|
||||
mFlagEncrypt.setChecked(false);
|
||||
} else {
|
||||
mFlagCertify.setEnabled(false);
|
||||
|
||||
mFlagCertify.setChecked(false);
|
||||
mFlagSign.setChecked(true);
|
||||
mFlagEncrypt.setChecked(true);
|
||||
}
|
||||
mFlagAuthenticate.setChecked(false);
|
||||
break;
|
||||
case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT:
|
||||
replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values);
|
||||
mCustomKeyInfoTextView.setText(""); // ElGamal does not support custom key length
|
||||
// allowed flags:
|
||||
mFlagCertify.setChecked(false);
|
||||
mFlagCertify.setEnabled(false);
|
||||
mFlagSign.setChecked(false);
|
||||
mFlagSign.setEnabled(false);
|
||||
mFlagEncrypt.setChecked(true);
|
||||
mFlagEncrypt.setEnabled(true);
|
||||
mFlagAuthenticate.setChecked(false);
|
||||
mFlagAuthenticate.setEnabled(false);
|
||||
break;
|
||||
case PublicKeyAlgorithmTags.DSA:
|
||||
replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values);
|
||||
mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_dsa));
|
||||
// allowed flags:
|
||||
mFlagCertify.setChecked(false);
|
||||
mFlagCertify.setEnabled(false);
|
||||
mFlagSign.setChecked(true);
|
||||
mFlagSign.setEnabled(true);
|
||||
mFlagEncrypt.setChecked(false);
|
||||
mFlagEncrypt.setEnabled(false);
|
||||
mFlagAuthenticate.setChecked(false);
|
||||
mFlagAuthenticate.setEnabled(false);
|
||||
break;
|
||||
}
|
||||
keySizeAdapter.notifyDataSetChanged();
|
||||
|
Loading…
Reference in New Issue
Block a user