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 mKeys;
|
||||
|
||||
private static final int LOADER_ID_UNIFIED = 0;
|
||||
private static final int LOADER_ID_USER_IDS = 1;
|
||||
private static final int LOADER_ID_KEYS = 2;
|
||||
|
||||
@ -131,60 +132,17 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
|
||||
Log.i(Constants.TAG, "mDataUri: " + mDataUri.toString());
|
||||
|
||||
{ // label whether secret key is available, and edit button if it is
|
||||
final long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), mDataUri);
|
||||
// TODO do this some other way...
|
||||
if (ProviderHelper.hasSecretKeyByMasterKeyId(getActivity(), masterKeyId)) {
|
||||
// set this attribute. this is a LITTLE unclean, but we have the info available
|
||||
// right here, so why not.
|
||||
mSecretKey.setTextColor(getResources().getColor(R.color.emphasis));
|
||||
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
|
||||
mActionEdit.setVisibility(View.VISIBLE);
|
||||
mActionEdit.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
|
||||
editIntent.setData(
|
||||
KeyRingData.buildSecretKeyRingUri(
|
||||
Long.toString(masterKeyId)));
|
||||
editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
|
||||
startActivityForResult(editIntent, 0);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mSecretKey.setTextColor(Color.BLACK);
|
||||
mSecretKey.setText(getResources().getString(R.string.secret_key_no));
|
||||
|
||||
// certify button
|
||||
mActionCertify.setVisibility(View.VISIBLE);
|
||||
// edit button
|
||||
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);
|
||||
}
|
||||
});
|
||||
mActionCertify.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
certifyKey(mDataUri);
|
||||
}
|
||||
});
|
||||
|
||||
mUserIdsAdapter = new ViewKeyUserIdsAdapter(getActivity(), null, 0);
|
||||
mUserIds.setAdapter(mUserIdsAdapter);
|
||||
@ -194,49 +152,50 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
|
||||
// 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[] USER_IDS_PROJECTION =
|
||||
new String[] {
|
||||
UserIds._ID,
|
||||
UserIds.USER_ID,
|
||||
UserIds.RANK,
|
||||
};
|
||||
static final int INDEX_UID_UID = 1;
|
||||
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
|
||||
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_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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -249,11 +208,10 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
// 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:
|
||||
case LOADER_ID_UNIFIED: {
|
||||
if (data.moveToFirst()) {
|
||||
// get name, email, and comment from USER_ID
|
||||
String[] mainUserId = PgpKeyHelper.splitUserId(data
|
||||
.getString(INDEX_UID_UID));
|
||||
String[] mainUserId = PgpKeyHelper.splitUserId(data.getString(INDEX_UNIFIED_UID));
|
||||
if (mainUserId[0] != null) {
|
||||
getActivity().setTitle(mainUserId[0]);
|
||||
mName.setText(mainUserId[0]);
|
||||
@ -263,22 +221,43 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
}
|
||||
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()) {
|
||||
|
||||
if (data.getInt(INDEX_UNIFIED_HAS_SECRET) > 0) {
|
||||
// set this attribute. this is a LITTLE unclean, but we have the info available
|
||||
// right here, so why not.
|
||||
mSecretKey.setTextColor(getResources().getColor(R.color.emphasis));
|
||||
mSecretKey.setText(R.string.secret_key_yes);
|
||||
|
||||
// edit button
|
||||
mActionEdit.setVisibility(View.VISIBLE);
|
||||
mActionEdit.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
|
||||
editIntent.setData(mDataUri);
|
||||
editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
|
||||
startActivityForResult(editIntent, 0);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mSecretKey.setTextColor(Color.BLACK);
|
||||
mSecretKey.setText(getResources().getString(R.string.secret_key_no));
|
||||
|
||||
// certify button
|
||||
mActionCertify.setVisibility(View.VISIBLE);
|
||||
// edit button
|
||||
mActionEdit.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// get key id from MASTER_KEY_ID
|
||||
long keyId = data.getLong(KEYS_INDEX_KEY_ID);
|
||||
String keyIdStr = PgpKeyHelper.convertKeyIdToHex(keyId);
|
||||
long masterKeyId = data.getLong(INDEX_UNIFIED_MKI);
|
||||
String keyIdStr = PgpKeyHelper.convertKeyIdToHex(masterKeyId);
|
||||
mKeyId.setText(keyIdStr);
|
||||
|
||||
// get creation date from CREATION
|
||||
if (data.isNull(KEYS_INDEX_CREATION)) {
|
||||
if (data.isNull(INDEX_UNIFIED_CREATION)) {
|
||||
mCreation.setText(R.string.none);
|
||||
} else {
|
||||
Date creationDate = new Date(data.getLong(KEYS_INDEX_CREATION) * 1000);
|
||||
Date creationDate = new Date(data.getLong(INDEX_UNIFIED_CREATION) * 1000);
|
||||
|
||||
mCreation.setText(
|
||||
DateFormat.getDateFormat(getActivity().getApplicationContext()).format(
|
||||
@ -286,10 +265,10 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
}
|
||||
|
||||
// get expiry date from EXPIRY
|
||||
if (data.isNull(KEYS_INDEX_EXPIRY)) {
|
||||
if (data.isNull(INDEX_UNIFIED_EXPIRY)) {
|
||||
mExpiry.setText(R.string.none);
|
||||
} else {
|
||||
Date expiryDate = new Date(data.getLong(KEYS_INDEX_EXPIRY) * 1000);
|
||||
Date expiryDate = new Date(data.getLong(INDEX_UNIFIED_EXPIRY) * 1000);
|
||||
|
||||
mExpiry.setText(
|
||||
DateFormat.getDateFormat(getActivity().getApplicationContext()).format(
|
||||
@ -297,15 +276,22 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
byte[] fingerprintBlob = data.getBlob(KEYS_INDEX_FINGERPRINT);
|
||||
byte[] fingerprintBlob = data.getBlob(INDEX_UNIFIED_FINGERPRINT);
|
||||
String fingerprint = PgpKeyHelper.convertFingerprintToHex(fingerprintBlob);
|
||||
|
||||
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
|
||||
boolean canEncrypt = false;
|
||||
data.moveToFirst();
|
||||
@ -321,9 +307,6 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
|
||||
mKeysAdapter.swapCursor(data);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
getActivity().setProgressBarIndeterminateVisibility(Boolean.FALSE);
|
||||
mContainer.setVisibility(View.VISIBLE);
|
||||
@ -341,8 +324,6 @@ public class ViewKeyMainFragment extends Fragment implements
|
||||
case LOADER_ID_KEYS:
|
||||
mKeysAdapter.swapCursor(null);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user