diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-03-10 02:08:51 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-03-10 02:08:51 +0100 |
commit | 2a42ff016fbe3974811323f4da3775279d6bdccc (patch) | |
tree | 03790bb1a4cd2f2f0f3e6bdc519d987acf3bad27 /OpenKeychain/src/main/java | |
parent | 4db86fdabe80cffba13b5e18e1576b5d8de39e8d (diff) | |
download | open-keychain-2a42ff016fbe3974811323f4da3775279d6bdccc.tar.gz open-keychain-2a42ff016fbe3974811323f4da3775279d6bdccc.tar.bz2 open-keychain-2a42ff016fbe3974811323f4da3775279d6bdccc.zip |
cleaner handling of verification state
Diffstat (limited to 'OpenKeychain/src/main/java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java | 110 |
1 files changed, 64 insertions, 46 deletions
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 f523441c5..1c301c642 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 @@ -71,7 +71,6 @@ public class LinkedIdViewFragment extends Fragment implements private Context mContext; private byte[] mFingerprint; - private LayoutInflater mInflater; private AsyncTask mInProgress; @@ -106,9 +105,9 @@ public class LinkedIdViewFragment extends Fragment implements mFingerprint = args.getByteArray(ARG_FINGERPRINT); mContext = getActivity(); - mInflater = getLayoutInflater(savedInstanceState); getLoaderManager().initLoader(LOADER_ID_LINKED_ID, null, this); + } @Override @@ -169,22 +168,7 @@ public class LinkedIdViewFragment extends Fragment implements private void loadIdentity(RawLinkedIdentity linkedId, int certStatus) { mLinkedId = linkedId; - new Handler().post(new Runnable() { - @Override - public void run() { - getFragmentManager().popBackStack("verification", - FragmentManager.POP_BACK_STACK_INCLUSIVE); - } - }); - mViewHolder.setShowVerifying(false); - - { - Bundle args = new Bundle(); - args.putParcelable(CertListWidget.ARG_URI, mDataUri); - args.putInt(CertListWidget.ARG_RANK, mLidRank); - getLoaderManager().initLoader(CertListWidget.LOADER_ID_LINKED_CERTS, - args, mViewHolder.vLinkedCerts); - } + setShowVerifying(false); if (mLinkedId instanceof LinkedIdentity) { LinkedResource res = ((LinkedIdentity) mLinkedId).mResource; @@ -281,17 +265,6 @@ public class LinkedIdViewFragment extends Fragment implements vText = (TextView) root.findViewById(R.id.linked_cert_text); } - void setShowVerifying(boolean show) { - int child = show ? 1 : 0; - if (vVerifyingContainer.getDisplayedChild() != child) { - vVerifyingContainer.setDisplayedChild(child); - } - if (!show) { - vKeySpinner.setVisibility(View.GONE); - showButton(0); - } - } - void setShowProgress(boolean show) { vProgress.setDisplayedChild(show ? 0 : 1); } @@ -305,6 +278,58 @@ public class LinkedIdViewFragment extends Fragment implements } + private boolean mVerificationState = false; + /** Switches between the 'verifying' ui bit and certificate status. This method + * must behave correctly in all states, showing or hiding the appropriate views + * and cancelling pending operations where necessary. + * + * This method also handles back button functionality in combination with + * onBackStateChanged. + */ + void setShowVerifying(boolean show) { + if (!show) { + if (mInProgress != null) { + mInProgress.cancel(false); + mInProgress = null; + } + getFragmentManager().removeOnBackStackChangedListener(this); + new Handler().post(new Runnable() { + @Override + public void run() { + getFragmentManager().popBackStack("verification", + FragmentManager.POP_BACK_STACK_INCLUSIVE); + } + }); + + if (!mVerificationState) { + return; + } + mVerificationState = false; + + mViewHolder.showButton(0); + mViewHolder.vKeySpinner.setVisibility(View.GONE); + mViewHolder.vVerifyingContainer.setDisplayedChild(0); + return; + } + + if (mVerificationState) { + return; + } + mVerificationState = true; + + FragmentManager manager = getFragmentManager(); + manager.beginTransaction().addToBackStack("verification").commit(); + manager.executePendingTransactions(); + manager.addOnBackStackChangedListener(this); + mViewHolder.vVerifyingContainer.setDisplayedChild(1); + + } + + @Override + public void onBackStackChanged() { + setShowVerifying(false); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.linked_id_view_fragment, null); @@ -339,22 +364,25 @@ public class LinkedIdViewFragment extends Fragment implements } }); + { + Bundle args = new Bundle(); + args.putParcelable(CertListWidget.ARG_URI, mDataUri); + args.putInt(CertListWidget.ARG_RANK, mLidRank); + getLoaderManager().initLoader(CertListWidget.LOADER_ID_LINKED_CERTS, + args, mViewHolder.vLinkedCerts); + } + return root; } void verifyResource() { - // only one at a time + // only one at a time (no sync needed, mInProgress is only touched in ui thread) if (mInProgress != null) { return; } - FragmentManager manager = getFragmentManager(); - manager.beginTransaction().addToBackStack("verification").commit(); - manager.executePendingTransactions(); - manager.addOnBackStackChangedListener(this); - - mViewHolder.setShowVerifying(true); + setShowVerifying(true); mViewHolder.vKeySpinner.setVisibility(View.GONE); mViewHolder.setShowProgress(true); @@ -428,16 +456,6 @@ public class LinkedIdViewFragment extends Fragment implements } @Override - public void onBackStackChanged() { - mViewHolder.setShowVerifying(false); - getFragmentManager().removeOnBackStackChangedListener(LinkedIdViewFragment.this); - if (mInProgress != null) { - mInProgress.cancel(false); - mInProgress = null; - } - } - - @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CODE_PASSPHRASE: { |