mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-24 23:41:45 -05:00
added contact linking
This commit is contained in:
parent
bc43797c32
commit
f8a6f814dd
@ -18,25 +18,31 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
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.*;
|
||||||
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.compatibility.DialogFragmentWorkaround;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.UserIdInfoDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.UserIdInfoDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.util.ContactHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class ViewKeyFragment extends LoaderFragment implements
|
public class ViewKeyFragment extends LoaderFragment implements
|
||||||
@ -45,12 +51,18 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
public static final String ARG_DATA_URI = "uri";
|
public static final String ARG_DATA_URI = "uri";
|
||||||
|
|
||||||
private ListView mUserIds;
|
private ListView mUserIds;
|
||||||
private ListView mLinkedSystemContact;
|
//private ListView mLinkedSystemContact;
|
||||||
|
|
||||||
boolean mIsSecret = false;
|
boolean mIsSecret = false;
|
||||||
|
private String mName;
|
||||||
|
|
||||||
|
LinearLayout mSystemContactLayout;
|
||||||
|
ImageView mSystemContactPicture;
|
||||||
|
TextView mSystemContactName;
|
||||||
|
|
||||||
private static final int LOADER_ID_UNIFIED = 0;
|
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_SYSTEM_CONTACT = 2;
|
||||||
|
|
||||||
private UserIdsAdapter mUserIdsAdapter;
|
private UserIdsAdapter mUserIdsAdapter;
|
||||||
|
|
||||||
@ -83,15 +95,17 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mLinkedSystemContact = (ListView) view.findViewById(R.id.view_key_linked_system_contact);
|
mSystemContactLayout = (LinearLayout) view.findViewById(R.id.system_contact_layout);
|
||||||
|
mSystemContactName = (TextView) view.findViewById(R.id.system_contact_name);
|
||||||
|
mSystemContactPicture = (ImageView) view.findViewById(R.id.system_contact_picture);
|
||||||
|
// mLinkedSystemContact = (ListView) view.findViewById(R.id.view_key_linked_system_contact);
|
||||||
|
|
||||||
mLinkedSystemContact.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
/* mLinkedSystemContact.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
showSystemContact(position);
|
showSystemContact(position);
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +125,32 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSystemContact(final int position) {
|
private void loadLinkedSystemContact(String name, final long masterKeyId) {
|
||||||
|
final Context context = mSystemContactName.getContext();
|
||||||
|
final ContentResolver resolver = context.getContentResolver();
|
||||||
|
|
||||||
|
final long contactId = ContactHelper.findContactId(resolver, masterKeyId);
|
||||||
|
|
||||||
|
if (contactId != -1) {//contact exists for given master key
|
||||||
|
mSystemContactName.setText(name);
|
||||||
|
|
||||||
|
Bitmap picture = ContactHelper.loadPhotoByMasterKeyId(resolver, masterKeyId, true);
|
||||||
|
if (picture != null) mSystemContactPicture.setImageBitmap(picture);
|
||||||
|
|
||||||
|
mSystemContactLayout.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
launchContactActivity(contactId, context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchContactActivity(final long contactId, Context context) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId));
|
||||||
|
intent.setData(uri);
|
||||||
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -196,7 +234,12 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
if (data.moveToFirst()) {
|
if (data.moveToFirst()) {
|
||||||
|
|
||||||
mIsSecret = data.getInt(INDEX_HAS_ANY_SECRET) != 0;
|
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];
|
||||||
|
long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
|
||||||
|
loadLinkedSystemContact(mName, masterKeyId);
|
||||||
|
}
|
||||||
// load user ids after we know if it's a secret key
|
// load user ids after we know if it's a secret key
|
||||||
mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0, !mIsSecret, null);
|
mUserIdsAdapter = new UserIdsAdapter(getActivity(), null, 0, !mIsSecret, null);
|
||||||
mUserIds.setAdapter(mUserIdsAdapter);
|
mUserIds.setAdapter(mUserIdsAdapter);
|
||||||
|
@ -267,6 +267,34 @@ public class ContactHelper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the CONTACT_ID of the raw contact to which a masterKeyId is associated, if the
|
||||||
|
* raw contact has not been marked for deletion
|
||||||
|
* @param resolver
|
||||||
|
* @param masterKeyId
|
||||||
|
* @return CONTACT_ID (id of aggregated contact) linked to masterKeyId
|
||||||
|
*/
|
||||||
|
public static long findContactId(ContentResolver resolver, long masterKeyId) {
|
||||||
|
long contactId = -1;
|
||||||
|
Cursor raw = resolver.query(ContactsContract.RawContacts.CONTENT_URI,
|
||||||
|
new String[]{
|
||||||
|
ContactsContract.RawContacts.CONTACT_ID
|
||||||
|
},
|
||||||
|
ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " +
|
||||||
|
ContactsContract.RawContacts.SOURCE_ID + "=? AND " +
|
||||||
|
ContactsContract.RawContacts.DELETED + "=?",
|
||||||
|
new String[]{//"0" for "not deleted"
|
||||||
|
Constants.ACCOUNT_TYPE, Long.toString(masterKeyId), "0"
|
||||||
|
}, null);
|
||||||
|
if (raw != null) {
|
||||||
|
if (raw.moveToNext()) {
|
||||||
|
contactId = raw.getLong(0);
|
||||||
|
}
|
||||||
|
raw.close();
|
||||||
|
}
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
public static Bitmap getCachedPhotoByMasterKeyId(ContentResolver contentResolver, long masterKeyId) {
|
public static Bitmap getCachedPhotoByMasterKeyId(ContentResolver contentResolver, long masterKeyId) {
|
||||||
if (masterKeyId == -1) {
|
if (masterKeyId == -1) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -62,11 +62,28 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/section_linked_system_contact"/>
|
android:text="@string/section_linked_system_contact"/>
|
||||||
|
|
||||||
<org.sufficientlysecure.keychain.ui.widget.FixedListView
|
<LinearLayout
|
||||||
android:id="@+id/view_key_linked_system_contact"
|
android:id='@+id/system_contact_layout'
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="4dp"/>
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/system_contact_picture"
|
||||||
|
android:layout_margin="6dp"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:src="@color/bg_gray"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/system_contact_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:text="@string/view_key_fragment_no_system_contact"/>
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
||||||
|
|
||||||
|
@ -639,6 +639,8 @@
|
|||||||
<string name="view_key_verified">"Confirmed Key"</string>
|
<string name="view_key_verified">"Confirmed Key"</string>
|
||||||
<string name="view_key_unverified">"Unconfirmed: Scan QR Code to confirm key!"</string>
|
<string name="view_key_unverified">"Unconfirmed: Scan QR Code to confirm key!"</string>
|
||||||
|
|
||||||
|
<string name="view_key_fragment_no_system_contact">"<none>"</string>
|
||||||
|
|
||||||
<!-- Navigation Drawer -->
|
<!-- Navigation Drawer -->
|
||||||
<string name="nav_keys">"Keys"</string>
|
<string name="nav_keys">"Keys"</string>
|
||||||
<string name="nav_encrypt_decrypt">"Encrypt/Decrypt"</string>
|
<string name="nav_encrypt_decrypt">"Encrypt/Decrypt"</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user