final fixes for public key list

This commit is contained in:
Dominik Schürmann 2014-01-02 22:36:57 +01:00
parent faabf8eca2
commit 7b9b3d07bb
6 changed files with 29 additions and 38 deletions

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@color/header_pressed" />
<item android:drawable="@color/header_normal" />
</selector>

View File

@ -14,7 +14,6 @@
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="32dp" android:paddingRight="32dp"
android:paddingTop="16dp"
android:scrollbarStyle="outsideOverlay" /> android:scrollbarStyle="outsideOverlay" />
<TextView <TextView

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content" >
android:background="@color/abs__background_holo_light" >
<se.emilsjolander.stickylistheaders.views.UnderlineTextView <se.emilsjolander.stickylistheaders.views.UnderlineTextView
android:id="@+id/stickylist_header_text" android:id="@+id/stickylist_header_text"

View File

@ -3,8 +3,5 @@
<color name="emphasis">#31b6e7</color> <color name="emphasis">#31b6e7</color>
<color name="bg_gray">#cecbce</color> <color name="bg_gray">#cecbce</color>
<color name="header_normal">#ffe74c3c</color>
<color name="header_pressed">#ffc0392b</color>
<color name="menu_section_header">#FFDDDDDD</color>
</resources> </resources>

View File

@ -44,19 +44,28 @@ import com.actionbarsherlock.app.SherlockFragment;
/** /**
* Public key list with sticky list headers. * Public key list with sticky list headers.
* *
* - uses StickyListHeaders library - custom adapter: KeyListPublicAdapter * - uses StickyListHeaders library
* *
* TODO: - fix loader with spinning animation - fix design - fix view holder in adapter * - custom adapter: KeyListPublicAdapter
*
* TODO: - fix view holder in adapter, fix loader
* *
*/ */
public class KeyListPublicFragment extends SherlockFragment implements public class KeyListPublicFragment extends SherlockFragment implements
AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor> { AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor> {
private KeyListPublicActivity mKeyListPublicActivity; private KeyListPublicActivity mKeyListPublicActivity;
private KeyListPublicAdapter mAdapter; private KeyListPublicAdapter mAdapter;
private StickyListHeadersListView mStickyList;
StickyListHeadersListView stickyList; /**
* Load custom layout with StickyListView from library
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.key_list_public_fragment, container, false);
return view;
}
/** /**
* Define Adapter and Loader on create of Activity * Define Adapter and Loader on create of Activity
@ -67,20 +76,17 @@ public class KeyListPublicFragment extends SherlockFragment implements
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mKeyListPublicActivity = (KeyListPublicActivity) getActivity(); mKeyListPublicActivity = (KeyListPublicActivity) getActivity();
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
stickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list); mStickyList.setOnItemClickListener(this);
stickyList.setOnItemClickListener(this);
// stickyList.setOnHeaderClickListener(this);
// stickyList.setOnStickyHeaderOffsetChangedListener(this);
// mStickyList.addHeaderView(inflater.inflate(R.layout.list_header, null)); // mStickyList.addHeaderView(inflater.inflate(R.layout.list_header, null));
// mStickyList.addFooterView(inflater.inflate(R.layout.list_footer, null)); // mStickyList.addFooterView(inflater.inflate(R.layout.list_footer, null));
stickyList.setEmptyView(getActivity().findViewById(R.id.empty)); mStickyList.setEmptyView(getActivity().findViewById(R.id.empty));
stickyList.setAreHeadersSticky(true); mStickyList.setAreHeadersSticky(true);
stickyList.setDrawingListUnderStickyHeader(true); mStickyList.setDrawingListUnderStickyHeader(false);
stickyList.setFastScrollEnabled(true); mStickyList.setFastScrollEnabled(true);
try { try {
stickyList.setFastScrollAlwaysVisible(true); mStickyList.setFastScrollAlwaysVisible(true);
} catch (ApiLevelTooLowException e) { } catch (ApiLevelTooLowException e) {
} }
@ -101,12 +107,6 @@ public class KeyListPublicFragment extends SherlockFragment implements
getLoaderManager().initLoader(0, null, this); getLoaderManager().initLoader(0, null, this);
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.key_list_public_fragment, container, false);
return view;
}
// These are the rows that we will retrieve. // These are the rows that we will retrieve.
static final String[] PROJECTION = new String[] { KeyRings._ID, KeyRings.MASTER_KEY_ID, static final String[] PROJECTION = new String[] { KeyRings._ID, KeyRings.MASTER_KEY_ID,
UserIds.USER_ID }; UserIds.USER_ID };
@ -134,7 +134,7 @@ public class KeyListPublicFragment extends SherlockFragment implements
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, data, Id.type.public_key, mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, data, Id.type.public_key,
userIdIndex); userIdIndex);
stickyList.setAdapter(mAdapter); mStickyList.setAdapter(mAdapter);
// The list should now be shown. // The list should now be shown.
if (isResumed()) { if (isResumed()) {
@ -152,9 +152,11 @@ public class KeyListPublicFragment extends SherlockFragment implements
mAdapter.swapCursor(null); mAdapter.swapCursor(null);
} }
/**
* On click on item, start key view activity
*/
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
// start key view on click
Intent detailsIntent = new Intent(mKeyListPublicActivity, KeyViewActivity.class); Intent detailsIntent = new Intent(mKeyListPublicActivity, KeyViewActivity.class);
detailsIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(id))); detailsIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(id)));
startActivity(detailsIntent); startActivity(detailsIntent);

View File

@ -86,7 +86,6 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
@Override @Override
public View getHeaderView(int position, View convertView, ViewGroup parent) { public View getHeaderView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder; HeaderViewHolder holder;
if (convertView == null) { if (convertView == null) {
holder = new HeaderViewHolder(); holder = new HeaderViewHolder();
@ -97,6 +96,7 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
holder = (HeaderViewHolder) convertView.getTag(); holder = (HeaderViewHolder) convertView.getTag();
} }
// similar to getView in CursorAdapter
if (!mDataValid) { if (!mDataValid) {
// no data available at this point // no data available at this point
Log.d(Constants.TAG, "getHeaderView: No data available at this point!"); Log.d(Constants.TAG, "getHeaderView: No data available at this point!");
@ -108,17 +108,18 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
throw new IllegalStateException("couldn't move cursor to position " + position); throw new IllegalStateException("couldn't move cursor to position " + position);
} }
// set header text as first char in name // set header text as first char in user id
String headerText = "" + mCursor.getString(mSectionColumnIndex).subSequence(0, 1).charAt(0); String headerText = "" + mCursor.getString(mSectionColumnIndex).subSequence(0, 1).charAt(0);
holder.text.setText(headerText); holder.text.setText(headerText);
return convertView; return convertView;
} }
/** /**
* Remember that these have to be static, position=1 should always return the same Id that is. * Header IDs should be static, position=1 should always return the same Id that is.
*/ */
@Override @Override
public long getHeaderId(int position) { public long getHeaderId(int position) {
// similar to getView in CursorAdapter
if (!mDataValid) { if (!mDataValid) {
// no data available at this point // no data available at this point
Log.d(Constants.TAG, "getHeaderView: No data available at this point!"); Log.d(Constants.TAG, "getHeaderView: No data available at this point!");