fixed multi-deletion bug, moved logic into DeleteKeyDialogActivity

This commit is contained in:
Adithya Abraham Philip
2015-07-15 20:16:07 +05:30
parent 771d654766
commit fe0b083bc5
4 changed files with 21 additions and 20 deletions

View File

@@ -125,7 +125,10 @@ public class DeleteResult extends InputPendingResult {
} else { } else {
duration = 0; duration = 0;
style = Style.ERROR; style = Style.ERROR;
if (mFail == 0) { if (mLog.getLast().mType == LogType.MSG_DEL_ERROR_MULTI_SECRET) {
str = activity.getString(R.string.secret_cannot_multiple);
}
else if (mFail == 0) {
str = activity.getString(R.string.delete_nothing); str = activity.getString(R.string.delete_nothing);
} else { } else {
str = activity.getResources().getQuantityString(R.plurals.delete_fail, mFail); str = activity.getResources().getQuantityString(R.plurals.delete_fail, mFail);

View File

@@ -754,7 +754,7 @@ public abstract class OperationResult implements Parcelable {
MSG_GET_QUERY_FAILED(LogLevel.ERROR, R.string.msg_download_query_failed), MSG_GET_QUERY_FAILED(LogLevel.ERROR, R.string.msg_download_query_failed),
MSG_DEL_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_del_error_empty), MSG_DEL_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_del_error_empty),
MSG_DEL_ERROR_MULTI_SECRET (LogLevel.DEBUG, R.string.msg_del_error_multi_secret), MSG_DEL_ERROR_MULTI_SECRET (LogLevel.ERROR, R.string.msg_del_error_multi_secret),
MSG_DEL (LogLevel.START, R.plurals.msg_del), MSG_DEL (LogLevel.START, R.plurals.msg_del),
MSG_DEL_KEY (LogLevel.DEBUG, R.string.msg_del_key), MSG_DEL_KEY (LogLevel.DEBUG, R.string.msg_del_key),
MSG_DEL_KEY_FAIL (LogLevel.WARN, R.string.msg_del_key_fail), MSG_DEL_KEY_FAIL (LogLevel.WARN, R.string.msg_del_key_fail),

View File

@@ -48,6 +48,7 @@ import org.sufficientlysecure.keychain.service.RevokeKeyringParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import java.util.Date; import java.util.Date;
@@ -62,6 +63,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
private CryptoOperationHelper<RevokeKeyringParcel, RevokeResult> mRevokeOpHelper; private CryptoOperationHelper<RevokeKeyringParcel, RevokeResult> mRevokeOpHelper;
private long[] mMasterKeyIds; private long[] mMasterKeyIds;
private boolean mHasSecret;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -74,14 +76,17 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
getRevocationCallback(), R.string.progress_revoking_uploading); getRevocationCallback(), R.string.progress_revoking_uploading);
mMasterKeyIds = getIntent().getLongArrayExtra(EXTRA_DELETE_MASTER_KEY_IDS); mMasterKeyIds = getIntent().getLongArrayExtra(EXTRA_DELETE_MASTER_KEY_IDS);
boolean hasSecret = getIntent().getBooleanExtra(EXTRA_HAS_SECRET, false); mHasSecret = getIntent().getBooleanExtra(EXTRA_HAS_SECRET, false);
if (mMasterKeyIds.length > 1 && hasSecret) { if (mMasterKeyIds.length > 1 && mHasSecret) {
throw new AssertionError("Secret keys can be deleted only one at a time!" + // secret keys can only be deleted individually
" Should be checked before reaching DeleteKeyDialogActivity."); OperationResult.OperationLog log = new OperationResult.OperationLog();
log.add(OperationResult.LogType.MSG_DEL_ERROR_MULTI_SECRET, 0);
returnResult(new DeleteResult(OperationResult.RESULT_ERROR, log, 0,
mMasterKeyIds.length));
} }
if (mMasterKeyIds.length == 1 && hasSecret) { if (mMasterKeyIds.length == 1 && mHasSecret) {
// if mMasterKeyIds.length == 0 we let the DeleteOperation respond // if mMasterKeyIds.length == 0 we let the DeleteOperation respond
try { try {
HashMap<String, Object> data = new ProviderHelper(this).getUnifiedData( HashMap<String, Object> data = new ProviderHelper(this).getUnifiedData(
@@ -122,7 +127,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
private void showNormalDeleteDialog() { private void showNormalDeleteDialog() {
DeleteKeyDialogFragment deleteKeyDialogFragment DeleteKeyDialogFragment deleteKeyDialogFragment
= DeleteKeyDialogFragment.newInstance(mMasterKeyIds); = DeleteKeyDialogFragment.newInstance(mMasterKeyIds, mHasSecret);
deleteKeyDialogFragment.show(getSupportFragmentManager(), "deleteKeyDialog"); deleteKeyDialogFragment.show(getSupportFragmentManager(), "deleteKeyDialog");
@@ -179,7 +184,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
return new CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult>() { return new CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult>() {
@Override @Override
public DeleteKeyringParcel createOperationInput() { public DeleteKeyringParcel createOperationInput() {
return new DeleteKeyringParcel(mMasterKeyIds, true); return new DeleteKeyringParcel(mMasterKeyIds, mHasSecret);
} }
@Override @Override
@@ -221,6 +226,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
public static class DeleteKeyDialogFragment extends DialogFragment { public static class DeleteKeyDialogFragment extends DialogFragment {
private static final String ARG_DELETE_MASTER_KEY_IDS = "delete_master_key_ids"; private static final String ARG_DELETE_MASTER_KEY_IDS = "delete_master_key_ids";
private static final String ARG_HAS_SECRET = "has_secret";
private TextView mMainMessage; private TextView mMainMessage;
private View mInflateView; private View mInflateView;
@@ -228,11 +234,12 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
/** /**
* Creates new instance of this delete file dialog fragment * Creates new instance of this delete file dialog fragment
*/ */
public static DeleteKeyDialogFragment newInstance(long[] masterKeyIds) { public static DeleteKeyDialogFragment newInstance(long[] masterKeyIds, boolean hasSecret) {
DeleteKeyDialogFragment frag = new DeleteKeyDialogFragment(); DeleteKeyDialogFragment frag = new DeleteKeyDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray(ARG_DELETE_MASTER_KEY_IDS, masterKeyIds); args.putLongArray(ARG_DELETE_MASTER_KEY_IDS, masterKeyIds);
args.putBoolean(ARG_HAS_SECRET, hasSecret);
frag.setArguments(args); frag.setArguments(args);
@@ -245,6 +252,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
final FragmentActivity activity = getActivity(); final FragmentActivity activity = getActivity();
final long[] masterKeyIds = getArguments().getLongArray(ARG_DELETE_MASTER_KEY_IDS); final long[] masterKeyIds = getArguments().getLongArray(ARG_DELETE_MASTER_KEY_IDS);
final boolean hasSecret = getArguments().getBoolean(ARG_HAS_SECRET);
ContextThemeWrapper theme = new ContextThemeWrapper(activity, ContextThemeWrapper theme = new ContextThemeWrapper(activity,
R.style.Theme_AppCompat_Light_Dialog); R.style.Theme_AppCompat_Light_Dialog);
@@ -258,8 +266,6 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
mMainMessage = (TextView) mInflateView.findViewById(R.id.mainMessage); mMainMessage = (TextView) mInflateView.findViewById(R.id.mainMessage);
final boolean hasSecret;
// If only a single key has been selected // If only a single key has been selected
if (masterKeyIds.length == 1) { if (masterKeyIds.length == 1) {
long masterKeyId = masterKeyIds[0]; long masterKeyId = masterKeyIds[0];
@@ -281,7 +287,6 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
} else { } else {
name = getString(R.string.user_id_no_name); name = getString(R.string.user_id_no_name);
} }
hasSecret = ((Long) data.get(KeychainContract.KeyRings.HAS_ANY_SECRET)) == 1;
if (hasSecret) { if (hasSecret) {
// show title only for secret key deletions, // show title only for secret key deletions,

View File

@@ -352,13 +352,6 @@ public class KeyListFragment extends LoaderFragment
* @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not
*/ */
public void showDeleteKeyDialog(long[] masterKeyIds, boolean hasSecret) { public void showDeleteKeyDialog(long[] masterKeyIds, boolean hasSecret) {
// Can only work on singular secret keys
if (hasSecret && masterKeyIds.length > 1) {
Notify.create(getActivity(), R.string.secret_cannot_multiple,
Notify.Style.ERROR).show();
return;
}
Intent intent = new Intent(getActivity(), DeleteKeyDialogActivity.class); Intent intent = new Intent(getActivity(), DeleteKeyDialogActivity.class);
intent.putExtra(DeleteKeyDialogActivity.EXTRA_DELETE_MASTER_KEY_IDS, masterKeyIds); intent.putExtra(DeleteKeyDialogActivity.EXTRA_DELETE_MASTER_KEY_IDS, masterKeyIds);
intent.putExtra(DeleteKeyDialogActivity.EXTRA_HAS_SECRET, hasSecret); intent.putExtra(DeleteKeyDialogActivity.EXTRA_HAS_SECRET, hasSecret);