mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
Merge branch 'adithyaphilip-contact-card' into development
This commit is contained in:
commit
ae1c80e8b3
@ -18,24 +18,30 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
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
|
||||||
@ -44,8 +50,14 @@ 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;
|
||||||
|
|
||||||
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;
|
||||||
@ -81,6 +93,10 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +116,49 @@ 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
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param masterKeyId
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* launches the default android Contacts app to view a contact with the passed
|
||||||
|
* contactId (CONTACT_ID column from ContactsContract.RawContact table which is _ID column in
|
||||||
|
* ContactsContract.Contact table)
|
||||||
|
*
|
||||||
|
* @param contactId _ID for row in ContactsContract.Contacts table
|
||||||
|
* @param 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
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
@ -148,6 +207,7 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
getLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
|
getLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
setContentShown(false);
|
setContentShown(false);
|
||||||
|
|
||||||
@ -164,6 +224,7 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||||
/* TODO better error handling? May cause problems when a key is deleted,
|
/* TODO better error handling? May cause problems when a key is deleted,
|
||||||
* because the notification triggers faster than the activity closes.
|
* because the notification triggers faster than the activity closes.
|
||||||
@ -179,7 +240,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);
|
||||||
@ -202,6 +268,7 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
* This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
|
* This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
|
||||||
* We need to make sure we are no longer using it.
|
* We need to make sure we are no longer using it.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void onLoaderReset(Loader<Cursor> loader) {
|
public void onLoaderReset(Loader<Cursor> loader) {
|
||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case LOADER_ID_USER_IDS: {
|
case LOADER_ID_USER_IDS: {
|
||||||
|
@ -41,6 +41,51 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
||||||
|
|
||||||
|
<android.support.v7.widget.CardView
|
||||||
|
android:id="@+id/linked_system_contact_card"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
card_view:cardBackgroundColor="@android:color/white"
|
||||||
|
card_view:cardElevation="2dp"
|
||||||
|
card_view:cardUseCompatPadding="true"
|
||||||
|
card_view:cardCornerRadius="4dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/CardViewHeader"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/section_linked_system_contact"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id='@+id/system_contact_layout'
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/system_contact_picture"
|
||||||
|
android:layout_margin="6dp"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:src="@drawable/ic_person_grey_48dp"/>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</android.support.v7.widget.CardView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
|
|
||||||
<!-- section -->
|
<!-- section -->
|
||||||
<string name="section_user_ids">"Identities"</string>
|
<string name="section_user_ids">"Identities"</string>
|
||||||
|
<string name="section_linked_system_contact">"Linked System Contact"</string>
|
||||||
<string name="section_should_you_trust">"Should you trust this key?"</string>
|
<string name="section_should_you_trust">"Should you trust this key?"</string>
|
||||||
<string name="section_proof_details">Proof verification</string>
|
<string name="section_proof_details">Proof verification</string>
|
||||||
<string name="section_cloud_evidence">"Proofs from the cloud"</string>
|
<string name="section_cloud_evidence">"Proofs from the cloud"</string>
|
||||||
@ -644,6 +645,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…
Reference in New Issue
Block a user