diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-03-06 14:20:58 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-03-06 14:21:13 +0100 |
commit | 6e17d5244dcbfaad5c4de902e1f4c2cd913fd596 (patch) | |
tree | 52058bdfbad4395bf5fcae519791fa8f3c8a07fc /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked | |
parent | a2419aa688afb61c02a1fcd4a8d1df46fdd97b5e (diff) | |
download | open-keychain-6e17d5244dcbfaad5c4de902e1f4c2cd913fd596.tar.gz open-keychain-6e17d5244dcbfaad5c4de902e1f4c2cd913fd596.tar.bz2 open-keychain-6e17d5244dcbfaad5c4de902e1f4c2cd913fd596.zip |
first steps in ui towards confirmation of linked ids
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdViewFragment.java | 116 |
1 files changed, 108 insertions, 8 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 b526776f0..5cf0ed115 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,6 +4,7 @@ import java.io.IOException; import android.content.Context; import android.content.Intent; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.CardView; @@ -11,8 +12,13 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.ViewAnimator; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.operations.results.LinkedVerifyResult; import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource; import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; import org.sufficientlysecure.keychain.pgp.linked.LinkedResource; @@ -21,12 +27,15 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter.ViewHolder; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; +import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; public class LinkedIdViewFragment extends Fragment { - private static final String EXTRA_ENCODED_LID = "encoded_lid"; - private static final String EXTRA_VERIFIED = "verified"; + private static final String ARG_ENCODED_LID = "encoded_lid"; + private static final String ARG_VERIFIED = "verified"; + private static final String ARG_FINGERPRINT = "fingerprint"; private RawLinkedIdentity mLinkedId; private LinkedCookieResource mLinkedResource; @@ -34,13 +43,20 @@ public class LinkedIdViewFragment extends Fragment { private CardView vLinkedIdsCard; private Context mContext; + private byte[] mFingerprint; + private LayoutInflater mInflater; + private LinearLayout vLinkedCerts; + + private View mCurrentCert; + private boolean mInProgress; + private ViewAnimator mButtonSwitcher; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); - byte[] data = args.getByteArray(EXTRA_ENCODED_LID); + byte[] data = args.getByteArray(ARG_ENCODED_LID); try { mLinkedId = LinkedIdentity.fromAttributeData(data); @@ -55,19 +71,24 @@ public class LinkedIdViewFragment extends Fragment { mLinkedResource = (LinkedCookieResource) res; } - mVerified = args.containsKey(EXTRA_VERIFIED) ? args.getInt(EXTRA_VERIFIED) : null; + mVerified = args.containsKey(ARG_VERIFIED) ? args.getInt(ARG_VERIFIED) : null; + mFingerprint = args.getByteArray(ARG_FINGERPRINT); mContext = getActivity(); + mInflater = getLayoutInflater(savedInstanceState); + } - public static Fragment newInstance(RawLinkedIdentity id, Integer isVerified) throws IOException { + public static Fragment newInstance(RawLinkedIdentity id, + Integer isVerified, byte[] fingerprint) throws IOException { LinkedIdViewFragment frag = new LinkedIdViewFragment(); Bundle args = new Bundle(); - args.putByteArray(EXTRA_ENCODED_LID, id.toUserAttribute().getEncoded()); + args.putByteArray(ARG_ENCODED_LID, id.toUserAttribute().getEncoded()); if (isVerified != null) { - args.putInt(EXTRA_VERIFIED, isVerified); + args.putInt(ARG_VERIFIED, isVerified); } + args.putByteArray(ARG_FINGERPRINT, fingerprint); frag.setArguments(args); return frag; @@ -78,6 +99,7 @@ public class LinkedIdViewFragment extends Fragment { View root = inflater.inflate(R.layout.linked_id_view_fragment, null); vLinkedIdsCard = (CardView) root.findViewById(R.id.card_linked_ids); + vLinkedCerts = (LinearLayout) root.findViewById(R.id.linked_id_certs); View back = root.findViewById(R.id.back_button); back.setClickable(true); @@ -136,6 +158,8 @@ public class LinkedIdViewFragment extends Fragment { button_view.setVisibility(View.GONE); } + mButtonSwitcher = (ViewAnimator) root.findViewById(R.id.button_animator); + View button_verify = root.findViewById(R.id.button_verify); button_verify.setOnClickListener(new OnClickListener() { @Override @@ -144,12 +168,88 @@ public class LinkedIdViewFragment extends Fragment { } }); + View button_retry = root.findViewById(R.id.button_retry); + button_retry.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + verifyResource(); + } + }); + + View button_confirm = root.findViewById(R.id.button_confirm); + button_confirm.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Notify.createNotify(getActivity(), "confirmed!", Notify.LENGTH_LONG, Style.INFO).show(); + } + }); + return root; } + static class ViewHolderCert { + final ViewAnimator vProgress; + final ImageView vIcon; + final TextView vText; + + ViewHolderCert(View view) { + vProgress = (ViewAnimator) view.findViewById(R.id.linked_cert_progress); + vIcon = (ImageView) view.findViewById(R.id.linked_cert_icon); + vText = (TextView) view.findViewById(R.id.linked_cert_text); + } + void setShowProgress(boolean show) { + vProgress.setDisplayedChild(show ? 0 : 1); + } + } + public void verifyResource() { - // TODO + // only one at a time + synchronized (this) { + if (mInProgress) { + return; + } + mInProgress = true; + } + + // is there a current certification? if not create a new one + final ViewHolderCert holder; + if (mCurrentCert == null) { + mCurrentCert = mInflater.inflate(R.layout.linked_id_cert, null); + holder = new ViewHolderCert(mCurrentCert); + mCurrentCert.setTag(holder); + vLinkedCerts.addView(mCurrentCert); + } else { + holder = (ViewHolderCert) mCurrentCert.getTag(); + } + + holder.setShowProgress(true); + holder.vText.setText("Verifying…"); + + new AsyncTask<Void,Void,LinkedVerifyResult>() { + @Override + protected LinkedVerifyResult doInBackground(Void... params) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // nvm + } + return mLinkedResource.verify(mFingerprint, mLinkedId.mNonce); + } + + @Override + protected void onPostExecute(LinkedVerifyResult result) { + holder.setShowProgress(false); + if (result.success()) { + mButtonSwitcher.setDisplayedChild(2); + holder.vText.setText("Ok"); + } else { + mButtonSwitcher.setDisplayedChild(1); + holder.vText.setText("Error"); + } + mInProgress = false; + } + }.execute(); } |