Add user info dialog

This commit is contained in:
Dominik Schürmann 2014-08-13 21:49:04 +02:00
parent c7d5b09286
commit f941431d63
4 changed files with 136 additions and 20 deletions

View File

@ -22,17 +22,22 @@ import android.database.Cursor;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; 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.app.LoaderManager;
import android.support.v4.content.CursorLoader; import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract; 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;
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; 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.Log;
import org.sufficientlysecure.keychain.util.Notify; import org.sufficientlysecure.keychain.util.Notify;
@ -88,9 +95,30 @@ public class ViewKeyMainFragment extends LoaderFragment implements
PorterDuff.Mode.SRC_IN); PorterDuff.Mode.SRC_IN);
mActionUpdate = view.findViewById(R.id.view_key_action_update); 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; 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 @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);

View File

@ -257,6 +257,11 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
return mCursor.getInt(INDEX_IS_REVOKED) > 0; 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) { public boolean getIsRevokedPending(int position) {
mCursor.moveToPosition(position); mCursor.moveToPosition(position);
String userId = mCursor.getString(INDEX_USER_ID); String userId = mCursor.getString(INDEX_USER_ID);
@ -280,24 +285,4 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC
return view; 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);
}
}
} }

View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -429,6 +429,14 @@
<string name="key_view_tab_share">Share</string> <string name="key_view_tab_share">Share</string>
<string name="key_view_tab_keys">Subkeys</string> <string name="key_view_tab_keys">Subkeys</string>
<string name="key_view_tab_certs">Certificates</string> <string name="key_view_tab_certs">Certificates</string>
<string name="user_id_info_revoked_title">Revoked</string>
<string name="user_id_info_revoked_text">This identity has been revoked by the key owner. It is no longer valid.</string>
<string name="user_id_info_verified_title">Verified</string>
<string name="user_id_info_verified_text">This identity has been verified.</string>
<string name="user_id_info_not_verified_title">Not verified</string>
<string name="user_id_info_not_verified_text">This identity has not been verified yet. You can not be sure if the identity really corresponds to a specific person.</string>
<string name="user_id_info_invalid_title">Invalid</string>
<string name="user_id_info_invalid_text">Something is wrong with this identity!</string>
<!-- Edit key --> <!-- Edit key -->
<string name="edit_key_action_change_passphrase">Change Passphrase</string> <string name="edit_key_action_change_passphrase">Change Passphrase</string>