diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked')
2 files changed, 25 insertions, 73 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java index 0767aabd2..b98fc6238 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateFinalFragment.java @@ -1,6 +1,5 @@ package org.sufficientlysecure.keychain.ui.linked; -import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.graphics.PorterDuff; @@ -8,7 +7,6 @@ import android.os.AsyncTask; 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.View.OnClickListener; @@ -28,14 +26,11 @@ import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.ServiceProgressHandler; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; +import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment.ServiceType; import org.sufficientlysecure.keychain.ui.util.Notify; -import org.sufficientlysecure.keychain.util.Passphrase; -public abstract class LinkedIdCreateFinalFragment extends Fragment { - - protected static final int REQUEST_CODE_PASSPHRASE = 0x00007008; +public abstract class LinkedIdCreateFinalFragment extends CryptoOperationFragment { protected LinkedIdWizard mLinkedIdWizard; @@ -63,7 +58,7 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment { view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - startCertify(); + cryptoOperation(); } }); @@ -174,29 +169,28 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment { } - private void startCertify() { + protected void cryptoOperation(CryptoInputParcel cryptoInput) { if (mVerifiedResource == null) { Notify.create(getActivity(), R.string.linked_need_verify, Notify.Style.ERROR).show(); return; } - Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class); - intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mLinkedIdWizard.mMasterKeyId); - startActivityForResult(intent, REQUEST_CODE_PASSPHRASE); - - } - - private void certifyLinkedIdentity (CryptoInputParcel cryptoInput) { ServiceProgressHandler saveHandler = new ServiceProgressHandler( getActivity(), getString(R.string.progress_saving), ProgressDialog.STYLE_HORIZONTAL, true, ServiceType.KEYCHAIN_INTENT) { + public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); + // handle pending messages + if (handlePendingMessage(message)) { + return; + } + if (message.arg1 == MessageStatus.OKAY.ordinal()) { // get returned data bundle @@ -252,20 +246,4 @@ public abstract class LinkedIdCreateFinalFragment extends Fragment { } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case REQUEST_CODE_PASSPHRASE: - if (resultCode == Activity.RESULT_OK && data != null) { - CryptoInputParcel cryptoInput = - data.getParcelableExtra(PassphraseDialogActivity.RESULT_CRYPTO_INPUT); - certifyLinkedIdentity(cryptoInput); - } - break; - default: - super.onActivityResult(requestCode, resultCode, data); - } - } - } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java index 1944146dd..152cb8988 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.util.Collections; import android.animation.ObjectAnimator; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.database.Cursor; @@ -16,7 +15,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.Messenger; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager.OnBackStackChangedListener; import android.support.v4.app.LoaderManager; @@ -45,12 +43,11 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.ServiceProgressHandler; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; +import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.linked.LinkedIdViewFragment.ViewHolder.VerifyState; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; @@ -60,14 +57,11 @@ import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker; import org.sufficientlysecure.keychain.ui.widget.CertListWidget; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.Passphrase; -public class LinkedIdViewFragment extends Fragment implements +public class LinkedIdViewFragment extends CryptoOperationFragment implements LoaderManager.LoaderCallbacks<Cursor>, OnBackStackChangedListener { - public static final int REQUEST_CODE_PASSPHRASE = 0x00008001; - private static final String ARG_DATA_URI = "data_uri"; private static final String ARG_LID_RANK = "rank"; private static final String ARG_IS_SECRET = "verified"; @@ -512,44 +506,20 @@ public class LinkedIdViewFragment extends Fragment implements return; } - Passphrase passphrase; - try { - passphrase = PassphraseCacheService.getCachedPassphrase( - getActivity(), mCertifyKeyId, mCertifyKeyId); - } catch (PassphraseCacheService.KeyNotFoundException e) { - Log.e(Constants.TAG, "Key not found!", e); - getActivity().finish(); - return; - } - if (passphrase == null) { - Intent intent = new Intent(getActivity(), PassphraseDialogActivity.class); - intent.putExtra(PassphraseDialogActivity.EXTRA_SUBKEY_ID, mCertifyKeyId); - startActivityForResult(intent, REQUEST_CODE_PASSPHRASE); - // bail out; need to wait until the user has entered the passphrase before trying again - } else { - certifyResource(new CryptoInputParcel()); - } + cryptoOperation(); } @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - switch (requestCode) { - case REQUEST_CODE_PASSPHRASE: { - if (resultCode == Activity.RESULT_OK && data != null) { - CryptoInputParcel cryptoInput = data.getParcelableExtra( - PassphraseDialogActivity.RESULT_CRYPTO_INPUT); - certifyResource(cryptoInput); - } - return; - } + protected void onCryptoOperationCancelled() { + super.onCryptoOperationCancelled(); + + // go back to 'verified ok' + setShowVerifying(false); - default: { - super.onActivityResult(requestCode, resultCode, data); - } - } } - private void certifyResource(CryptoInputParcel cryptoInput) { + @Override + protected void cryptoOperation(CryptoInputParcel cryptoInput) { if (mIsSecret) { return; @@ -588,9 +558,13 @@ public class LinkedIdViewFragment extends Fragment implements // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); - Bundle data = message.getData(); + // handle pending messages + if (handlePendingMessage(message)) { + return; + } if (message.arg1 == MessageStatus.OKAY.ordinal()) { + Bundle data = message.getData(); CertifyResult result = data.getParcelable(CertifyResult.EXTRA_RESULT); result.createNotify(getActivity()).show(); // no need to do anything else, we will get a loader refresh! |