mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 04:22:18 -05:00
fixed OperationHelper
This commit is contained in:
parent
9f61359c43
commit
1ce2877b41
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
@ -47,6 +48,12 @@ public class EditKeyActivity extends BaseActivity {
|
|||||||
loadFragment(savedInstanceState, dataUri, saveKeyringParcel);
|
loadFragment(savedInstanceState, dataUri, saveKeyringParcel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
Log.e("PHILIP", "activity result");
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initLayout() {
|
protected void initLayout() {
|
||||||
setContentView(R.layout.edit_key_activity);
|
setContentView(R.layout.edit_key_activity);
|
||||||
|
@ -66,8 +66,8 @@ import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment;
|
|||||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.OperationHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
import org.sufficientlysecure.keychain.util.operation.OperationHelper;
|
||||||
|
|
||||||
public class EditKeyFragment extends NewCryptoOperationFragment<SaveKeyringParcel, OperationResult>
|
public class EditKeyFragment extends NewCryptoOperationFragment<SaveKeyringParcel, OperationResult>
|
||||||
implements LoaderManager.LoaderCallbacks<Cursor> {
|
implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
@ -144,18 +144,19 @@ public class EditKeyFragment extends NewCryptoOperationFragment<SaveKeyringParce
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
setOperationHelper(
|
super.setOperationHelper(
|
||||||
new OperationHelper<SaveKeyringParcel, OperationResult>(getActivity()) {
|
new OperationHelper<SaveKeyringParcel, OperationResult>(this) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SaveKeyringParcel createOperationInput() {
|
public SaveKeyringParcel createOperationInput() {
|
||||||
|
Log.d("PHILIP", "edit key creating operation input " + mSaveKeyringParcel);
|
||||||
return mSaveKeyringParcel;
|
return mSaveKeyringParcel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCryptoOperationSuccess(OperationResult result) {
|
protected void onCryptoOperationSuccess(OperationResult result) {
|
||||||
|
Log.d("PHILIP", "edit key success");
|
||||||
// if good -> finish, return result to showkey and display there!
|
// if good -> finish, return result to showkey and display thered!
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(OperationResult.EXTRA_RESULT, result);
|
intent.putExtra(OperationResult.EXTRA_RESULT, result);
|
||||||
getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
|
getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
|
||||||
@ -200,6 +201,12 @@ public class EditKeyFragment extends NewCryptoOperationFragment<SaveKeyringParce
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
Log.e("PHILIP","Frament onActivityResult");
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
private void loadSaveKeyringParcel(SaveKeyringParcel saveKeyringParcel) {
|
private void loadSaveKeyringParcel(SaveKeyringParcel saveKeyringParcel) {
|
||||||
mSaveKeyringParcel = saveKeyringParcel;
|
mSaveKeyringParcel = saveKeyringParcel;
|
||||||
mPrimaryUserId = saveKeyringParcel.mChangePrimaryUserId;
|
mPrimaryUserId = saveKeyringParcel.mChangePrimaryUserId;
|
||||||
|
@ -18,30 +18,14 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.base;
|
package org.sufficientlysecure.keychain.ui.base;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.Messenger;
|
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainNewService;
|
|
||||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
|
||||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
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.dialog.ProgressDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.OperationHelper;
|
import org.sufficientlysecure.keychain.util.operation.OperationHelper;
|
||||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.util.operation;
|
||||||
|
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
|
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public abstract class ImportOperationHelper extends OperationHelper<ImportKeyringParcel, ImportKeyResult> {
|
||||||
|
private ArrayList<ParcelableKeyRing> mKeyList;
|
||||||
|
private String mKeyserver;
|
||||||
|
|
||||||
|
public ImportOperationHelper(FragmentActivity activity, ArrayList<ParcelableKeyRing> keyList, String keyserver) {
|
||||||
|
super(activity);
|
||||||
|
mKeyList = keyList;
|
||||||
|
mKeyserver = keyserver;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ImportKeyringParcel createOperationInput() {
|
||||||
|
return new ImportKeyringParcel(mKeyList, mKeyserver);
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.util;
|
package org.sufficientlysecure.keychain.util.operation;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
@ -26,6 +26,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
import org.sufficientlysecure.keychain.operations.results.InputPendingResult;
|
||||||
@ -39,16 +40,44 @@ import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
|
|||||||
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public abstract class OperationHelper <T extends Parcelable, S extends OperationResult> {
|
/**
|
||||||
|
* Designed to be intergrated into activities or fragments used for CryptoOperations.
|
||||||
|
* Encapsulates the execution of a crypto operation and handling of input pending cases.s
|
||||||
|
*
|
||||||
|
* @param <T> The type of input parcel sent to the operation
|
||||||
|
* @param <S> The type of result retruend by the operation
|
||||||
|
*/
|
||||||
|
public abstract class OperationHelper<T extends Parcelable, S extends OperationResult> {
|
||||||
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
||||||
public static final int REQUEST_CODE_NFC = 0x00008002;
|
public static final int REQUEST_CODE_NFC = 0x00008002;
|
||||||
public static final int REQUEST_ENABLE_ORBOT = 0x00008004;
|
public static final int REQUEST_ENABLE_ORBOT = 0x00008004;
|
||||||
|
|
||||||
private FragmentActivity mActivity;
|
private FragmentActivity mActivity;
|
||||||
|
private Fragment mFragment;
|
||||||
|
|
||||||
|
private boolean mUseFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If OperationHelper is being integrated into an activity
|
||||||
|
*
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
public OperationHelper(FragmentActivity activity) {
|
public OperationHelper(FragmentActivity activity) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
|
mUseFragment = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if OperationHelper is being integrated into a fragment
|
||||||
|
*
|
||||||
|
* @param fragment
|
||||||
|
*/
|
||||||
|
public OperationHelper(Fragment fragment) {
|
||||||
|
mFragment = fragment;
|
||||||
|
mActivity = fragment.getActivity();
|
||||||
|
mUseFragment = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initiateInputActivity(RequiredInputParcel requiredInput) {
|
private void initiateInputActivity(RequiredInputParcel requiredInput) {
|
||||||
@ -60,7 +89,11 @@ public abstract class OperationHelper <T extends Parcelable, S extends Operation
|
|||||||
case NFC_SIGN: {
|
case NFC_SIGN: {
|
||||||
Intent intent = new Intent(mActivity, NfcOperationActivity.class);
|
Intent intent = new Intent(mActivity, NfcOperationActivity.class);
|
||||||
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||||
|
if (mUseFragment) {
|
||||||
|
mFragment.startActivityForResult(intent, REQUEST_CODE_NFC);
|
||||||
|
} else {
|
||||||
mActivity.startActivityForResult(intent, REQUEST_CODE_NFC);
|
mActivity.startActivityForResult(intent, REQUEST_CODE_NFC);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,13 +101,21 @@ public abstract class OperationHelper <T extends Parcelable, S extends Operation
|
|||||||
case PASSPHRASE_SYMMETRIC: {
|
case PASSPHRASE_SYMMETRIC: {
|
||||||
Intent intent = new Intent(mActivity, PassphraseDialogActivity.class);
|
Intent intent = new Intent(mActivity, PassphraseDialogActivity.class);
|
||||||
intent.putExtra(PassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
intent.putExtra(PassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||||
|
if (mUseFragment) {
|
||||||
|
mFragment.startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
||||||
|
} else {
|
||||||
mActivity.startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
mActivity.startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ENABLE_ORBOT: {
|
case ENABLE_ORBOT: {
|
||||||
Intent intent = new Intent(mActivity, OrbotRequiredDialogActivity.class);
|
Intent intent = new Intent(mActivity, OrbotRequiredDialogActivity.class);
|
||||||
|
if (mUseFragment) {
|
||||||
|
mFragment.startActivityForResult(intent, REQUEST_ENABLE_ORBOT);
|
||||||
|
} else {
|
||||||
mActivity.startActivityForResult(intent, REQUEST_ENABLE_ORBOT);
|
mActivity.startActivityForResult(intent, REQUEST_ENABLE_ORBOT);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,6 +133,7 @@ public abstract class OperationHelper <T extends Parcelable, S extends Operation
|
|||||||
* @return true if requestCode was recognized, false otherwise
|
* @return true if requestCode was recognized, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
|
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
Log.d("PHILIP", "received activity result in OperationHelper");
|
||||||
if (resultCode == Activity.RESULT_CANCELED) {
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
onCryptoOperationCancelled();
|
onCryptoOperationCancelled();
|
||||||
return true;
|
return true;
|
Loading…
Reference in New Issue
Block a user