add edit button and secret key info to public key view

This commit is contained in:
Vincent Breitmoser 2014-03-08 13:17:52 +01:00
parent 7ad8977cf3
commit 706e212b6b
5 changed files with 71 additions and 2 deletions

View File

@ -483,6 +483,12 @@ public class ProviderHelper {
return (masterKeyId > 0);
}
public static boolean hasSecretKeyByMasterKeyId(Context context, long masterKeyId) {
Uri queryUri = KeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId));
// see if we can get our master key id back from the uri
return getMasterKeyId(context, queryUri) == masterKeyId;
}
/**
* Get master key id of keyring by its row id
*/

View File

@ -427,7 +427,6 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent editIntent = new Intent(getActivity(), EditKeyActivity.class);
// editIntent.setData(KeychainContract.KeyRings.buildSecretKeyRingsUri(Long.toString(1)));
editIntent.setData(KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long.toString(id)));
editIntent.setAction(EditKeyActivity.ACTION_EDIT_KEY);
startActivityForResult(editIntent, 0);

View File

@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.ui;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@ -59,6 +60,8 @@ public class ViewKeyMainFragment extends Fragment implements
private TextView mExpiry;
private TextView mCreation;
private TextView mFingerprint;
private TextView mSecretKey;
private BootstrapButton mActionEdit;
private BootstrapButton mActionEncrypt;
private ListView mUserIds;
@ -85,8 +88,10 @@ public class ViewKeyMainFragment extends Fragment implements
mCreation = (TextView) view.findViewById(R.id.creation);
mExpiry = (TextView) view.findViewById(R.id.expiry);
mFingerprint = (TextView) view.findViewById(R.id.fingerprint);
mSecretKey = (TextView) view.findViewById(R.id.secret_key);
mUserIds = (ListView) view.findViewById(R.id.user_ids);
mKeys = (ListView) view.findViewById(R.id.keys);
mActionEdit = (BootstrapButton) view.findViewById(R.id.action_edit);
mActionEncrypt = (BootstrapButton) view.findViewById(R.id.action_encrypt);
return view;
@ -116,6 +121,31 @@ 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);
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);
// 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(KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(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));
mActionEdit.setVisibility(View.GONE);
}
}
mActionEncrypt.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -160,7 +160,10 @@
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tableRow">
<TextView
android:layout_width="wrap_content"
@ -175,6 +178,22 @@
android:layout_height="wrap_content"
android:typeface="monospace" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="10dip"
android:text="@string/label_secret_key" />
<TextView
android:id="@+id/secret_key"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:typeface="monospace" />
</TableRow>
</TableLayout>
<TextView
@ -211,6 +230,17 @@
android:layout_marginTop="14dp"
android:text="@string/section_actions" />
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/action_edit"
android:layout_width="match_parent"
android:layout_height="60dp"
android:padding="4dp"
android:layout_marginBottom="10dp"
android:text="@string/key_view_action_edit"
bootstrapbutton:bb_icon_left="fa-lock"
bootstrapbutton:bb_type="info"
android:visibility="gone" />
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/action_encrypt"
android:layout_width="match_parent"

View File

@ -417,6 +417,7 @@
<string name="key_list_empty_button_import">importing keys.</string>
<!-- Key view -->
<string name="key_view_action_edit">Edit this key</string>
<string name="key_view_action_encrypt">Encrypt to this contact</string>
<string name="key_view_action_certify">Certify this contact\'s key</string>
<string name="key_view_tab_main">Info</string>
@ -433,5 +434,8 @@
<string name="drawer_close">Close navigation drawer</string>
<string name="edit">Edit</string>
<string name="my_keys">My Keys</string>
<string name="label_secret_key">Secret Key</string>
<string name="secret_key_yes">available</string>
<string name="secret_key_no">unavailable</string>
</resources>