mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-31 15:10:19 -05:00
ViewKeyMainFragment cleanup (don't use inline queries!)
This commit is contained in:
parent
958eba1c95
commit
53e8afaee0
@ -73,6 +73,7 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
private ListView mUserIds;
|
private ListView mUserIds;
|
||||||
private ListView mKeys;
|
private ListView mKeys;
|
||||||
|
|
||||||
|
private static final int LOADER_ID_UNIFIED = 0;
|
||||||
private static final int LOADER_ID_USER_IDS = 1;
|
private static final int LOADER_ID_USER_IDS = 1;
|
||||||
private static final int LOADER_ID_KEYS = 2;
|
private static final int LOADER_ID_KEYS = 2;
|
||||||
|
|
||||||
@ -131,28 +132,108 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
|
|
||||||
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
|
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
|
||||||
|
|
||||||
{ // label whether secret key is available, and edit button if it is
|
mActionEncrypt.setOnClickListener(new View.OnClickListener() {
|
||||||
final long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), mDataUri);
|
@Override
|
||||||
// TODO do this some other way...
|
public void onClick(View v) {
|
||||||
if (ProviderHelper.hasSecretKeyByMasterKeyId(getActivity(), masterKeyId)) {
|
encryptToContact(mDataUri);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mActionCertify.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
certifyKey(mDataUri);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mUserIdsAdapter = new ViewKeyUserIdsAdapter(getActivity(), null, 0);
|
||||||
|
mUserIds.setAdapter(mUserIdsAdapter);
|
||||||
|
|
||||||
|
mKeysAdapter = new ViewKeyKeysAdapter(getActivity(), null, 0);
|
||||||
|
mKeys.setAdapter(mKeysAdapter);
|
||||||
|
|
||||||
|
// Prepare the loaders. Either re-connect with an existing ones,
|
||||||
|
// or start new ones.
|
||||||
|
getActivity().getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
|
||||||
|
getActivity().getSupportLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
|
||||||
|
getActivity().getSupportLoaderManager().initLoader(LOADER_ID_KEYS, null, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final String[] UNIFIED_PROJECTION = new String[] {
|
||||||
|
KeyRings._ID, KeyRings.MASTER_KEY_ID, KeyRings.HAS_SECRET,
|
||||||
|
KeyRings.USER_ID, KeyRings.FINGERPRINT,
|
||||||
|
KeyRings.ALGORITHM, KeyRings.KEY_SIZE, KeyRings.CREATION, KeyRings.EXPIRY,
|
||||||
|
|
||||||
|
};
|
||||||
|
static final int INDEX_UNIFIED_MKI = 1;
|
||||||
|
static final int INDEX_UNIFIED_HAS_SECRET = 2;
|
||||||
|
static final int INDEX_UNIFIED_UID = 3;
|
||||||
|
static final int INDEX_UNIFIED_FINGERPRINT = 4;
|
||||||
|
static final int INDEX_UNIFIED_ALGORITHM = 5;
|
||||||
|
static final int INDEX_UNIFIED_KEY_SIZE = 6;
|
||||||
|
static final int INDEX_UNIFIED_CREATION = 7;
|
||||||
|
static final int INDEX_UNIFIED_EXPIRY = 8;
|
||||||
|
|
||||||
|
static final String[] USER_IDS_PROJECTION = new String[] {
|
||||||
|
UserIds._ID, UserIds.USER_ID, UserIds.RANK,
|
||||||
|
};
|
||||||
|
|
||||||
|
static final String[] KEYS_PROJECTION = new String[] {
|
||||||
|
Keys._ID,
|
||||||
|
Keys.KEY_ID, Keys.RANK, Keys.ALGORITHM, Keys.KEY_SIZE,
|
||||||
|
Keys.CAN_CERTIFY, Keys.CAN_ENCRYPT, Keys.CAN_SIGN, Keys.IS_REVOKED,
|
||||||
|
Keys.CREATION, Keys.EXPIRY, Keys.FINGERPRINT
|
||||||
|
};
|
||||||
|
static final int KEYS_INDEX_CAN_ENCRYPT = 6;
|
||||||
|
|
||||||
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
|
switch (id) {
|
||||||
|
case LOADER_ID_UNIFIED: {
|
||||||
|
Uri baseUri = KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
||||||
|
return new CursorLoader(getActivity(), baseUri, UNIFIED_PROJECTION, null, null, null);
|
||||||
|
}
|
||||||
|
case LOADER_ID_USER_IDS: {
|
||||||
|
Uri baseUri = UserIds.buildUserIdsUri(mDataUri);
|
||||||
|
return new CursorLoader(getActivity(), baseUri, USER_IDS_PROJECTION, null, null, null);
|
||||||
|
}
|
||||||
|
case LOADER_ID_KEYS: {
|
||||||
|
Uri baseUri = Keys.buildKeysUri(mDataUri);
|
||||||
|
return new CursorLoader(getActivity(), baseUri, KEYS_PROJECTION, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||||
|
// Swap the new cursor in. (The framework will take care of closing the
|
||||||
|
// old cursor once we return.)
|
||||||
|
switch (loader.getId()) {
|
||||||
|
case LOADER_ID_UNIFIED: {
|
||||||
|
if (data.moveToFirst()) {
|
||||||
|
// get name, email, and comment from USER_ID
|
||||||
|
String[] mainUserId = PgpKeyHelper.splitUserId(data.getString(INDEX_UNIFIED_UID));
|
||||||
|
if (mainUserId[0] != null) {
|
||||||
|
getActivity().setTitle(mainUserId[0]);
|
||||||
|
mName.setText(mainUserId[0]);
|
||||||
|
} else {
|
||||||
|
getActivity().setTitle(R.string.user_id_no_name);
|
||||||
|
mName.setText(R.string.user_id_no_name);
|
||||||
|
}
|
||||||
|
mEmail.setText(mainUserId[1]);
|
||||||
|
mComment.setText(mainUserId[2]);
|
||||||
|
|
||||||
|
if (data.getInt(INDEX_UNIFIED_HAS_SECRET) > 0) {
|
||||||
// set this attribute. this is a LITTLE unclean, but we have the info available
|
// set this attribute. this is a LITTLE unclean, but we have the info available
|
||||||
// right here, so why not.
|
// right here, so why not.
|
||||||
mSecretKey.setTextColor(getResources().getColor(R.color.emphasis));
|
mSecretKey.setTextColor(getResources().getColor(R.color.emphasis));
|
||||||
mSecretKey.setText(R.string.secret_key_yes);
|
mSecretKey.setText(R.string.secret_key_yes);
|
||||||
|
|
||||||
// certify button
|
|
||||||
// TODO this button MIGHT be useful if the user wants to
|
|
||||||
// certify a private key with another...
|
|
||||||
// mActionCertify.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
// edit button
|
// edit button
|
||||||
mActionEdit.setVisibility(View.VISIBLE);
|
mActionEdit.setVisibility(View.VISIBLE);
|
||||||
mActionEdit.setOnClickListener(new View.OnClickListener() {
|
mActionEdit.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
|
Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
|
||||||
editIntent.setData(
|
editIntent.setData(mDataUri);
|
||||||
KeyRingData.buildSecretKeyRingUri(
|
|
||||||
Long.toString(masterKeyId)));
|
|
||||||
editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
|
editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
|
||||||
startActivityForResult(editIntent, 0);
|
startActivityForResult(editIntent, 0);
|
||||||
}
|
}
|
||||||
@ -167,118 +248,16 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
mActionEdit.setVisibility(View.GONE);
|
mActionEdit.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO see todo note above, doing this here for now
|
|
||||||
mActionCertify.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View view) {
|
|
||||||
certifyKey(KeyRings.buildGenericKeyRingUri(
|
|
||||||
Long.toString(masterKeyId)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
mActionEncrypt.setOnClickListener(new View.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
encryptToContact(mDataUri);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mUserIdsAdapter = new ViewKeyUserIdsAdapter(getActivity(), null, 0);
|
|
||||||
mUserIds.setAdapter(mUserIdsAdapter);
|
|
||||||
|
|
||||||
mKeysAdapter = new ViewKeyKeysAdapter(getActivity(), null, 0);
|
|
||||||
mKeys.setAdapter(mKeysAdapter);
|
|
||||||
|
|
||||||
// Prepare the loaders. Either re-connect with an existing ones,
|
|
||||||
// or start new ones.
|
|
||||||
getActivity().getSupportLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
|
|
||||||
getActivity().getSupportLoaderManager().initLoader(LOADER_ID_KEYS, null, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
static final String[] USER_IDS_PROJECTION =
|
|
||||||
new String[] {
|
|
||||||
UserIds._ID,
|
|
||||||
UserIds.USER_ID,
|
|
||||||
UserIds.RANK,
|
|
||||||
};
|
|
||||||
static final int INDEX_UID_UID = 1;
|
|
||||||
|
|
||||||
static final String[] KEYS_PROJECTION = new String[] {
|
|
||||||
Keys._ID,
|
|
||||||
Keys.KEY_ID, Keys.RANK,
|
|
||||||
Keys.ALGORITHM, Keys.KEY_SIZE,
|
|
||||||
Keys.CAN_CERTIFY, Keys.CAN_ENCRYPT,
|
|
||||||
Keys.CAN_SIGN, Keys.IS_REVOKED,
|
|
||||||
Keys.CREATION, Keys.EXPIRY,
|
|
||||||
Keys.FINGERPRINT
|
|
||||||
};
|
|
||||||
static final int KEYS_INDEX_KEY_ID = 1;
|
|
||||||
static final int KEYS_INDEX_ALGORITHM = 3;
|
|
||||||
static final int KEYS_INDEX_KEY_SIZE = 4;
|
|
||||||
static final int KEYS_INDEX_CAN_ENCRYPT = 6;
|
|
||||||
static final int KEYS_INDEX_CREATION = 9;
|
|
||||||
static final int KEYS_INDEX_EXPIRY = 10;
|
|
||||||
static final int KEYS_INDEX_FINGERPRINT = 11;
|
|
||||||
|
|
||||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
|
||||||
switch (id) {
|
|
||||||
case LOADER_ID_USER_IDS: {
|
|
||||||
Uri baseUri = UserIds.buildUserIdsUri(mDataUri);
|
|
||||||
|
|
||||||
// Now create and return a CursorLoader that will take care of
|
|
||||||
// creating a Cursor for the data being displayed.
|
|
||||||
return new CursorLoader(getActivity(), baseUri, USER_IDS_PROJECTION, null, null, null);
|
|
||||||
}
|
|
||||||
case LOADER_ID_KEYS: {
|
|
||||||
Uri baseUri = Keys.buildKeysUri(mDataUri);
|
|
||||||
|
|
||||||
// Now create and return a CursorLoader that will take care of
|
|
||||||
// creating a Cursor for the data being displayed.
|
|
||||||
return new CursorLoader(getActivity(), baseUri, KEYS_PROJECTION, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
|
||||||
// Swap the new cursor in. (The framework will take care of closing the
|
|
||||||
// old cursor once we return.)
|
|
||||||
switch (loader.getId()) {
|
|
||||||
case LOADER_ID_USER_IDS:
|
|
||||||
if (data.moveToFirst()) {
|
|
||||||
// get name, email, and comment from USER_ID
|
|
||||||
String[] mainUserId = PgpKeyHelper.splitUserId(data
|
|
||||||
.getString(INDEX_UID_UID));
|
|
||||||
if (mainUserId[0] != null) {
|
|
||||||
getActivity().setTitle(mainUserId[0]);
|
|
||||||
mName.setText(mainUserId[0]);
|
|
||||||
} else {
|
|
||||||
getActivity().setTitle(R.string.user_id_no_name);
|
|
||||||
mName.setText(R.string.user_id_no_name);
|
|
||||||
}
|
|
||||||
mEmail.setText(mainUserId[1]);
|
|
||||||
mComment.setText(mainUserId[2]);
|
|
||||||
}
|
|
||||||
mUserIdsAdapter.swapCursor(data);
|
|
||||||
break;
|
|
||||||
case LOADER_ID_KEYS:
|
|
||||||
// the first key here is our master key
|
|
||||||
if (data.moveToFirst()) {
|
|
||||||
// get key id from MASTER_KEY_ID
|
// get key id from MASTER_KEY_ID
|
||||||
long keyId = data.getLong(KEYS_INDEX_KEY_ID);
|
long masterKeyId = data.getLong(INDEX_UNIFIED_MKI);
|
||||||
String keyIdStr = PgpKeyHelper.convertKeyIdToHex(keyId);
|
String keyIdStr = PgpKeyHelper.convertKeyIdToHex(masterKeyId);
|
||||||
mKeyId.setText(keyIdStr);
|
mKeyId.setText(keyIdStr);
|
||||||
|
|
||||||
// get creation date from CREATION
|
// get creation date from CREATION
|
||||||
if (data.isNull(KEYS_INDEX_CREATION)) {
|
if (data.isNull(INDEX_UNIFIED_CREATION)) {
|
||||||
mCreation.setText(R.string.none);
|
mCreation.setText(R.string.none);
|
||||||
} else {
|
} else {
|
||||||
Date creationDate = new Date(data.getLong(KEYS_INDEX_CREATION) * 1000);
|
Date creationDate = new Date(data.getLong(INDEX_UNIFIED_CREATION) * 1000);
|
||||||
|
|
||||||
mCreation.setText(
|
mCreation.setText(
|
||||||
DateFormat.getDateFormat(getActivity().getApplicationContext()).format(
|
DateFormat.getDateFormat(getActivity().getApplicationContext()).format(
|
||||||
@ -286,10 +265,10 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get expiry date from EXPIRY
|
// get expiry date from EXPIRY
|
||||||
if (data.isNull(KEYS_INDEX_EXPIRY)) {
|
if (data.isNull(INDEX_UNIFIED_EXPIRY)) {
|
||||||
mExpiry.setText(R.string.none);
|
mExpiry.setText(R.string.none);
|
||||||
} else {
|
} else {
|
||||||
Date expiryDate = new Date(data.getLong(KEYS_INDEX_EXPIRY) * 1000);
|
Date expiryDate = new Date(data.getLong(INDEX_UNIFIED_EXPIRY) * 1000);
|
||||||
|
|
||||||
mExpiry.setText(
|
mExpiry.setText(
|
||||||
DateFormat.getDateFormat(getActivity().getApplicationContext()).format(
|
DateFormat.getDateFormat(getActivity().getApplicationContext()).format(
|
||||||
@ -297,15 +276,22 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
String algorithmStr = PgpKeyHelper.getAlgorithmInfo(
|
String algorithmStr = PgpKeyHelper.getAlgorithmInfo(
|
||||||
data.getInt(KEYS_INDEX_ALGORITHM), data.getInt(KEYS_INDEX_KEY_SIZE));
|
data.getInt(INDEX_UNIFIED_ALGORITHM), data.getInt(INDEX_UNIFIED_KEY_SIZE));
|
||||||
mAlgorithm.setText(algorithmStr);
|
mAlgorithm.setText(algorithmStr);
|
||||||
|
|
||||||
byte[] fingerprintBlob = data.getBlob(KEYS_INDEX_FINGERPRINT);
|
byte[] fingerprintBlob = data.getBlob(INDEX_UNIFIED_FINGERPRINT);
|
||||||
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
|
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
|
||||||
|
|
||||||
mFingerprint.setText(PgpKeyHelper.colorizeFingerprint(fingerprint));
|
mFingerprint.setText(PgpKeyHelper.colorizeFingerprint(fingerprint));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case LOADER_ID_USER_IDS:
|
||||||
|
mUserIdsAdapter.swapCursor(data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOADER_ID_KEYS:
|
||||||
// hide encrypt button if no encryption key is available
|
// hide encrypt button if no encryption key is available
|
||||||
boolean canEncrypt = false;
|
boolean canEncrypt = false;
|
||||||
data.moveToFirst();
|
data.moveToFirst();
|
||||||
@ -321,9 +307,6 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
|
|
||||||
mKeysAdapter.swapCursor(data);
|
mKeysAdapter.swapCursor(data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
getActivity().setProgressBarIndeterminateVisibility(Boolean.FALSE);
|
getActivity().setProgressBarIndeterminateVisibility(Boolean.FALSE);
|
||||||
mContainer.setVisibility(View.VISIBLE);
|
mContainer.setVisibility(View.VISIBLE);
|
||||||
@ -341,8 +324,6 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
case LOADER_ID_KEYS:
|
case LOADER_ID_KEYS:
|
||||||
mKeysAdapter.swapCursor(null);
|
mKeysAdapter.swapCursor(null);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user