diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index b607ba9f4..b3786eac3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -17,6 +17,7 @@ package org.sufficientlysecure.keychain.ui; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -47,6 +48,12 @@ public class EditKeyActivity extends BaseActivity { 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 protected void initLayout() { setContentView(R.layout.edit_key_activity); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index cf975c4f3..d3ec0f2cc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -66,8 +66,8 @@ import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.OperationHelper; import org.sufficientlysecure.keychain.util.Passphrase; +import org.sufficientlysecure.keychain.util.operation.OperationHelper; public class EditKeyFragment extends NewCryptoOperationFragment implements LoaderManager.LoaderCallbacks { @@ -144,18 +144,19 @@ public class EditKeyFragment extends NewCryptoOperationFragment(getActivity()) { + super.setOperationHelper( + new OperationHelper(this) { @Override public SaveKeyringParcel createOperationInput() { + Log.d("PHILIP", "edit key creating operation input " + mSaveKeyringParcel); return mSaveKeyringParcel; } @Override protected void onCryptoOperationSuccess(OperationResult result) { - - // if good -> finish, return result to showkey and display there! + Log.d("PHILIP", "edit key success"); + // if good -> finish, return result to showkey and display thered! Intent intent = new Intent(); intent.putExtra(OperationResult.EXTRA_RESULT, result); getActivity().setResult(EditKeyActivity.RESULT_OK, intent); @@ -200,6 +201,12 @@ public class EditKeyFragment extends NewCryptoOperationFragment + * Copyright (C) 2015 Adithya Abraham Philip + * + * 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 . + */ + +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 { + private ArrayList mKeyList; + private String mKeyserver; + + public ImportOperationHelper(FragmentActivity activity, ArrayList keyList, String keyserver) { + super(activity); + mKeyList = keyList; + mKeyserver = keyserver; + } + @Override + public ImportKeyringParcel createOperationInput() { + return new ImportKeyringParcel(mKeyList, mKeyserver); + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/OperationHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/operation/OperationHelper.java similarity index 82% rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/OperationHelper.java rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/operation/OperationHelper.java index 11045cc24..1f7e1bbd4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/OperationHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/operation/OperationHelper.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.sufficientlysecure.keychain.util; +package org.sufficientlysecure.keychain.util.operation; import android.app.Activity; import android.app.ProgressDialog; @@ -26,6 +26,7 @@ import android.os.Bundle; import android.os.Message; import android.os.Messenger; import android.os.Parcelable; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import org.sufficientlysecure.keychain.R; 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.PassphraseDialogActivity; import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment; +import org.sufficientlysecure.keychain.util.Log; -public abstract class OperationHelper { +/** + * 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 The type of input parcel sent to the operation + * @param The type of result retruend by the operation + */ +public abstract class OperationHelper { public static final int REQUEST_CODE_PASSPHRASE = 0x00008001; public static final int REQUEST_CODE_NFC = 0x00008002; public static final int REQUEST_ENABLE_ORBOT = 0x00008004; private FragmentActivity mActivity; + private Fragment mFragment; + private boolean mUseFragment; + + /** + * If OperationHelper is being integrated into an activity + * + * @param activity + */ public OperationHelper(FragmentActivity 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) { @@ -60,7 +89,11 @@ public abstract class OperationHelper