mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
Work on edit
This commit is contained in:
parent
8cbdf7b1c5
commit
55f067b063
@ -55,10 +55,10 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
// performance gain for using Parcelable here would probably be negligible,
|
||||
// use Serializable instead.
|
||||
public static class SubkeyAdd implements Serializable {
|
||||
public final int mAlgorithm;
|
||||
public final int mKeysize;
|
||||
public final int mFlags;
|
||||
public final Long mExpiry;
|
||||
public int mAlgorithm;
|
||||
public int mKeysize;
|
||||
public int mFlags;
|
||||
public Long mExpiry;
|
||||
public SubkeyAdd(int algorithm, int keysize, int flags, Long expiry) {
|
||||
mAlgorithm = algorithm;
|
||||
mKeysize = keysize;
|
||||
@ -68,9 +68,9 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
}
|
||||
|
||||
public static class SubkeyChange implements Serializable {
|
||||
public final long mKeyId;
|
||||
public final Integer mFlags;
|
||||
public final Long mExpiry;
|
||||
public long mKeyId;
|
||||
public Integer mFlags;
|
||||
public Long mExpiry;
|
||||
public SubkeyChange(long keyId, Integer flags, Long expiry) {
|
||||
mKeyId = keyId;
|
||||
mFlags = flags;
|
||||
|
@ -37,6 +37,7 @@ import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||
@ -50,6 +51,7 @@ import org.sufficientlysecure.keychain.service.OperationResults;
|
||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAddedAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment;
|
||||
@ -67,17 +69,22 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
private ListView mUserIdsList;
|
||||
private ListView mSubkeysList;
|
||||
private ListView mUserIdsAddedList;
|
||||
private ListView mKeysAddedList;
|
||||
private ListView mSubkeysAddedList;
|
||||
private View mChangePassphrase;
|
||||
private View mAddUserId;
|
||||
private View mAddKey;
|
||||
private View mAddSubkey;
|
||||
|
||||
private static final int LOADER_ID_USER_IDS = 0;
|
||||
private static final int LOADER_ID_SUBKEYS = 1;
|
||||
|
||||
// cursor adapter
|
||||
private UserIdsAdapter mUserIdsAdapter;
|
||||
private SubkeysAdapter mSubkeysAdapter;
|
||||
|
||||
// array adapter
|
||||
private UserIdsAddedAdapter mUserIdsAddedAdapter;
|
||||
private SubkeysAddedAdapter mSubkeysAddedAdapter;
|
||||
|
||||
private ArrayList<UserIdsAddedAdapter.UserIdModel> mUserIdsAddedData;
|
||||
|
||||
private Uri mDataUri;
|
||||
@ -106,10 +113,10 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
mUserIdsList = (ListView) view.findViewById(R.id.edit_key_user_ids);
|
||||
mSubkeysList = (ListView) view.findViewById(R.id.edit_key_keys);
|
||||
mUserIdsAddedList = (ListView) view.findViewById(R.id.edit_key_user_ids_added);
|
||||
mKeysAddedList = (ListView) view.findViewById(R.id.edit_key_keys_added);
|
||||
mSubkeysAddedList = (ListView) view.findViewById(R.id.edit_key_keys_added);
|
||||
mChangePassphrase = view.findViewById(R.id.edit_key_action_change_passphrase);
|
||||
mAddUserId = view.findViewById(R.id.edit_key_action_add_user_id);
|
||||
mAddKey = view.findViewById(R.id.edit_key_action_add_key);
|
||||
mAddSubkey = view.findViewById(R.id.edit_key_action_add_key);
|
||||
|
||||
return root;
|
||||
}
|
||||
@ -180,6 +187,13 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
}
|
||||
});
|
||||
|
||||
mAddSubkey.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
addSubkey();
|
||||
}
|
||||
});
|
||||
|
||||
mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0, mSaveKeyringParcel);
|
||||
mUserIdsList.setAdapter(mUserIdsAdapter);
|
||||
|
||||
@ -199,6 +213,9 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
mSubkeysAdapter = new SubkeysAdapter(getActivity(), null, 0);
|
||||
mSubkeysList.setAdapter(mSubkeysAdapter);
|
||||
|
||||
mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mSaveKeyringParcel.addSubKeys);
|
||||
mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter);
|
||||
|
||||
// Prepare the loaders. Either re-connect with an existing ones,
|
||||
// or start new ones.
|
||||
getLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
|
||||
@ -327,6 +344,11 @@ public class EditKeyFragment extends LoaderFragment implements
|
||||
mUserIdsAddedAdapter.add(new UserIdsAddedAdapter.UserIdModel());
|
||||
}
|
||||
|
||||
private void addSubkey() {
|
||||
// default values
|
||||
mSubkeysAddedAdapter.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.SIGN_DATA, null));
|
||||
}
|
||||
|
||||
private void save() {
|
||||
String passphrase = PassphraseCacheService.getCachedPassphrase(getActivity(),
|
||||
mSaveKeyringParcel.mMasterKeyId);
|
||||
|
@ -107,7 +107,6 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
|
||||
TextView vAddress = (TextView) view.findViewById(R.id.address);
|
||||
TextView vComment = (TextView) view.findViewById(R.id.comment);
|
||||
ImageView vVerified = (ImageView) view.findViewById(R.id.certified);
|
||||
ImageView vHasChanges = (ImageView) view.findViewById(R.id.has_changes);
|
||||
ImageView vEditImage = (ImageView) view.findViewById(R.id.edit_image);
|
||||
|
||||
String userId = cursor.getString(INDEX_USER_ID);
|
||||
@ -135,27 +134,23 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
|
||||
|
||||
// for edit key
|
||||
if (mSaveKeyringParcel != null) {
|
||||
boolean changeUserId = (mSaveKeyringParcel.changePrimaryUserId != null
|
||||
boolean changeAnyPrimaryUserId = (mSaveKeyringParcel.changePrimaryUserId != null);
|
||||
boolean changeThisPrimaryUserId = (mSaveKeyringParcel.changePrimaryUserId != null
|
||||
&& mSaveKeyringParcel.changePrimaryUserId.equals(userId));
|
||||
boolean revoke = (mSaveKeyringParcel.revokeUserIds.contains(userId));
|
||||
boolean revokeThisUserId = (mSaveKeyringParcel.revokeUserIds.contains(userId));
|
||||
|
||||
if (changeUserId) {
|
||||
isPrimary = !isPrimary;
|
||||
if (changeAnyPrimaryUserId) {
|
||||
// change all user ids, only this one should be primary
|
||||
isPrimary = changeThisPrimaryUserId;
|
||||
}
|
||||
if (revoke) {
|
||||
if (revokeThisUserId) {
|
||||
if (!isRevoked) {
|
||||
isRevoked = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changeUserId || revoke) {
|
||||
vHasChanges.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
vHasChanges.setVisibility(View.GONE);
|
||||
}
|
||||
vEditImage.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
vHasChanges.setVisibility(View.GONE);
|
||||
vEditImage.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@ -166,11 +161,14 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
|
||||
// disable and strike through text for revoked user ids
|
||||
vName.setEnabled(false);
|
||||
vAddress.setEnabled(false);
|
||||
vComment.setEnabled(false);
|
||||
vName.setText(OtherHelper.strikeOutText(vName.getText()));
|
||||
vAddress.setText(OtherHelper.strikeOutText(vAddress.getText()));
|
||||
vComment.setText(OtherHelper.strikeOutText(vComment.getText()));
|
||||
} else {
|
||||
vName.setEnabled(true);
|
||||
vAddress.setEnabled(true);
|
||||
vComment.setEnabled(true);
|
||||
|
||||
// verified: has been verified
|
||||
// isPrimary: show small star icon for primary user ids
|
||||
|
@ -106,14 +106,14 @@ public class UserIdsAddedAdapter extends ArrayAdapter<UserIdsAddedAdapter.UserId
|
||||
if (convertView == null) {
|
||||
// Not recycled, inflate a new view
|
||||
convertView = mInflater.inflate(R.layout.edit_key_user_id_added_item, null);
|
||||
final ViewHolder viewHolder = new ViewHolder();
|
||||
viewHolder.vAddress = (AutoCompleteTextView) convertView.findViewById(R.id.user_id_added_item_address);
|
||||
viewHolder.vName = (AutoCompleteTextView) convertView.findViewById(R.id.user_id_added_item_name);
|
||||
viewHolder.vComment = (EditText) convertView.findViewById(R.id.user_id_added_item_comment);
|
||||
viewHolder.vDelete = (ImageButton) convertView.findViewById(R.id.user_id_added_item_delete);
|
||||
convertView.setTag(viewHolder);
|
||||
final ViewHolder holder = new ViewHolder();
|
||||
holder.vAddress = (AutoCompleteTextView) convertView.findViewById(R.id.user_id_added_item_address);
|
||||
holder.vName = (AutoCompleteTextView) convertView.findViewById(R.id.user_id_added_item_name);
|
||||
holder.vComment = (EditText) convertView.findViewById(R.id.user_id_added_item_comment);
|
||||
holder.vDelete = (ImageButton) convertView.findViewById(R.id.user_id_added_item_delete);
|
||||
convertView.setTag(holder);
|
||||
|
||||
viewHolder.vAddress.addTextChangedListener(new TextWatcher() {
|
||||
holder.vAddress.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
@ -125,26 +125,26 @@ public class UserIdsAddedAdapter extends ArrayAdapter<UserIdsAddedAdapter.UserId
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// update referenced item in view holder
|
||||
viewHolder.mModel.address = s.toString();
|
||||
holder.mModel.address = s.toString();
|
||||
|
||||
// show icon on valid email addresses
|
||||
if (viewHolder.mModel.address.length() > 0) {
|
||||
Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(viewHolder.mModel.address);
|
||||
if (holder.mModel.address.length() > 0) {
|
||||
Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(holder.mModel.address);
|
||||
if (emailMatcher.matches()) {
|
||||
viewHolder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||
holder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||
R.drawable.uid_mail_ok, 0);
|
||||
} else {
|
||||
viewHolder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||
holder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||
R.drawable.uid_mail_bad, 0);
|
||||
}
|
||||
} else {
|
||||
// remove drawable if email is empty
|
||||
viewHolder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
holder.vAddress.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
viewHolder.vName.addTextChangedListener(new TextWatcher() {
|
||||
holder.vName.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
@ -156,11 +156,11 @@ public class UserIdsAddedAdapter extends ArrayAdapter<UserIdsAddedAdapter.UserId
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// update referenced item in view holder
|
||||
viewHolder.mModel.name = s.toString();
|
||||
holder.mModel.name = s.toString();
|
||||
}
|
||||
});
|
||||
|
||||
viewHolder.vComment.addTextChangedListener(new TextWatcher() {
|
||||
holder.vComment.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
@ -172,15 +172,15 @@ public class UserIdsAddedAdapter extends ArrayAdapter<UserIdsAddedAdapter.UserId
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// update referenced item in view holder
|
||||
viewHolder.mModel.comment = s.toString();
|
||||
holder.mModel.comment = s.toString();
|
||||
}
|
||||
});
|
||||
|
||||
viewHolder.vDelete.setOnClickListener(new View.OnClickListener() {
|
||||
holder.vDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// remove reference model item from adapter (data and notify about change)
|
||||
UserIdsAddedAdapter.this.remove(viewHolder.mModel);
|
||||
UserIdsAddedAdapter.this.remove(holder.mModel);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -51,8 +51,6 @@ public class CreateKeyDialogFragment extends DialogFragment {
|
||||
|
||||
private static final String ARG_EDITOR_CHILD_COUNT = "child_count";
|
||||
|
||||
private int mNewKeySize;
|
||||
private Choice mNewKeyAlgorithmChoice;
|
||||
private OnAlgorithmSelectedListener mAlgorithmSelectedListener;
|
||||
private Spinner mAlgorithmSpinner;
|
||||
private Spinner mKeySizeSpinner;
|
||||
@ -131,9 +129,9 @@ public class CreateKeyDialogFragment extends DialogFragment {
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface di, int id) {
|
||||
di.dismiss();
|
||||
mNewKeyAlgorithmChoice = (Choice) mAlgorithmSpinner.getSelectedItem();
|
||||
mNewKeySize = getProperKeyLength(mNewKeyAlgorithmChoice.getId(), getSelectedKeyLength());
|
||||
mAlgorithmSelectedListener.onAlgorithmSelected(mNewKeyAlgorithmChoice, mNewKeySize);
|
||||
Choice newKeyAlgorithmChoice = (Choice) mAlgorithmSpinner.getSelectedItem();
|
||||
int newKeySize = getProperKeyLength(newKeyAlgorithmChoice.getId(), getSelectedKeyLength());
|
||||
mAlgorithmSelectedListener.onAlgorithmSelected(newKeyAlgorithmChoice, newKeySize);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -7,7 +7,6 @@
|
||||
android:singleLine="true">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/has_changes"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:minWidth="10dp"
|
||||
|
@ -6,13 +6,6 @@
|
||||
android:orientation="horizontal"
|
||||
android:singleLine="true">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/has_changes"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:minWidth="10dp"
|
||||
android:background="@color/result_green" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkBox"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -222,7 +222,6 @@
|
||||
<string name="keys_exported">Successfully exported %d keys.</string>
|
||||
<string name="no_keys_exported">No keys exported.</string>
|
||||
<string name="key_creation_el_gamal_info">Note: only subkeys support ElGamal.</string>
|
||||
<string name="key_creation_weak_rsa_info">Note: generating RSA key with length 1024-bit and less is considered unsafe and it\'s disabled for generating new keys.</string>
|
||||
<string name="key_not_found">Couldn\'t find key %08X.</string>
|
||||
|
||||
<plurals name="bad_keys_encountered">
|
||||
@ -626,8 +625,8 @@
|
||||
<!-- modifySecretKeyRing -->
|
||||
<string name="msg_mr">Modifying keyring %s</string>
|
||||
<string name="msg_mf_error_encode">Encoding exception!</string>
|
||||
<string name="msg_mf_error_fingerprint">Actual key fingerprint does not match expected!</string>
|
||||
<string name="msg_mf_error_keyid">No keyid. This is a programming error, please file a bug report!</string>
|
||||
<string name="msg_mf_error_fingerprint">Actual key fingerprint does not match the expected one!</string>
|
||||
<string name="msg_mf_error_keyid">No key ID. This is an internal error, please file a bug report!</string>
|
||||
<string name="msg_mf_error_integrity">Internal error, integrity check failed!</string>
|
||||
<string name="msg_mf_error_revoked_primary">Revoked user ids cannot be primary!</string>
|
||||
<string name="msg_mf_error_pgp">PGP internal exception!</string>
|
||||
@ -636,7 +635,7 @@
|
||||
<string name="msg_mf_subkey_change">Modifying subkey %s</string>
|
||||
<string name="msg_mf_subkey_missing">Tried to operate on missing subkey %s!</string>
|
||||
<string name="msg_mf_subkey_new">Generating new %1$s bit %2$s subkey</string>
|
||||
<string name="msg_mf_subkey_new_id">New subkey id: %s</string>
|
||||
<string name="msg_mf_subkey_new_id">New subkey ID: %s</string>
|
||||
<string name="msg_mf_subkey_past_expiry">Expiry date cannot be in the past!</string>
|
||||
<string name="msg_mf_subkey_revoke">Revoking subkey %s</string>
|
||||
<string name="msg_mf_success">Keyring successfully modified</string>
|
||||
|
Loading…
Reference in New Issue
Block a user