aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java46
1 files changed, 34 insertions, 12 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 bb3df2541..c3a8d60f8 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> {
@@ -53,7 +55,7 @@ public class ViewKeyFragment extends LoaderFragment implements
//private ListView mLinkedSystemContact;
boolean mIsSecret = false;
- private String mName;
+ boolean mSystemContactLoaded = false;
LinearLayout mSystemContactLayout;
ImageView mSystemContactPicture;
@@ -119,28 +121,48 @@ public class ViewKeyFragment extends LoaderFragment implements
/**
* Checks if a system contact exists for given masterKeyId, and if it does, sets name, picture
* and onClickListener for the linked system contact's layout
+ * In the case of a secret key, "me" contact details are loaded
*
- * @param name
* @param masterKeyId
*/
- private void loadLinkedSystemContact(String name, final long masterKeyId) {
+ private void loadLinkedSystemContact(final long masterKeyId) {
final Context context = mSystemContactName.getContext();
final ContentResolver resolver = context.getContentResolver();
- final long contactId = ContactHelper.findContactId(resolver, masterKeyId);
+ long contactId;
+ String contactName = null;
+
+ if (mIsSecret) {//all secret keys are linked to "me" profile in contacts
+ contactId = ContactHelper.getMainProfileContactId(resolver);
+ List<String> mainProfileNames = ContactHelper.getMainProfileContactName(context);
+ if (mainProfileNames != null && mainProfileNames.size() > 0) {
+ contactName = mainProfileNames.get(0);
+ }
- if (contactId != -1) {//contact exists for given master key
- mSystemContactName.setText(name);
+ } else {
+ contactId = ContactHelper.findContactId(resolver, masterKeyId);
+ contactName = ContactHelper.getContactName(resolver, contactId);
+ }
- Bitmap picture = ContactHelper.loadPhotoByMasterKeyId(resolver, masterKeyId, true);
+ if (contactName != null) {//contact name exists for given master key
+ mSystemContactName.setText(contactName);
+
+ 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;
}
}
@@ -240,11 +262,11 @@ public class ViewKeyFragment extends LoaderFragment implements
if (data.moveToFirst()) {
mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
- if (mName == null) {//to ensure we load the linked system contact only once
- String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
- mName = mainUserId[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(mName, masterKeyId);
+ loadLinkedSystemContact(masterKeyId);
}
// load user ids after we know if it's a secret key
mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0, !mIsSecret, null);