add expand item to linked id list

This commit is contained in:
Vincent Breitmoser 2015-03-10 04:27:40 +01:00
parent deafe946fd
commit 3b7f21d98a
5 changed files with 79 additions and 5 deletions

View File

@ -37,6 +37,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
@ -70,6 +71,7 @@ public class ViewKeyFragment extends LoaderFragment implements
private ListView mLinkedIds; private ListView mLinkedIds;
private CardView mLinkedIdsCard; private CardView mLinkedIdsCard;
private byte[] mFingerprint; private byte[] mFingerprint;
private TextView mLinkedIdsExpander;
/** /**
* Creates new instance of this fragment * Creates new instance of this fragment
@ -113,6 +115,8 @@ public class ViewKeyFragment extends LoaderFragment implements
mLinkedIds = (ListView) view.findViewById(R.id.view_key_linked_ids); mLinkedIds = (ListView) view.findViewById(R.id.view_key_linked_ids);
mLinkedIdsExpander = (TextView) view.findViewById(R.id.view_key_linked_ids_expander);
mUserIds.setOnItemClickListener(new AdapterView.OnItemClickListener() { mUserIds.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) {
@ -198,7 +202,8 @@ public class ViewKeyFragment extends LoaderFragment implements
mUserIds.setAdapter(mUserIdsAdapter); mUserIds.setAdapter(mUserIdsAdapter);
getLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this); getLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this);
mLinkedIdsAdapter = new LinkedIdsAdapter(getActivity(), null, 0, !mIsSecret); mLinkedIdsAdapter = new LinkedIdsAdapter(getActivity(), null, 0,
!mIsSecret, mLinkedIdsExpander);
mLinkedIds.setAdapter(mLinkedIdsAdapter); mLinkedIds.setAdapter(mLinkedIdsAdapter);
getLoaderManager().initLoader(LOADER_ID_LINKED_IDS, null, this); getLoaderManager().initLoader(LOADER_ID_LINKED_IDS, null, this);

View File

@ -26,6 +26,7 @@ import android.support.v4.content.CursorLoader;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -50,19 +51,36 @@ public class LinkedIdsAdapter extends UserAttributesAdapter {
protected LayoutInflater mInflater; protected LayoutInflater mInflater;
WeakHashMap<Integer,RawLinkedIdentity> mLinkedIdentityCache = new WeakHashMap<>(); WeakHashMap<Integer,RawLinkedIdentity> mLinkedIdentityCache = new WeakHashMap<>();
public LinkedIdsAdapter(Context context, Cursor c, int flags, boolean showCertification) { private Cursor mUnfilteredCursor;
private TextView mExpander;
public LinkedIdsAdapter(Context context, Cursor c, int flags,
boolean showCertification, TextView expander) {
super(context, c, flags); super(context, c, flags);
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
mShowCertification = showCertification; mShowCertification = showCertification;
if (expander != null) {
mExpander = expander;
mExpander.setVisibility(View.GONE);
mExpander.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showUnfiltered();
}
});
}
} }
@Override @Override
public Cursor swapCursor(Cursor cursor) { public Cursor swapCursor(Cursor cursor) {
if (cursor == null) { if (cursor == null) {
mUnfilteredCursor = null;
return super.swapCursor(null); return super.swapCursor(null);
} }
mUnfilteredCursor = cursor;
Cursor filteredCursor = new FilterCursorWrapper(cursor) { FilterCursorWrapper filteredCursor = new FilterCursorWrapper(cursor) {
@Override @Override
public boolean isVisible(Cursor cursor) { public boolean isVisible(Cursor cursor) {
RawLinkedIdentity id = getItemAtPosition(cursor); RawLinkedIdentity id = getItemAtPosition(cursor);
@ -70,9 +88,25 @@ public class LinkedIdsAdapter extends UserAttributesAdapter {
} }
}; };
if (mExpander != null) {
int hidden = filteredCursor.getHiddenCount();
if (hidden == 0) {
mExpander.setVisibility(View.GONE);
} else {
mExpander.setVisibility(View.VISIBLE);
mExpander.setText(mContext.getResources().getQuantityString(
R.plurals.linked_id_expand, hidden));
}
}
return super.swapCursor(filteredCursor); return super.swapCursor(filteredCursor);
} }
private void showUnfiltered() {
mExpander.setVisibility(View.GONE);
super.swapCursor(mUnfilteredCursor);
}
@Override @Override
public void bindView(View view, Context context, Cursor cursor) { public void bindView(View view, Context context, Cursor cursor) {

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<size
android:height="1px"
android:width="1000dp" />
<solid android:color="@color/bg_gray" />
</shape>

View File

@ -55,7 +55,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical"
android:animateLayoutChanges="true">
<TextView <TextView
style="@style/CardViewHeader" style="@style/CardViewHeader"
@ -68,6 +69,25 @@
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:layout_marginBottom="4dp" />
<TextView
android:id="@+id/view_key_linked_ids_expander"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:gravity="center_vertical"
android:drawableTop="@drawable/divider"
android:drawableRight="@drawable/ic_expand_more_black_24dp"
android:drawableEnd="@drawable/ic_expand_more_black_24dp"
android:drawablePadding="3dp"
android:clickable="true"
android:textColor="@color/tertiary_text_light"
android:text="%d more unknown identity types"
android:paddingLeft="8dp"
android:paddingRight="8dp"
style="@style/SelectableItem" />
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>

View File

@ -1310,5 +1310,9 @@
<string name="linked_need_verify">The resource needs to be verified before you can proceed!</string> <string name="linked_need_verify">The resource needs to be verified before you can proceed!</string>
<string name="menu_linked_add_identity">"Add Linked Identity"</string> <string name="menu_linked_add_identity">"Add Linked Identity"</string>
<string name="section_linked_identities">Linked Identities</string> <string name="section_linked_identities">Linked Identities</string>
<plurals name="linked_id_expand">
<item quantity="one">"There is one more unknown identity type"</item>
<item quantity="other">"There are %d more unknown identity types"</item>
</plurals>
</resources> </resources>