From f941431d634b1e008726ce5501ffed55cb6899de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 13 Aug 2014 21:49:04 +0200 Subject: Add user info dialog --- .../keychain/ui/ViewKeyMainFragment.java | 28 +++++++ .../keychain/ui/adapter/UserIdsAdapter.java | 25 ++---- .../ui/dialog/UserIdInfoDialogFragment.java | 95 ++++++++++++++++++++++ OpenKeychain/src/main/res/values/strings.xml | 8 ++ 4 files changed, 136 insertions(+), 20 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/UserIdInfoDialogFragment.java diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index 370a7312f..08243f06b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -22,17 +22,22 @@ import android.database.Cursor; import android.graphics.PorterDuff; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.Messenger; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ImageView; import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract; @@ -41,6 +46,8 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; +import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment; +import org.sufficientlysecure.keychain.ui.dialog.UserIdInfoDialogFragment; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Notify; @@ -88,9 +95,30 @@ public class ViewKeyMainFragment extends LoaderFragment implements PorterDuff.Mode.SRC_IN); mActionUpdate = view.findViewById(R.id.view_key_action_update); + mUserIds.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + showUserIdInfo(position); + } + }); + return root; } + private void showUserIdInfo(final int position) { + final boolean isRevoked = mUserIdsAdapter.getIsRevoked(position); + final int isVerified = mUserIdsAdapter.getIsVerified(position); + + DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { + public void run() { + UserIdInfoDialogFragment dialogFragment = + UserIdInfoDialogFragment.newInstance(isRevoked, isVerified); + + dialogFragment.show(getActivity().getSupportFragmentManager(), "userIdInfoDialog"); + } + }); + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java index 9bf47a387..717dcf818 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java @@ -257,6 +257,11 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC return mCursor.getInt(INDEX_IS_REVOKED) > 0; } + public int getIsVerified(int position) { + mCursor.moveToPosition(position); + return mCursor.getInt(INDEX_VERIFIED); + } + public boolean getIsRevokedPending(int position) { mCursor.moveToPosition(position); String userId = mCursor.getString(INDEX_USER_ID); @@ -280,24 +285,4 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC return view; } - // Disable selection of items for lists without checkboxes, http://stackoverflow.com/a/4075045 - @Override - public boolean areAllItemsEnabled() { - if (mCheckStates == null && mSaveKeyringParcel == null) { - return false; - } else { - return super.areAllItemsEnabled(); - } - } - - // Disable selection of items for lists without checkboxes, http://stackoverflow.com/a/4075045 - @Override - public boolean isEnabled(int position) { - if (mCheckStates == null && mSaveKeyringParcel == null) { - return false; - } else { - return super.isEnabled(position); - } - } - } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/UserIdInfoDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/UserIdInfoDialogFragment.java new file mode 100644 index 000000000..968b2429b --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/UserIdInfoDialogFragment.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.ui.dialog; + +import android.app.Activity; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.KeychainContract; + +public class UserIdInfoDialogFragment extends DialogFragment { + private static final String ARG_IS_REVOKED = "is_revoked"; + private static final String ARG_IS_VERIFIED = "is_verified"; + + /** + * Creates new instance of this dialog fragment + */ + public static UserIdInfoDialogFragment newInstance(boolean isRevoked, int isVerified) { + UserIdInfoDialogFragment frag = new UserIdInfoDialogFragment(); + Bundle args = new Bundle(); + args.putBoolean(ARG_IS_REVOKED, isRevoked); + args.putInt(ARG_IS_VERIFIED, isVerified); + + frag.setArguments(args); + + return frag; + } + + /** + * Creates dialog + */ + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final Activity activity = getActivity(); + + int isVerified = getArguments().getInt(ARG_IS_VERIFIED); + boolean isRevoked = getArguments().getBoolean(ARG_IS_REVOKED); + + CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); + + String title; + String message; + if (isRevoked) { + title = getString(R.string.user_id_info_revoked_title); + message = getString(R.string.user_id_info_revoked_text); + } else { + switch (isVerified) { + case KeychainContract.Certs.VERIFIED_SECRET: + title = getString(R.string.user_id_info_verified_title); + message = getString(R.string.user_id_info_verified_text); + break; + case KeychainContract.Certs.VERIFIED_SELF: + title = getString(R.string.user_id_info_not_verified_title); + message = getString(R.string.user_id_info_not_verified_text); + break; + default: + title = getString(R.string.user_id_info_invalid_title); + message = getString(R.string.user_id_info_invalid_text); + break; + } + } + + alert.setTitle(title); + alert.setMessage(message); + + alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int id) { + dismiss(); + } + }); + + return alert.show(); + } + +} diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 9d84d8840..352ca951c 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -429,6 +429,14 @@ Share Subkeys Certificates + Revoked + This identity has been revoked by the key owner. It is no longer valid. + Verified + This identity has been verified. + Not verified + This identity has not been verified yet. You can not be sure if the identity really corresponds to a specific person. + Invalid + Something is wrong with this identity! Change Passphrase -- cgit v1.2.3