fixed OperationHelper

This commit is contained in:
Adithya Abraham Philip 2015-06-20 19:25:21 +05:30
parent 9f61359c43
commit 1ce2877b41
5 changed files with 108 additions and 27 deletions

View File

@ -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);

View File

@ -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<SaveKeyringParcel, OperationResult>
implements LoaderManager.LoaderCallbacks<Cursor> {
@ -144,18 +144,19 @@ public class EditKeyFragment extends NewCryptoOperationFragment<SaveKeyringParce
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setOperationHelper(
new OperationHelper<SaveKeyringParcel, OperationResult>(getActivity()) {
super.setOperationHelper(
new OperationHelper<SaveKeyringParcel, OperationResult>(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<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) {
mSaveKeyringParcel = saveKeyringParcel;
mPrimaryUserId = saveKeyringParcel.mChangePrimaryUserId;

View File

@ -18,30 +18,14 @@
package org.sufficientlysecure.keychain.ui.base;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcelable;
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.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.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.OperationHelper;
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
import org.sufficientlysecure.keychain.util.operation.OperationHelper;
/**

View File

@ -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);
}
}

View File

@ -17,7 +17,7 @@
* 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.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 <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_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 <T extends Parcelable, S extends Operation
case NFC_SIGN: {
Intent intent = new Intent(mActivity, NfcOperationActivity.class);
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
if (mUseFragment) {
mFragment.startActivityForResult(intent, REQUEST_CODE_NFC);
} else {
mActivity.startActivityForResult(intent, REQUEST_CODE_NFC);
}
return;
}
@ -68,13 +101,21 @@ public abstract class OperationHelper <T extends Parcelable, S extends Operation
case PASSPHRASE_SYMMETRIC: {
Intent intent = new Intent(mActivity, PassphraseDialogActivity.class);
intent.putExtra(PassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
if (mUseFragment) {
mFragment.startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
} else {
mActivity.startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
}
return;
}
case ENABLE_ORBOT: {
Intent intent = new Intent(mActivity, OrbotRequiredDialogActivity.class);
if (mUseFragment) {
mFragment.startActivityForResult(intent, REQUEST_ENABLE_ORBOT);
} else {
mActivity.startActivityForResult(intent, REQUEST_ENABLE_ORBOT);
}
return;
}
}
@ -92,6 +133,7 @@ public abstract class OperationHelper <T extends Parcelable, S extends Operation
* @return true if requestCode was recognized, false otherwise
*/
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("PHILIP", "received activity result in OperationHelper");
if (resultCode == Activity.RESULT_CANCELED) {
onCryptoOperationCancelled();
return true;