From 79f37d3267883110dd1a6ccaf29d8a228fc86176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 1 Jul 2015 14:16:54 +0200 Subject: Use operation helper for move to card --- .../keychain/ui/CreateKeyFinalFragment.java | 101 +++++++++++++-------- 1 file changed, 64 insertions(+), 37 deletions(-) (limited to 'OpenKeychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 52083a552..7a083ba5e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -18,13 +18,11 @@ package org.sufficientlysecure.keychain.ui; import android.app.Activity; -import android.app.ProgressDialog; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; +import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -43,21 +41,17 @@ import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.ExportKeyringParcel; -import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel; -import org.sufficientlysecure.keychain.service.ServiceProgressHandler; -import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; -import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; import java.util.Iterator; -public class CreateKeyFinalFragment extends CryptoOperationFragment { +public class CreateKeyFinalFragment extends Fragment { public static final int REQUEST_EDIT_KEY = 0x00008007; @@ -73,6 +67,7 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment mUploadOpHelper; private CryptoOperationHelper mCreateOpHelper; + private CryptoOperationHelper mMoveToCardOpHelper; public static CreateKeyFinalFragment newInstance() { CreateKeyFinalFragment frag = new CreateKeyFinalFragment(); @@ -150,6 +145,16 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment callback + = new CryptoOperationHelper.Callback() { - // currently only used for moveToCard - @Override - public void onCryptoOperationSuccess(OperationResult result) { - EditKeyResult editResult = (EditKeyResult) result; + @Override + public SaveKeyringParcel createOperationInput() { + return changeKeyringParcel; + } + + @Override + public void onCryptoOperationSuccess(EditKeyResult result) { + handleResult(result); + } + + @Override + public void onCryptoOperationCancelled() { + + } + + @Override + public void onCryptoOperationError(EditKeyResult result) { + handleResult(result); + } + + public void handleResult(EditKeyResult result) { + if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) { + // result will be displayed after upload + uploadKey(result); + return; + } + + Intent data = new Intent(); + data.putExtra(OperationResult.EXTRA_RESULT, result); + getActivity().setResult(Activity.RESULT_OK, data); + getActivity().finish(); + } + + @Override + public boolean onCryptoSetProgress(String msg, int progress, int max) { + return false; + } + }; - if (editResult.mMasterKeyId != null && mUploadCheckbox.isChecked()) { - // result will be displayed after upload - uploadKey(editResult); - return; - } - Intent data = new Intent(); - data.putExtra(OperationResult.EXTRA_RESULT, result); - getActivity().setResult(Activity.RESULT_OK, data); - getActivity().finish(); + mMoveToCardOpHelper = new CryptoOperationHelper<>(this, callback, R.string.progress_modify); + mMoveToCardOpHelper.cryptoOperation(); } - // TODO move into EditKeyOperation private void uploadKey(final EditKeyResult saveKeyResult) { // set data uri as path to keyring final Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri( -- cgit v1.2.3