Better handling of user id revocation in UI code

This commit is contained in:
Dominik Schürmann 2014-08-05 17:59:05 +02:00
parent 160e6972d8
commit d377d1f23d
4 changed files with 75 additions and 19 deletions

View File

@ -318,6 +318,8 @@ public class EditKeyFragment extends LoaderFragment implements
private void editUserId(final int position) {
final String userId = mUserIdsAdapter.getUserId(position);
final boolean isRevoked = mUserIdsAdapter.getIsRevoked(position);
final boolean isRevokedPending = mUserIdsAdapter.getIsRevokedPending(position);
Handler returnHandler = new Handler() {
@Override
@ -351,8 +353,7 @@ public class EditKeyFragment extends LoaderFragment implements
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
public void run() {
EditUserIdDialogFragment dialogFragment =
EditUserIdDialogFragment.newInstance(messenger);
EditUserIdDialogFragment.newInstance(messenger, isRevoked, isRevokedPending);
dialogFragment.show(getActivity().getSupportFragmentManager(), "editUserIdDialog");
}
});

View File

@ -252,6 +252,26 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
return mCursor.getString(INDEX_USER_ID);
}
public boolean getIsRevoked(int position) {
mCursor.moveToPosition(position);
return mCursor.getInt(INDEX_IS_REVOKED) > 0;
}
public boolean getIsRevokedPending(int position) {
mCursor.moveToPosition(position);
String userId = mCursor.getString(INDEX_USER_ID);
boolean isRevokedPending = false;
if (mSaveKeyringParcel != null) {
if (mSaveKeyringParcel.mRevokeUserIds.contains(userId)) {
isRevokedPending = true;
}
}
return isRevokedPending;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = mInflater.inflate(R.layout.view_key_user_id_item, null);

View File

@ -29,9 +29,14 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log;
import java.util.Arrays;
public class EditUserIdDialogFragment extends DialogFragment {
private static final String ARG_MESSENGER = "messenger";
private static final String ARG_IS_REVOKED = "is_revoked";
private static final String ARG_IS_REVOKED_PENDING = "is_revoked_pending";
public static final int MESSAGE_CHANGE_PRIMARY_USER_ID = 1;
public static final int MESSAGE_REVOKE = 2;
@ -40,10 +45,13 @@ public class EditUserIdDialogFragment extends DialogFragment {
/**
* Creates new instance of this dialog fragment
*/
public static EditUserIdDialogFragment newInstance(Messenger messenger) {
public static EditUserIdDialogFragment newInstance(Messenger messenger, boolean isRevoked,
boolean isRevokedPending) {
EditUserIdDialogFragment frag = new EditUserIdDialogFragment();
Bundle args = new Bundle();
args.putParcelable(ARG_MESSENGER, messenger);
args.putBoolean(ARG_IS_REVOKED, isRevoked);
args.putBoolean(ARG_IS_REVOKED_PENDING, isRevokedPending);
frag.setArguments(args);
@ -56,13 +64,33 @@ public class EditUserIdDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
boolean isRevoked = getArguments().getBoolean(ARG_IS_REVOKED);
boolean isRevokedPending = getArguments().getBoolean(ARG_IS_REVOKED_PENDING);
CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(getActivity());
builder.setTitle(R.string.edit_key_edit_user_id_title);
if (isRevokedPending) {
CharSequence[] array = getResources().getStringArray(R.array.edit_key_edit_user_id_revert_revocation);
builder.setItems(array, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
sendMessageToHandler(MESSAGE_REVOKE, null);
break;
default:
break;
}
}
});
} else if (isRevoked) {
builder.setMessage(R.string.edit_key_edit_user_id_revoked);
} else {
CharSequence[] array = getResources().getStringArray(R.array.edit_key_edit_user_id);
builder.setTitle(R.string.edit_key_edit_user_id_title);
builder.setItems(array, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
@ -77,6 +105,8 @@ public class EditUserIdDialogFragment extends DialogFragment {
}
}
});
}
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {

View File

@ -437,12 +437,17 @@
<item>Change to Primary Identity</item>
<item>Revoke Identity</item>
</string-array>
<string-array name="edit_key_edit_user_id_revert_revocation">
<item>Revert revocation</item>
</string-array>
<string name="edit_key_edit_user_id_revoked">This identity has been revoked. This cannot be undone.</string>
<string name="edit_key_edit_subkey_title">Select an action!</string>
<string-array name="edit_key_edit_subkey">
<item>Change Expiry</item>
<item>Revoke Subkey</item>
</string-array>
<!-- Create key -->
<string name="create_key_upload">Upload key to keyserver</string>
<string name="create_key_empty">This field is required</string>