use only one DeleteDialogActivity
This commit is contained in:
@@ -764,7 +764,7 @@ public abstract class OperationResult implements Parcelable {
|
||||
MSG_REVOKE_ERROR_MULTI_SECRET (LogLevel.DEBUG, R.string.msg_revoke_error_multi_secret),
|
||||
MSG_REVOKE_ERROR_NOT_FOUND (LogLevel.DEBUG, R.string.msg_revoke_error_multi_secret),
|
||||
MSG_REVOKE (LogLevel.DEBUG, R.string.msg_revoke_key),
|
||||
MSG_REVOKE_KEY_FAIL (LogLevel.WARN, R.string.msg_revoke_key_fail),
|
||||
MSG_REVOKE_KEY_FAIL (LogLevel.ERROR, R.string.msg_revoke_key_fail),
|
||||
MSG_REVOKE_OK (LogLevel.OK, R.string.msg_revoke_ok),
|
||||
|
||||
// keybase verification
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -8,32 +10,40 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.RevokeResult;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.DeleteKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.RevokeKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DeleteKeyDialogActivity extends FragmentActivity
|
||||
implements CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult> {
|
||||
public class DeleteKeyDialogActivity extends FragmentActivity {
|
||||
public static final String EXTRA_DELETE_MASTER_KEY_IDS = "extra_delete_master_key_ids";
|
||||
public static final String EXTRA_HAS_SECRET = "extra_has_secret";
|
||||
public static final String EXTRA_KEYSERVER = "extra_keyserver";
|
||||
|
||||
private CryptoOperationHelper<DeleteKeyringParcel, DeleteResult> mDeleteOpHelper;
|
||||
private CryptoOperationHelper<RevokeKeyringParcel, RevokeResult> mRevokeOpHelper;
|
||||
|
||||
private long[] mMasterKeyIds;
|
||||
private boolean mHasSecret;
|
||||
@@ -42,95 +52,168 @@ public class DeleteKeyDialogActivity extends FragmentActivity
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mDeleteOpHelper = new CryptoOperationHelper<>(DeleteKeyDialogActivity.this,
|
||||
DeleteKeyDialogActivity.this, R.string.progress_deleting);
|
||||
mDeleteOpHelper.onRestoreInstanceState(savedInstanceState);
|
||||
mDeleteOpHelper = new CryptoOperationHelper<>(1, DeleteKeyDialogActivity.this,
|
||||
getDeletionCallback(), R.string.progress_deleting);
|
||||
|
||||
mRevokeOpHelper = new CryptoOperationHelper<>(2, this,
|
||||
getRevocationCallback(), R.string.progress_revoking_uploading);
|
||||
|
||||
mMasterKeyIds = getIntent().getLongArrayExtra(EXTRA_DELETE_MASTER_KEY_IDS);
|
||||
mHasSecret = getIntent().getBooleanExtra(EXTRA_HAS_SECRET, false);
|
||||
|
||||
Handler deleteDialogHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == DeleteKeyDialogFragment.MESSAGE_PERFORM_DELETE) {
|
||||
mHasSecret = msg.getData().getBoolean(DeleteKeyDialogFragment.MSG_HAS_SECRET);
|
||||
mDeleteOpHelper.cryptoOperation();
|
||||
if (mMasterKeyIds.length > 1 && mHasSecret) {
|
||||
throw new AssertionError("Secret keys can be deleted only one at a time!" +
|
||||
" Should be checked before reaching DeleteKeyDialogActivity.");
|
||||
}
|
||||
|
||||
if (mMasterKeyIds.length == 1 && mHasSecret) {
|
||||
// if mMasterKeyIds.length == 0 we let the DeleteOperation respond
|
||||
try {
|
||||
HashMap<String, Object> data = new ProviderHelper(this).getUnifiedData(
|
||||
mMasterKeyIds[0], new String[]{
|
||||
KeychainContract.KeyRings.USER_ID,
|
||||
KeychainContract.KeyRings.IS_REVOKED
|
||||
}, new int[]{
|
||||
ProviderHelper.FIELD_TYPE_STRING,
|
||||
ProviderHelper.FIELD_TYPE_INTEGER
|
||||
}
|
||||
);
|
||||
if ((long) data.get(KeychainContract.KeyRings.IS_REVOKED) > 0) {
|
||||
showNormalDeleteDialog();
|
||||
} else {
|
||||
showRevokeDeleteDialog();
|
||||
}
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG,
|
||||
"Secret key to delete not found at DeleteKeyDialogActivity for "
|
||||
+ mMasterKeyIds[0], e);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
showNormalDeleteDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void showNormalDeleteDialog() {
|
||||
|
||||
DeleteKeyDialogFragment deleteKeyDialogFragment
|
||||
= DeleteKeyDialogFragment.newInstance(mMasterKeyIds);
|
||||
|
||||
deleteKeyDialogFragment.show(getSupportFragmentManager(), "deleteKeyDialog");
|
||||
|
||||
}
|
||||
|
||||
private void showRevokeDeleteDialog() {
|
||||
|
||||
RevokeDeleteDialogFragment fragment = RevokeDeleteDialogFragment.newInstance();
|
||||
fragment.show(getSupportFragmentManager(), "deleteRevokeDialog");
|
||||
}
|
||||
|
||||
private void startRevocationOperation() {
|
||||
mRevokeOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
private void startDeletionOperation() {
|
||||
mDeleteOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
private CryptoOperationHelper.Callback<RevokeKeyringParcel, RevokeResult> getRevocationCallback() {
|
||||
|
||||
CryptoOperationHelper.Callback<RevokeKeyringParcel, RevokeResult> callback
|
||||
= new CryptoOperationHelper.Callback<RevokeKeyringParcel, RevokeResult>() {
|
||||
@Override
|
||||
public RevokeKeyringParcel createOperationInput() {
|
||||
return new RevokeKeyringParcel(mMasterKeyIds[0], true,
|
||||
getIntent().getStringExtra(EXTRA_KEYSERVER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(RevokeResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(RevokeResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Messenger messenger = new Messenger(deleteDialogHandler);
|
||||
|
||||
DeleteKeyDialogFragment deleteKeyDialogFragment
|
||||
= DeleteKeyDialogFragment.newInstance(messenger, mMasterKeyIds);
|
||||
|
||||
deleteKeyDialogFragment.show(getSupportFragmentManager(), "deleteKeyDialog");
|
||||
return callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
mDeleteOpHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
private CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult> getDeletionCallback() {
|
||||
|
||||
CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult> callback
|
||||
= new CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult>() {
|
||||
@Override
|
||||
public DeleteKeyringParcel createOperationInput() {
|
||||
return new DeleteKeyringParcel(mMasterKeyIds, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(DeleteResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(DeleteResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mDeleteOpHelper.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteKeyringParcel createOperationInput() {
|
||||
return new DeleteKeyringParcel(mMasterKeyIds, mHasSecret);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(DeleteResult result) {
|
||||
handleResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(DeleteResult result) {
|
||||
handleResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void handleResult(DeleteResult result) {
|
||||
private void returnResult(OperationResult result) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(OperationResult.EXTRA_RESULT, result);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
mDeleteOpHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
mRevokeOpHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
public static class DeleteKeyDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String MSG_HAS_SECRET = "msg_has_secret";
|
||||
|
||||
private static final String ARG_MESSENGER = "messenger";
|
||||
private static final String ARG_DELETE_MASTER_KEY_IDS = "delete_master_key_ids";
|
||||
|
||||
public static final int MESSAGE_PERFORM_DELETE = 1;
|
||||
|
||||
private TextView mMainMessage;
|
||||
private View mInflateView;
|
||||
|
||||
private Messenger mMessenger;
|
||||
/**
|
||||
* Creates new instance of this delete file dialog fragment
|
||||
*/
|
||||
public static DeleteKeyDialogFragment newInstance(Messenger messenger, long[] masterKeyIds) {
|
||||
public static DeleteKeyDialogFragment newInstance(long[] masterKeyIds) {
|
||||
DeleteKeyDialogFragment frag = new DeleteKeyDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
|
||||
args.putParcelable(ARG_MESSENGER, messenger);
|
||||
args.putLongArray(ARG_DELETE_MASTER_KEY_IDS, masterKeyIds);
|
||||
|
||||
frag.setArguments(args);
|
||||
@@ -138,10 +221,10 @@ public class DeleteKeyDialogActivity extends FragmentActivity
|
||||
return frag;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final FragmentActivity activity = getActivity();
|
||||
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
||||
|
||||
final long[] masterKeyIds = getArguments().getLongArray(ARG_DELETE_MASTER_KEY_IDS);
|
||||
|
||||
@@ -151,7 +234,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity
|
||||
CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme);
|
||||
|
||||
// Setup custom View to display in AlertDialog
|
||||
LayoutInflater inflater = activity.getLayoutInflater();
|
||||
LayoutInflater inflater = LayoutInflater.from(theme);
|
||||
mInflateView = inflater.inflate(R.layout.view_key_delete_fragment, null);
|
||||
builder.setView(mInflateView);
|
||||
|
||||
@@ -196,23 +279,13 @@ public class DeleteKeyDialogActivity extends FragmentActivity
|
||||
}
|
||||
} else {
|
||||
mMainMessage.setText(R.string.key_deletion_confirmation_multi);
|
||||
hasSecret = false;
|
||||
}
|
||||
|
||||
builder.setPositiveButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
Bundle data = new Bundle();
|
||||
data.putBoolean(MSG_HAS_SECRET, hasSecret);
|
||||
Message msg = Message.obtain();
|
||||
msg.setData(data);
|
||||
msg.what = MESSAGE_PERFORM_DELETE;
|
||||
try {
|
||||
mMessenger.send(msg);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "messenger error", e);
|
||||
}
|
||||
((DeleteKeyDialogActivity) getActivity()).startDeletionOperation();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -228,4 +301,88 @@ public class DeleteKeyDialogActivity extends FragmentActivity
|
||||
}
|
||||
}
|
||||
|
||||
public static class RevokeDeleteDialogFragment extends DialogFragment {
|
||||
|
||||
public static RevokeDeleteDialogFragment newInstance() {
|
||||
RevokeDeleteDialogFragment frag = new RevokeDeleteDialogFragment();
|
||||
return frag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Activity activity = getActivity();
|
||||
|
||||
final String CHOICE_REVOKE = getString(R.string.del_rev_dialog_choice_rev_upload);
|
||||
final String CHOICE_DELETE = getString(R.string.del_rev_dialog_choice_delete);
|
||||
|
||||
// if the dialog is displayed from the application class, design is missing
|
||||
// hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay
|
||||
ContextThemeWrapper theme = new ContextThemeWrapper(activity,
|
||||
R.style.Theme_AppCompat_Light_Dialog);
|
||||
|
||||
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);
|
||||
alert.setTitle(R.string.del_rev_dialog_title);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(theme);
|
||||
View view = inflater.inflate(R.layout.del_rev_dialog, null);
|
||||
alert.setView(view);
|
||||
|
||||
final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
|
||||
|
||||
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
activity.setResult(RESULT_CANCELED);
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
|
||||
alert.setPositiveButton(R.string.del_rev_dialog_btn_revoke,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
String choice = spinner.getSelectedItem().toString();
|
||||
if (choice.equals(CHOICE_REVOKE)) {
|
||||
((DeleteKeyDialogActivity) activity)
|
||||
.startRevocationOperation();
|
||||
} else if (choice.equals(CHOICE_DELETE)) {
|
||||
((DeleteKeyDialogActivity) activity)
|
||||
.startDeletionOperation();
|
||||
} else {
|
||||
throw new AssertionError(
|
||||
"Unsupported delete type in RevokeDeleteDialogFragment");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final AlertDialog alertDialog = alert.show();
|
||||
|
||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||
|
||||
String choice = parent.getItemAtPosition(pos).toString();
|
||||
|
||||
if (choice.equals(CHOICE_REVOKE)) {
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
.setText(R.string.del_rev_dialog_btn_revoke);
|
||||
} else if (choice.equals(CHOICE_DELETE)) {
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
.setText(R.string.del_rev_dialog_btn_delete);
|
||||
} else {
|
||||
throw new AssertionError(
|
||||
"Unsupported delete type in RevokeDeleteDialogFragment");
|
||||
}
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
return alertDialog;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -366,6 +366,11 @@ public class KeyListFragment extends LoaderFragment
|
||||
|
||||
Intent intent = new Intent(getActivity(), DeleteKeyDialogActivity.class);
|
||||
intent.putExtra(DeleteKeyDialogActivity.EXTRA_DELETE_MASTER_KEY_IDS, masterKeyIds);
|
||||
intent.putExtra(DeleteKeyDialogActivity.EXTRA_HAS_SECRET, hasSecret);
|
||||
if (hasSecret) {
|
||||
intent.putExtra(DeleteKeyDialogActivity.EXTRA_KEYSERVER,
|
||||
Preferences.getPreferences(getActivity()).getPreferredKeyserver());
|
||||
}
|
||||
startActivityForResult(intent, REQUEST_DELETE);
|
||||
}
|
||||
|
||||
@@ -603,7 +608,9 @@ public class KeyListFragment extends LoaderFragment
|
||||
|
||||
switch (requestCode) {
|
||||
case REQUEST_DELETE:
|
||||
mActionMode.finish();
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
}
|
||||
if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) {
|
||||
OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
|
||||
result.createNotify(getActivity()).show();
|
||||
|
||||
@@ -1,258 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2015 Adithya Abraham Philip <adithyaphilip@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.RevokeResult;
|
||||
import org.sufficientlysecure.keychain.service.DeleteKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.RevokeKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
public class RevokeDeleteDialogActivity extends FragmentActivity {
|
||||
|
||||
public static final String EXTRA_MASTER_KEY_ID = "extra_master_key_id";
|
||||
public static final String EXTRA_KEYSERVER = "extra_keyserver";
|
||||
|
||||
private final int REVOKE_OP_ID = 1;
|
||||
private final int DELETE_OP_ID = 2;
|
||||
private CryptoOperationHelper<RevokeKeyringParcel, RevokeResult> mRevokeOpHelper;
|
||||
private CryptoOperationHelper<DeleteKeyringParcel, DeleteResult> mDeleteOpHelper;
|
||||
|
||||
private long mMasterKeyId;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mRevokeOpHelper = new CryptoOperationHelper<>(this,
|
||||
getRevocationCallback(), R.string.progress_revoking_uploading, REVOKE_OP_ID);
|
||||
mRevokeOpHelper.onRestoreInstanceState(savedInstanceState);
|
||||
|
||||
mDeleteOpHelper = new CryptoOperationHelper<>(this,
|
||||
getDeletionCallback(), R.string.progress_deleting, DELETE_OP_ID);
|
||||
mDeleteOpHelper.onRestoreInstanceState(savedInstanceState);
|
||||
|
||||
mMasterKeyId = getIntent().getLongExtra(EXTRA_MASTER_KEY_ID, -1);
|
||||
|
||||
RevokeDeleteDialogFragment fragment = RevokeDeleteDialogFragment.newInstance();
|
||||
fragment.show(getSupportFragmentManager(), "deleteRevokeDialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
mDeleteOpHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
mRevokeOpHelper.handleActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mRevokeOpHelper.onSaveInstanceState(outState);
|
||||
mDeleteOpHelper.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void returnResult(OperationResult result) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(OperationResult.EXTRA_RESULT, result);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
private CryptoOperationHelper.Callback<RevokeKeyringParcel, RevokeResult> getRevocationCallback() {
|
||||
|
||||
CryptoOperationHelper.Callback<RevokeKeyringParcel, RevokeResult> callback
|
||||
= new CryptoOperationHelper.Callback<RevokeKeyringParcel, RevokeResult>() {
|
||||
@Override
|
||||
public RevokeKeyringParcel createOperationInput() {
|
||||
return new RevokeKeyringParcel(mMasterKeyId, true,
|
||||
getIntent().getStringExtra(EXTRA_KEYSERVER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(RevokeResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(RevokeResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return callback;
|
||||
}
|
||||
|
||||
private CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult> getDeletionCallback() {
|
||||
|
||||
CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult> callback
|
||||
= new CryptoOperationHelper.Callback<DeleteKeyringParcel, DeleteResult>() {
|
||||
@Override
|
||||
public DeleteKeyringParcel createOperationInput() {
|
||||
return new DeleteKeyringParcel(new long[]{mMasterKeyId}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationSuccess(DeleteResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationCancelled() {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCryptoOperationError(DeleteResult result) {
|
||||
returnResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCryptoSetProgress(String msg, int progress, int max) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return callback;
|
||||
}
|
||||
|
||||
private void startRevocationOperation() {
|
||||
mRevokeOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
private void startDeletionOperation() {
|
||||
mDeleteOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
public static class RevokeDeleteDialogFragment extends DialogFragment {
|
||||
|
||||
public static RevokeDeleteDialogFragment newInstance() {
|
||||
RevokeDeleteDialogFragment frag = new RevokeDeleteDialogFragment();
|
||||
return frag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Activity activity = getActivity();
|
||||
|
||||
final String CHOICE_REVOKE = getString(R.string.del_rev_dialog_choice_rev_upload);
|
||||
final String CHOICE_DELETE = getString(R.string.del_rev_dialog_choice_delete);
|
||||
|
||||
// if the dialog is displayed from the application class, design is missing
|
||||
// hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay
|
||||
ContextThemeWrapper theme = new ContextThemeWrapper(activity,
|
||||
R.style.Theme_AppCompat_Light_Dialog);
|
||||
|
||||
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);
|
||||
alert.setTitle(R.string.del_rev_dialog_title);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(theme);
|
||||
View view = inflater.inflate(R.layout.del_rev_dialog, null);
|
||||
alert.setView(view);
|
||||
|
||||
final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
|
||||
|
||||
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
activity.setResult(RESULT_CANCELED);
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
|
||||
alert.setPositiveButton(R.string.del_rev_dialog_btn_revoke,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
String choice = spinner.getSelectedItem().toString();
|
||||
if (choice.equals(CHOICE_REVOKE)) {
|
||||
((RevokeDeleteDialogActivity) activity)
|
||||
.startRevocationOperation();
|
||||
} else if (choice.equals(CHOICE_DELETE)) {
|
||||
((RevokeDeleteDialogActivity) activity)
|
||||
.startDeletionOperation();
|
||||
} else {
|
||||
throw new AssertionError(
|
||||
"Unsupported delete type in RevokeDeleteDialogFragment");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final AlertDialog alertDialog = alert.show();
|
||||
|
||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||
|
||||
String choice = parent.getItemAtPosition(pos).toString();
|
||||
|
||||
if (choice.equals(CHOICE_REVOKE)) {
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
.setText(R.string.del_rev_dialog_btn_revoke);
|
||||
} else if (choice.equals(CHOICE_DELETE)) {
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
.setText(R.string.del_rev_dialog_btn_delete);
|
||||
} else {
|
||||
throw new AssertionError(
|
||||
"Unsupported delete type in RevokeDeleteDialogFragment");
|
||||
}
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
return alertDialog;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,6 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
||||
static final int REQUEST_BACKUP = 2;
|
||||
static final int REQUEST_CERTIFY = 3;
|
||||
static final int REQUEST_DELETE = 4;
|
||||
static final int REQUEST_REVOKE_DELETE = 5;
|
||||
|
||||
public static final String EXTRA_DISPLAY_RESULT = "display_result";
|
||||
|
||||
@@ -419,24 +418,18 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
||||
}
|
||||
|
||||
private void deleteKey() {
|
||||
if (mIsSecret && !mIsRevoked) {
|
||||
Intent revokeDeleteIntent = new Intent(this, RevokeDeleteDialogActivity.class);
|
||||
Intent deleteIntent = new Intent(this, DeleteKeyDialogActivity.class);
|
||||
|
||||
revokeDeleteIntent.putExtra(RevokeDeleteDialogActivity.EXTRA_MASTER_KEY_ID,
|
||||
mMasterKeyId);
|
||||
revokeDeleteIntent.putExtra(RevokeDeleteDialogActivity.EXTRA_KEYSERVER,
|
||||
deleteIntent.putExtra(DeleteKeyDialogActivity.EXTRA_DELETE_MASTER_KEY_IDS,
|
||||
new long[]{mMasterKeyId});
|
||||
deleteIntent.putExtra(DeleteKeyDialogActivity.EXTRA_HAS_SECRET, mIsSecret);
|
||||
if (mIsSecret) {
|
||||
// for upload in case key is secret
|
||||
deleteIntent.putExtra(DeleteKeyDialogActivity.EXTRA_KEYSERVER,
|
||||
Preferences.getPreferences(this).getPreferredKeyserver());
|
||||
|
||||
startActivityForResult(revokeDeleteIntent, REQUEST_REVOKE_DELETE);
|
||||
|
||||
} else {
|
||||
Intent deleteIntent = new Intent(this, DeleteKeyDialogActivity.class);
|
||||
|
||||
deleteIntent.putExtra(DeleteKeyDialogActivity.EXTRA_DELETE_MASTER_KEY_IDS,
|
||||
new long[]{mMasterKeyId});
|
||||
|
||||
startActivityForResult(deleteIntent, REQUEST_DELETE);
|
||||
}
|
||||
|
||||
startActivityForResult(deleteIntent, REQUEST_DELETE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -485,7 +478,6 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
case REQUEST_REVOKE_DELETE:
|
||||
case REQUEST_DELETE: {
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
|
||||
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.RevokeDeleteDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@@ -152,13 +151,11 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
}
|
||||
|
||||
protected void startActivityForResult(Intent intent, int requestCode) {
|
||||
mRequestedCode = requestCode;
|
||||
if (mUseFragment) {
|
||||
mFragment.startActivityForResult(intent, mRequestedCode);
|
||||
mFragment.startActivityForResult(intent, mId + requestCode);
|
||||
} else {
|
||||
mActivity.startActivityForResult(intent, mRequestedCode);
|
||||
mActivity.startActivityForResult(intent, mId + requestCode);
|
||||
}
|
||||
Log.e("PHILIP", "mRequestedCode: " + mRequestedCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,13 +164,13 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
* @return true if requestCode was recognized, false otherwise
|
||||
*/
|
||||
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log.d(Constants.TAG, "received activity result in OperationHelper with code: "
|
||||
+ requestCode + " while waiting for: " + mRequestedCode);
|
||||
Log.d(Constants.TAG, "received activity result in OperationHelper");
|
||||
|
||||
if ((requestCode & mId) != mId) {
|
||||
// this wasn't meant for us to handle
|
||||
return false;
|
||||
}
|
||||
Log.d(Constants.TAG, "handling activity result in OperationHelper");
|
||||
// filter out mId from requestCode
|
||||
requestCode ^= mId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user