mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-16 13:55:03 -05:00
Add subkey: at least one flag should be selected!
This commit is contained in:
parent
3e7ce0008f
commit
a5d34478df
@ -33,6 +33,7 @@ import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.DatePicker;
|
||||
@ -40,6 +41,7 @@ import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.spongycastle.bcpg.PublicKeyAlgorithmTags;
|
||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||
@ -167,60 +169,11 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
mKeySizeSpinner.setSelection(1); // Default to 4096 for the key length
|
||||
|
||||
|
||||
dialog.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface di, int id) {
|
||||
di.dismiss();
|
||||
Choice newKeyAlgorithmChoice = (Choice) mAlgorithmSpinner.getSelectedItem();
|
||||
int newKeySize = getProperKeyLength(newKeyAlgorithmChoice.getId(), getSelectedKeyLength());
|
||||
|
||||
int flags = 0;
|
||||
if (mFlagCertify.isChecked()) {
|
||||
flags |= KeyFlags.CERTIFY_OTHER;
|
||||
}
|
||||
if (mFlagSign.isChecked()) {
|
||||
flags |= KeyFlags.SIGN_DATA;
|
||||
}
|
||||
if (mFlagEncrypt.isChecked()) {
|
||||
flags |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
|
||||
}
|
||||
if (mFlagAuthenticate.isChecked()) {
|
||||
flags |= KeyFlags.AUTHENTICATION;
|
||||
}
|
||||
|
||||
long expiry;
|
||||
if (mNoExpiryCheckBox.isChecked()) {
|
||||
expiry = 0L;
|
||||
} else {
|
||||
Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault());
|
||||
//noinspection ResourceType
|
||||
selectedCal.set(mExpiryDatePicker.getYear(),
|
||||
mExpiryDatePicker.getMonth(), mExpiryDatePicker.getDayOfMonth());
|
||||
// date picker uses default time zone, we need to convert to UTC
|
||||
selectedCal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
expiry = selectedCal.getTime().getTime() / 1000;
|
||||
}
|
||||
|
||||
SaveKeyringParcel.SubkeyAdd newSubkey = new SaveKeyringParcel.SubkeyAdd(
|
||||
newKeyAlgorithmChoice.getId(),
|
||||
newKeySize,
|
||||
flags,
|
||||
expiry
|
||||
);
|
||||
mAlgorithmSelectedListener.onAlgorithmSelected(newSubkey);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
dialog.setCancelable(true);
|
||||
dialog.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface di, int id) {
|
||||
di.dismiss();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// onClickListener are set in onStart() to override default dismiss behaviour
|
||||
dialog.setPositiveButton(android.R.string.ok, null);
|
||||
dialog.setNegativeButton(android.R.string.cancel, null);
|
||||
|
||||
final AlertDialog alertDialog = dialog.show();
|
||||
|
||||
@ -268,6 +221,74 @@ public class AddSubkeyDialogFragment extends DialogFragment {
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point
|
||||
AlertDialog d = (AlertDialog) getDialog();
|
||||
if (d != null) {
|
||||
Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
|
||||
Button negativeButton = d.getButton(Dialog.BUTTON_NEGATIVE);
|
||||
positiveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!mFlagCertify.isChecked() && !mFlagSign.isChecked()
|
||||
&& !mFlagEncrypt.isChecked() && !mFlagAuthenticate.isChecked()) {
|
||||
Toast.makeText(getActivity(), R.string.edit_key_select_flag, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// dismiss only if at least one flag is selected
|
||||
dismiss();
|
||||
|
||||
Choice newKeyAlgorithmChoice = (Choice) mAlgorithmSpinner.getSelectedItem();
|
||||
int newKeySize = getProperKeyLength(newKeyAlgorithmChoice.getId(), getSelectedKeyLength());
|
||||
|
||||
int flags = 0;
|
||||
if (mFlagCertify.isChecked()) {
|
||||
flags |= KeyFlags.CERTIFY_OTHER;
|
||||
}
|
||||
if (mFlagSign.isChecked()) {
|
||||
flags |= KeyFlags.SIGN_DATA;
|
||||
}
|
||||
if (mFlagEncrypt.isChecked()) {
|
||||
flags |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
|
||||
}
|
||||
if (mFlagAuthenticate.isChecked()) {
|
||||
flags |= KeyFlags.AUTHENTICATION;
|
||||
}
|
||||
|
||||
long expiry;
|
||||
if (mNoExpiryCheckBox.isChecked()) {
|
||||
expiry = 0L;
|
||||
} else {
|
||||
Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault());
|
||||
//noinspection ResourceType
|
||||
selectedCal.set(mExpiryDatePicker.getYear(),
|
||||
mExpiryDatePicker.getMonth(), mExpiryDatePicker.getDayOfMonth());
|
||||
// date picker uses default time zone, we need to convert to UTC
|
||||
selectedCal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
expiry = selectedCal.getTime().getTime() / 1000;
|
||||
}
|
||||
|
||||
SaveKeyringParcel.SubkeyAdd newSubkey = new SaveKeyringParcel.SubkeyAdd(
|
||||
newKeyAlgorithmChoice.getId(),
|
||||
newKeySize,
|
||||
flags,
|
||||
expiry
|
||||
);
|
||||
mAlgorithmSelectedListener.onAlgorithmSelected(newSubkey);
|
||||
}
|
||||
});
|
||||
negativeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private int getSelectedKeyLength() {
|
||||
final String selectedItemString = (String) mKeySizeSpinner.getSelectedItem();
|
||||
final String customLengthString = getResources().getString(R.string.key_size_custom);
|
||||
|
@ -457,6 +457,7 @@
|
||||
<item>Revoke Subkey</item>
|
||||
</string-array>
|
||||
<string name="edit_key_new_subkey">new</string>
|
||||
<string name="edit_key_select_flag">Please select at least one flag!</string>
|
||||
|
||||
<!-- Create key -->
|
||||
<string name="create_key_upload">Upload key to keyserver</string>
|
||||
|
Loading…
Reference in New Issue
Block a user