aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java32
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java39
2 files changed, 61 insertions, 10 deletions
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 eae283269..68da3b58c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java
@@ -44,6 +44,8 @@ import org.sufficientlysecure.keychain.ui.dialog.UserIdInfoDialogFragment;
import org.sufficientlysecure.keychain.util.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
+import java.util.List;
+
public class ViewKeyFragment extends LoaderFragment implements
LoaderManager.LoaderCallbacks<Cursor> {
@@ -126,19 +128,35 @@ public class ViewKeyFragment extends LoaderFragment implements
final Context context = mSystemContactName.getContext();
final ContentResolver resolver = context.getContentResolver();
- final long contactId = ContactHelper.findContactId(resolver, masterKeyId);
- final String contactName = ContactHelper.getContactName(resolver, contactId);
+ long contactId;
+ String contactName = null;
+
+ if(mIsSecret) {
+ contactId = ContactHelper.getMainProfileContactId(resolver);
+ List<String> mainProfileNames = ContactHelper.getMainProfileContactName(context);
+ if(mainProfileNames!=null) contactName = mainProfileNames.get(0);
+
+ } else {
+ contactId = ContactHelper.findContactId(resolver, masterKeyId);
+ contactName = ContactHelper.getContactName(resolver, contactId);
+ }
if (contactName != null) {//contact name exists for given master key
mSystemContactName.setText(contactName);
- Bitmap picture = ContactHelper.loadPhotoByMasterKeyId(resolver, masterKeyId, true);
+ Bitmap picture;
+ if(mIsSecret) {
+ picture = ContactHelper.loadMainProfilePhoto(resolver, false);
+ } else {
+ picture = ContactHelper.loadPhotoByMasterKeyId(resolver,masterKeyId,false);
+ }
if (picture != null) mSystemContactPicture.setImageBitmap(picture);
+ final long finalContactId = contactId;
mSystemContactLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- launchContactActivity(contactId, context);
+ launchContactActivity(finalContactId, context);
}
});
mSystemContactLoaded = true;
@@ -239,14 +257,14 @@ public class ViewKeyFragment extends LoaderFragment implements
switch (loader.getId()) {
case LOADER_ID_UNIFIED: {
if (data.moveToFirst()) {
+
+ mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
+
//TODO system to allow immediate refreshing of system contact on verification
if (!mSystemContactLoaded) {//ensure we load linked system contact only once
long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
loadLinkedSystemContact(masterKeyId);
}
-
- mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
-
// load user ids after we know if it's a secret key
mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0, !mIsSecret, null);
mUserIds.setAdapter(mUserIdsAdapter);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java
index 1b52e4e6b..cb6c39188 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java
@@ -190,7 +190,7 @@ public class ContactHelper {
* @param context
* @return
*/
- private static List<String> getMainProfileContactName(Context context) {
+ public static List<String> getMainProfileContactName(Context context) {
ContentResolver resolver = context.getContentResolver();
Cursor profileCursor = resolver.query(
ContactsContract.Profile.CONTENT_URI,
@@ -214,6 +214,38 @@ public class ContactHelper {
return new ArrayList<>(names);
}
+ public static long getMainProfileContactId(ContentResolver resolver) {
+ Cursor profileCursor = resolver.query(
+ ContactsContract.Profile.CONTENT_URI,
+ new String[]{
+ ContactsContract.Profile._ID
+ },
+ null, null, null);
+ if (profileCursor == null) {
+ return -1;
+ }
+
+ profileCursor.moveToNext();
+ return profileCursor.getLong(0);
+ }
+
+ public static Bitmap loadMainProfilePhoto(ContentResolver contentResolver, boolean highRes) {
+ try {
+ long mainProfileContactId = getMainProfileContactId(contentResolver);
+
+ Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI,
+ Long.toString(mainProfileContactId));
+ InputStream photoInputStream =
+ ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, contactUri, highRes);
+ if (photoInputStream == null) {
+ return null;
+ }
+ return BitmapFactory.decodeStream(photoInputStream);
+ } catch (Throwable ignored) {
+ return null;
+ }
+ }
+
public static List<String> getContactMails(Context context) {
ContentResolver resolver = context.getContentResolver();
Cursor mailCursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
@@ -269,7 +301,7 @@ public class ContactHelper {
/**
* returns the CONTACT_ID of the raw contact to which a masterKeyId is associated, if the
- * raw contact has not been marked for deletion
+ * raw contact has not been marked for deletion.
*
* @param resolver
* @param masterKeyId
@@ -428,7 +460,8 @@ public class ContactHelper {
// Do not store expired or revoked or unverified keys in contact db - and
// remove them if they already exist. Secret keys do not reach this point
if (isExpired || isRevoked || !isVerified) {
- Log.d(Constants.TAG, "Expired or revoked or unverified: Deleting rawContactId " + rawContactId);
+ Log.d(Constants.TAG, "Expired or revoked or unverified: Deleting rawContactId "
+ + rawContactId);
if (rawContactId != -1) {
deleteRawContactById(resolver, rawContactId);
}