Fix flags UI in add subkey dialog

This commit is contained in:
Dominik Schürmann 2014-08-16 13:42:55 +02:00
parent c1f9c5e4b5
commit ccf58a92fa
2 changed files with 44 additions and 5 deletions

View File

@ -106,7 +106,7 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd
holder.vKeyId.setText(R.string.edit_key_new_subkey); holder.vKeyId.setText(R.string.edit_key_new_subkey);
holder.vKeyDetails.setText(algorithmStr); holder.vKeyDetails.setText(algorithmStr);
if (holder.mModel.mExpiry != null) { if (holder.mModel.mExpiry != 0L) {
Date expiryDate = new Date(holder.mModel.mExpiry * 1000); Date expiryDate = new Date(holder.mModel.mExpiry * 1000);
holder.vKeyExpiry.setText(getContext().getString(R.string.label_expiry) + ": " holder.vKeyExpiry.setText(getContext().getString(R.string.label_expiry) + ": "

View File

@ -76,6 +76,8 @@ public class AddSubkeyDialogFragment extends DialogFragment {
private CheckBox mFlagEncrypt; private CheckBox mFlagEncrypt;
private CheckBox mFlagAuthenticate; private CheckBox mFlagAuthenticate;
private boolean mWillBeMasterKey;
public void setOnAlgorithmSelectedListener(OnAlgorithmSelectedListener listener) { public void setOnAlgorithmSelectedListener(OnAlgorithmSelectedListener listener) {
mAlgorithmSelectedListener = listener; mAlgorithmSelectedListener = listener;
} }
@ -96,7 +98,7 @@ public class AddSubkeyDialogFragment extends DialogFragment {
final FragmentActivity context = getActivity(); final FragmentActivity context = getActivity();
final LayoutInflater mInflater; final LayoutInflater mInflater;
final boolean willBeMasterKey = getArguments().getBoolean(ARG_WILL_BE_MASTER_KEY); mWillBeMasterKey = getArguments().getBoolean(ARG_WILL_BE_MASTER_KEY);
mInflater = context.getLayoutInflater(); mInflater = context.getLayoutInflater();
CustomAlertDialogBuilder dialog = new CustomAlertDialogBuilder(context); CustomAlertDialogBuilder dialog = new CustomAlertDialogBuilder(context);
@ -136,7 +138,7 @@ public class AddSubkeyDialogFragment extends DialogFragment {
ArrayList<Choice> choices = new ArrayList<Choice>(); ArrayList<Choice> choices = new ArrayList<Choice>();
choices.add(new Choice(PublicKeyAlgorithmTags.DSA, getResources().getString( choices.add(new Choice(PublicKeyAlgorithmTags.DSA, getResources().getString(
R.string.dsa))); R.string.dsa)));
if (!willBeMasterKey) { if (!mWillBeMasterKey) {
choices.add(new Choice(PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT, getResources().getString( choices.add(new Choice(PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT, getResources().getString(
R.string.elgamal))); R.string.elgamal)));
} }
@ -246,7 +248,7 @@ public class AddSubkeyDialogFragment extends DialogFragment {
mAlgorithmSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { mAlgorithmSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
setKeyLengthSpinnerValuesForAlgorithm(((Choice) parent.getSelectedItem()).getId()); updateUiForAlgorithm(((Choice) parent.getSelectedItem()).getId());
setCustomKeyVisibility(); setCustomKeyVisibility();
setOkButtonAvailability(alertDialog); 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 ArrayAdapter<CharSequence> keySizeAdapter = (ArrayAdapter<CharSequence>) mKeySizeSpinner.getAdapter();
final Object selectedItem = mKeySizeSpinner.getSelectedItem(); final Object selectedItem = mKeySizeSpinner.getSelectedItem();
keySizeAdapter.clear(); keySizeAdapter.clear();
@ -356,14 +358,51 @@ public class AddSubkeyDialogFragment extends DialogFragment {
case PublicKeyAlgorithmTags.RSA_GENERAL: case PublicKeyAlgorithmTags.RSA_GENERAL:
replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values); replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values);
mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_rsa)); 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; break;
case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT: case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT:
replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values); replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values);
mCustomKeyInfoTextView.setText(""); // ElGamal does not support custom key length 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; break;
case PublicKeyAlgorithmTags.DSA: case PublicKeyAlgorithmTags.DSA:
replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values); replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values);
mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_dsa)); 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; break;
} }
keySizeAdapter.notifyDataSetChanged(); keySizeAdapter.notifyDataSetChanged();