aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-08-14 14:47:20 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-08-14 14:47:20 +0200
commitb2d447ab32c3e3327c0b3a89f51c46ede520a6d1 (patch)
treeea74ddafca804fa6f82d3c9ba11938c251eab379
parent94683607d64b004e58983d0eb7788fd3f0ba877b (diff)
downloadopen-keychain-b2d447ab32c3e3327c0b3a89f51c46ede520a6d1.tar.gz
open-keychain-b2d447ab32c3e3327c0b3a89f51c46ede520a6d1.tar.bz2
open-keychain-b2d447ab32c3e3327c0b3a89f51c46ede520a6d1.zip
show dummy item if there are no secret keys
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java49
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java24
-rw-r--r--OpenKeychain/src/main/res/layout/key_list_item.xml52
3 files changed, 121 insertions, 4 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
index 0488d8235..94f898089 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -29,6 +29,8 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.database.MergeCursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
@@ -265,7 +267,6 @@ public class KeyListFragment extends LoaderFragment
static final String ORDER =
KeyRings.HAS_ANY_SECRET + " DESC, UPPER(" + KeyRings.USER_ID + ") ASC";
-
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// This is called when a new Loader needs to be created. This
@@ -298,6 +299,22 @@ public class KeyListFragment extends LoaderFragment
// Swap the new cursor in. (The framework will take care of closing the
// old cursor once we return.)
mAdapter.setSearchQuery(mQuery);
+
+ if (data != null && data.moveToFirst()) {
+ boolean isSecret = data.getInt(KeyListAdapter.INDEX_HAS_ANY_SECRET) != 0;
+ if (!isSecret) {
+ MatrixCursor headerCursor = new MatrixCursor(KeyListAdapter.PROJECTION);
+ Long[] row = new Long[KeyListAdapter.PROJECTION.length];
+ row[KeyListAdapter.INDEX_HAS_ANY_SECRET] = 1L;
+ row[KeyListAdapter.INDEX_MASTER_KEY_ID] = 0L;
+ headerCursor.addRow(row);
+
+ Cursor dataCursor = data;
+ data = new MergeCursor(new Cursor[] {
+ headerCursor, dataCursor
+ });
+ }
+ }
mAdapter.swapCursor(data);
mStickyList.setAdapter(mAdapter);
@@ -722,6 +739,29 @@ public class KeyListFragment extends LoaderFragment
return v;
}
+ @Override
+ public void bindView(View view, Context context, Cursor cursor) {
+ boolean isSecret = cursor.getInt(INDEX_HAS_ANY_SECRET) != 0;
+ long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
+ if (isSecret && masterKeyId == 0L) {
+
+ // sort of a hack: if this item isn't enabled, we make it clickable
+ // to intercept its click events
+ view.setClickable(true);
+
+ KeyItemViewHolder h = (KeyItemViewHolder) view.getTag();
+ h.setDummy(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ createKey();
+ }
+ });
+ return;
+ }
+
+ super.bindView(view, context, cursor);
+ }
+
private class HeaderViewHolder {
TextView mText;
TextView mCount;
@@ -760,6 +800,10 @@ public class KeyListFragment extends LoaderFragment
if (mCursor.getInt(INDEX_HAS_ANY_SECRET) != 0) {
{ // set contact count
int num = mCursor.getCount();
+ // If this is a dummy secret key, subtract one
+ if (mCursor.getLong(INDEX_MASTER_KEY_ID) == 0L) {
+ num -= 1;
+ }
String contactsTotal = mContext.getResources().getQuantityString(R.plurals.n_keys, num, num);
holder.mCount.setText(contactsTotal);
holder.mCount.setVisibility(View.VISIBLE);
@@ -818,8 +862,9 @@ public class KeyListFragment extends LoaderFragment
public boolean isAnySecretSelected() {
for (int pos : mSelection.keySet()) {
- if (isSecretAvailable(pos))
+ if (isSecretAvailable(pos)) {
return true;
+ }
}
return false;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java
index aba1eb0d8..59d772d63 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java
@@ -31,6 +31,7 @@ import android.support.v4.widget.CursorAdapter;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
@@ -89,6 +90,8 @@ public class KeyAdapter extends CursorAdapter {
public static class KeyItemViewHolder {
public View mView;
+ public View mLayoutDummy;
+ public View mLayoutData;
public Long mMasterKeyId;
public TextView mMainUserId;
public TextView mMainUserIdRest;
@@ -101,6 +104,8 @@ public class KeyAdapter extends CursorAdapter {
public KeyItemViewHolder(View view) {
mView = view;
+ mLayoutData = view.findViewById(R.id.key_list_item_data);
+ mLayoutDummy = view.findViewById(R.id.key_list_item_dummy);
mMainUserId = (TextView) view.findViewById(R.id.key_list_item_name);
mMainUserIdRest = (TextView) view.findViewById(R.id.key_list_item_email);
mStatus = (ImageView) view.findViewById(R.id.key_list_item_status_icon);
@@ -111,6 +116,9 @@ public class KeyAdapter extends CursorAdapter {
public void setData(Context context, KeyItem item, Highlighter highlighter, boolean enabled) {
+ mLayoutData.setVisibility(View.VISIBLE);
+ mLayoutDummy.setVisibility(View.GONE);
+
mDisplayedItem = item;
{ // set name and stuff, common to both key types
@@ -129,7 +137,7 @@ public class KeyAdapter extends CursorAdapter {
}
// sort of a hack: if this item isn't enabled, we make it clickable
- // to intercept its click events
+ // to intercept its click events. either way, no listener!
mView.setClickable(!enabled);
{ // set edit button and status, specific by key type
@@ -200,6 +208,20 @@ public class KeyAdapter extends CursorAdapter {
}
+ /** Shows the "you have no keys yet" dummy view, and sets an OnClickListener. */
+ public void setDummy(OnClickListener listener) {
+
+ // just reset everything to display the dummy layout
+ mLayoutDummy.setVisibility(View.VISIBLE);
+ mLayoutData.setVisibility(View.GONE);
+ mSlinger.setVisibility(View.GONE);
+ mStatus.setVisibility(View.GONE);
+ mView.setClickable(false);
+
+ mLayoutDummy.setOnClickListener(listener);
+
+ }
+
}
public boolean isEnabled(Cursor cursor) {
diff --git a/OpenKeychain/src/main/res/layout/key_list_item.xml b/OpenKeychain/src/main/res/layout/key_list_item.xml
index 6078b898f..80be0ec34 100644
--- a/OpenKeychain/src/main/res/layout/key_list_item.xml
+++ b/OpenKeychain/src/main/res/layout/key_list_item.xml
@@ -11,6 +11,55 @@
android:focusable="false">
<LinearLayout
+ android:id="@+id/key_list_item_dummy"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:focusable="true"
+ android:visibility="gone"
+ android:background="?android:selectableItemBackground"
+ tools:visibility="visible">
+
+ <LinearLayout
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1"
+ android:orientation="vertical"
+ android:paddingLeft="8dp"
+ android:paddingRight="4dp"
+ android:paddingTop="4dp"
+ android:paddingBottom="4dp"
+ >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:text="You don't have any keys yet!"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:text="Click here to create or import one."
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ </LinearLayout>
+
+ <ImageView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:padding="16dp"
+ android:src="@drawable/ic_key_plus_grey600_24dp"
+ />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/key_list_item_data"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
@@ -20,7 +69,8 @@
android:paddingLeft="8dp"
android:paddingRight="4dp"
android:paddingTop="4dp"
- android:paddingBottom="4dp">
+ android:paddingBottom="4dp"
+ tools:visibility="gone">
<TextView
android:id="@+id/key_list_item_name"