diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2015-03-05 18:05:48 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2015-03-05 18:05:48 +0100 |
commit | a2419aa688afb61c02a1fcd4a8d1df46fdd97b5e (patch) | |
tree | a9c71b15629fcc4fefeb112d24475b011f3c58fc /OpenKeychain | |
parent | 5d2c81d715cf1fd9ff23a8d1aa43fcfb58f7d099 (diff) | |
download | open-keychain-a2419aa688afb61c02a1fcd4a8d1df46fdd97b5e.tar.gz open-keychain-a2419aa688afb61c02a1fcd4a8d1df46fdd97b5e.tar.bz2 open-keychain-a2419aa688afb61c02a1fcd4a8d1df46fdd97b5e.zip |
work on LinkedIdViewFragment
Diffstat (limited to 'OpenKeychain')
12 files changed, 178 insertions, 105 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedIdentity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedIdentity.java index 35813b8b3..ff5995329 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedIdentity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedIdentity.java @@ -13,6 +13,7 @@ import java.nio.ByteBuffer; import java.util.Arrays; import android.content.Context; +import android.content.Intent; import android.support.annotation.DrawableRes; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedResource.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedResource.java index 28f40f0d7..095fd4ac7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedResource.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/LinkedResource.java @@ -13,6 +13,7 @@ import java.util.Set; import java.util.regex.Pattern; import android.content.Context; +import android.content.Intent; import android.support.annotation.DrawableRes; public abstract class LinkedResource { @@ -105,5 +106,11 @@ public abstract class LinkedResource { public abstract @DrawableRes int getDisplayIcon(); public abstract String getDisplayTitle(Context context); public abstract String getDisplayComment(Context context); + public boolean isViewable() { + return false; + } + public Intent getViewIntent() { + return null; + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/RawLinkedIdentity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/RawLinkedIdentity.java index 0de55ac38..8b014db1d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/RawLinkedIdentity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/RawLinkedIdentity.java @@ -8,6 +8,7 @@ import java.net.URI; import java.nio.ByteBuffer; import android.content.Context; +import android.content.Intent; import android.support.annotation.DrawableRes; /** The RawLinkedIdentity contains raw parsed data from a Linked Identity subpacket. */ diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/DnsResource.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/DnsResource.java index 8f16aa24d..cd0706ff3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/DnsResource.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/DnsResource.java @@ -110,11 +110,11 @@ public class DnsResource extends LinkedCookieResource { @Override public String getDisplayTitle(Context context) { - return "dns"; + return "Domain Name"; } @Override public String getDisplayComment(Context context) { - return null; + return mFqdn; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/GenericHttpsResource.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/GenericHttpsResource.java index 7d4a38fe4..0ab90af75 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/GenericHttpsResource.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/resources/GenericHttpsResource.java @@ -1,6 +1,8 @@ package org.sufficientlysecure.keychain.pgp.linked.resources; import android.content.Context; +import android.content.Intent; +import android.net.Uri; import android.support.annotation.DrawableRes; import com.textuality.keybase.lib.Search; @@ -109,12 +111,23 @@ public class GenericHttpsResource extends LinkedCookieResource { @Override public String getDisplayTitle(Context context) { - return "https"; + return "Website (HTTPS)"; } @Override public String getDisplayComment(Context context) { - return null; + return mSubUri.toString(); } + @Override + public boolean isViewable() { + return true; + } + + @Override + public Intent getViewIntent() { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(mSubUri.toString())); + return intent; + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 2ff4803fb..fc5275713 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -39,7 +39,6 @@ import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.operations.ImportExportOperation; import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; -import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; @@ -54,7 +53,6 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.pgp.WrappedSignature; -import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAllowedKeys; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; @@ -62,15 +60,11 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; -import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; import org.sufficientlysecure.keychain.remote.AccountSettings; import org.sufficientlysecure.keychain.remote.AppSettings; -import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; -import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; -import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.ProgressFixedScaler; import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.Utf8Util; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java index 302bd6be4..311e1d0ee 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java @@ -18,6 +18,8 @@ package org.sufficientlysecure.keychain.ui; +import java.io.IOException; + import android.database.Cursor; import android.net.Uri; import android.os.Build; @@ -45,6 +47,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.ui.adapter.LinkedIdsAdapter; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.UserIdInfoDialogFragment; +import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; public class ViewKeyFragment extends LoaderFragment implements @@ -107,7 +110,13 @@ public class ViewKeyFragment extends LoaderFragment implements } private void showLinkedId(final int position) { - Fragment frag = mLinkedIdsAdapter.getLinkedIdFragment(position); + Fragment frag; + try { + frag = mLinkedIdsAdapter.getLinkedIdFragment(position); + } catch (IOException e) { + e.printStackTrace(); + return; + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Transition trans = TransitionInflater.from(getActivity()) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/LinkedIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/LinkedIdsAdapter.java index 031972918..7383db1b0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/LinkedIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/LinkedIdsAdapter.java @@ -125,26 +125,35 @@ public class LinkedIdsAdapter extends UserAttributesAdapter { UserIdsAdapter.USER_PACKETS_PROJECTION, LINKED_IDS_WHERE, null, null); } - public Fragment getLinkedIdFragment(int position) { + public Fragment getLinkedIdFragment(int position) throws IOException { RawLinkedIdentity id = getItem(position); - return LinkedIdViewFragment.newInstance(id); + Integer isVerified; + if (mShowCertification) { + Cursor cursor = getCursor(); + cursor.moveToPosition(position); + isVerified = cursor.getInt(INDEX_VERIFIED); + } else { + isVerified = null; + } + + return LinkedIdViewFragment.newInstance(id, isVerified); } - static class ViewHolder { - ImageView vVerified; - ImageView vIcon; - TextView vTitle; - TextView vComment; + public static class ViewHolder { + final public ImageView vVerified; + final public ImageView vIcon; + final public TextView vTitle; + final public TextView vComment; - ViewHolder(View view) { + public ViewHolder(View view) { vVerified = (ImageView) view.findViewById(R.id.user_id_item_certified); vIcon = (ImageView) view.findViewById(R.id.linked_id_type_icon); vTitle = (TextView) view.findViewById(R.id.linked_id_title); vComment = (TextView) view.findViewById(R.id.linked_id_comment); } - void setData(Context context, RawLinkedIdentity id) { + public void setData(Context context, RawLinkedIdentity id) { vTitle.setText(id.getDisplayTitle(context)); 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 0eb0dcd45..b526776f0 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 @@ -1,5 +1,9 @@ package org.sufficientlysecure.keychain.ui.linked; +import java.io.IOException; + +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.CardView; @@ -9,17 +13,61 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource; +import org.sufficientlysecure.keychain.pgp.linked.LinkedIdentity; +import org.sufficientlysecure.keychain.pgp.linked.LinkedResource; import org.sufficientlysecure.keychain.pgp.linked.RawLinkedIdentity; +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; public class LinkedIdViewFragment extends Fragment { - private CardView mLinkedIdsCard; + private static final String EXTRA_ENCODED_LID = "encoded_lid"; + private static final String EXTRA_VERIFIED = "verified"; + + private RawLinkedIdentity mLinkedId; + private LinkedCookieResource mLinkedResource; + private Integer mVerified; + + private CardView vLinkedIdsCard; + private Context mContext; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Bundle args = getArguments(); + byte[] data = args.getByteArray(EXTRA_ENCODED_LID); + + try { + mLinkedId = LinkedIdentity.fromAttributeData(data); + } catch (IOException e) { + // TODO um… + e.printStackTrace(); + throw new AssertionError("reconstruction of user attribute must succeed!"); + } - public static Fragment newInstance(RawLinkedIdentity id) { + if (mLinkedId instanceof LinkedIdentity) { + LinkedResource res = ((LinkedIdentity) mLinkedId).mResource; + mLinkedResource = (LinkedCookieResource) res; + } + + mVerified = args.containsKey(EXTRA_VERIFIED) ? args.getInt(EXTRA_VERIFIED) : null; + + mContext = getActivity(); + } + + public static Fragment newInstance(RawLinkedIdentity id, Integer isVerified) throws IOException { LinkedIdViewFragment frag = new LinkedIdViewFragment(); Bundle args = new Bundle(); + args.putByteArray(EXTRA_ENCODED_LID, id.toUserAttribute().getEncoded()); + if (isVerified != null) { + args.putInt(EXTRA_VERIFIED, isVerified); + } frag.setArguments(args); return frag; @@ -29,17 +77,80 @@ public class LinkedIdViewFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup superContainer, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.linked_id_view_fragment, null); - mLinkedIdsCard = (CardView) root.findViewById(R.id.card_linked_ids); + vLinkedIdsCard = (CardView) root.findViewById(R.id.card_linked_ids); - root.findViewById(R.id.back_button).setClickable(true); - root.findViewById(R.id.back_button).setOnClickListener(new OnClickListener() { + View back = root.findViewById(R.id.back_button); + back.setClickable(true); + back.findViewById(R.id.back_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getFragmentManager().popBackStack(); } }); + ViewHolder holder = new ViewHolder(root); + + if (mVerified != null) { + holder.vVerified.setVisibility(View.VISIBLE); + switch (mVerified) { + case Certs.VERIFIED_SECRET: + KeyFormattingUtils.setStatusImage(mContext, holder.vVerified, + null, State.VERIFIED, KeyFormattingUtils.DEFAULT_COLOR); + break; + case Certs.VERIFIED_SELF: + KeyFormattingUtils.setStatusImage(mContext, holder.vVerified, + null, State.UNVERIFIED, KeyFormattingUtils.DEFAULT_COLOR); + break; + default: + KeyFormattingUtils.setStatusImage(mContext, holder.vVerified, + null, State.INVALID, KeyFormattingUtils.DEFAULT_COLOR); + break; + } + } else { + holder.vVerified.setVisibility(View.GONE); + } + + holder.setData(mContext, mLinkedId); + + // no resource, nothing further we can do… + if (mLinkedResource == null) { + root.findViewById(R.id.button_view).setVisibility(View.GONE); + root.findViewById(R.id.button_verify).setVisibility(View.GONE); + return root; + } + + View button_view = root.findViewById(R.id.button_view); + if (mLinkedResource.isViewable()) { + button_view.setVisibility(View.VISIBLE); + button_view.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = mLinkedResource.getViewIntent(); + if (intent == null) { + return; + } + getActivity().startActivity(intent); + } + }); + } else { + button_view.setVisibility(View.GONE); + } + + View button_verify = root.findViewById(R.id.button_verify); + button_verify.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + verifyResource(); + } + }); + return root; } + public void verifyResource() { + + // TODO + + } + } diff --git a/OpenKeychain/src/main/res/layout/linked_id_item.xml b/OpenKeychain/src/main/res/layout/linked_id_item.xml index 52e7fceb5..312dee6ba 100644 --- a/OpenKeychain/src/main/res/layout/linked_id_item.xml +++ b/OpenKeychain/src/main/res/layout/linked_id_item.xml @@ -13,7 +13,8 @@ android:layout_marginLeft="14dp" android:layout_marginStart="14dp" android:src="@drawable/dns" - android:layout_gravity="center_vertical" /> + android:layout_gravity="center_vertical" + android:scaleType="fitCenter" /> <LinearLayout android:orientation="vertical" @@ -46,8 +47,8 @@ android:id="@+id/user_id_item_certified_layout" android:layout_width="22dp" android:layout_height="wrap_content" - android:layout_marginRight="8dp" - android:layout_marginEnd="8dp" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" android:layout_gravity="center_vertical" android:orientation="vertical"> diff --git a/OpenKeychain/src/main/res/layout/linked_id_item_unknown.xml b/OpenKeychain/src/main/res/layout/linked_id_item_unknown.xml deleted file mode 100644 index d80b814ca..000000000 --- a/OpenKeychain/src/main/res/layout/linked_id_item_unknown.xml +++ /dev/null @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:minHeight="?android:attr/listPreferredItemHeight" - android:orientation="horizontal" - android:singleLine="true"> - - <LinearLayout - android:orientation="vertical" - android:layout_gravity="center_vertical" - android:layout_width="0dip" - android:layout_marginLeft="8dp" - android:layout_marginTop="4dp" - android:layout_marginBottom="4dp" - android:layout_height="wrap_content" - android:layout_weight="1"> - - <TextView - android:id="@+id/linked_id_uri" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="uri" - android:textAppearance="?android:attr/textAppearanceMedium" /> - - <TextView - android:id="@+id/user_id_item_comment" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:textColor="@color/tertiary_text_light" - android:text="unknown linked identity type" - android:textAppearance="?android:attr/textAppearanceSmall" /> - - </LinearLayout> - - <LinearLayout - android:id="@+id/user_id_item_certified_layout" - android:layout_width="22dp" - android:layout_height="wrap_content" - android:layout_marginRight="12dp" - android:layout_marginEnd="12dp" - android:layout_gravity="center_vertical" - android:orientation="vertical"> - - <ImageView - android:id="@+id/user_id_item_certified" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:src="@drawable/status_signature_unverified_cutout_24dp" - android:layout_gravity="center_horizontal" /> - - </LinearLayout> - -</LinearLayout> diff --git a/OpenKeychain/src/main/res/layout/linked_id_view_fragment.xml b/OpenKeychain/src/main/res/layout/linked_id_view_fragment.xml index c260a35d3..abd71416f 100644 --- a/OpenKeychain/src/main/res/layout/linked_id_view_fragment.xml +++ b/OpenKeychain/src/main/res/layout/linked_id_view_fragment.xml @@ -29,28 +29,7 @@ android:layout_height="wrap_content" android:text="Linked Identity" /> - <LinearLayout - android:layout_width="fill_parent" - android:layout_height="wrap_content"> - - <ImageView - android:minHeight="?android:attr/listPreferredItemHeight" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:id="@+id/linked_id_type_icon" - android:layout_marginLeft="14dp" - android:layout_marginStart="14dp" - android:src="@drawable/dns" /> - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginLeft="14dp" - android:layout_marginStart="14dp" - android:text="This is a DNS linked identity~\nLorem ipsum\nmore text\neven more text\nyoooyoyo" - android:layout_gravity="center_vertical" /> - - </LinearLayout> + <include layout="@layout/linked_id_item" /> <LinearLayout android:layout_width="match_parent" @@ -65,11 +44,12 @@ style="?android:attr/borderlessButtonStyle" /> <Space - android:layout_width="wrap_content" + android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> <Button + android:id="@+id/button_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="View" @@ -78,6 +58,7 @@ /> <Button + android:id="@+id/verify_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Verify" |