mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-25 07:51:48 -05:00
cleanup and documentation
This commit is contained in:
parent
606caee145
commit
0e4cfed969
@ -42,14 +42,8 @@ import android.widget.AdapterView;
|
|||||||
import com.actionbarsherlock.app.SherlockFragment;
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public key list with sticky list headers.
|
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
|
||||||
*
|
* StickyListHeaders library which does not extend upon ListView.
|
||||||
* - uses StickyListHeaders library
|
|
||||||
*
|
|
||||||
* - 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> {
|
||||||
@ -79,9 +73,6 @@ public class KeyListPublicFragment extends SherlockFragment implements
|
|||||||
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
|
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
|
||||||
|
|
||||||
mStickyList.setOnItemClickListener(this);
|
mStickyList.setOnItemClickListener(this);
|
||||||
// mStickyList.addHeaderView(inflater.inflate(R.layout.list_header, null));
|
|
||||||
// mStickyList.addFooterView(inflater.inflate(R.layout.list_footer, null));
|
|
||||||
mStickyList.setEmptyView(getActivity().findViewById(R.id.empty));
|
|
||||||
mStickyList.setAreHeadersSticky(true);
|
mStickyList.setAreHeadersSticky(true);
|
||||||
mStickyList.setDrawingListUnderStickyHeader(false);
|
mStickyList.setDrawingListUnderStickyHeader(false);
|
||||||
mStickyList.setFastScrollEnabled(true);
|
mStickyList.setFastScrollEnabled(true);
|
||||||
@ -90,17 +81,17 @@ public class KeyListPublicFragment extends SherlockFragment implements
|
|||||||
} catch (ApiLevelTooLowException e) {
|
} catch (ApiLevelTooLowException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give some text to display if there is no data. In a real
|
// this view is made visible if no data is available
|
||||||
// application this would come from a resource.
|
mStickyList.setEmptyView(getActivity().findViewById(R.id.empty));
|
||||||
// setEmptyText(getString(R.string.list_empty));
|
|
||||||
|
|
||||||
|
// NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading
|
||||||
// Start out with a progress indicator.
|
// Start out with a progress indicator.
|
||||||
// setListShown(false);
|
// setListShown(false);
|
||||||
|
|
||||||
// Create an empty adapter we will use to display the loaded data.
|
// Create an empty adapter we will use to display the loaded data.
|
||||||
// mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, null, Id.type.public_key);
|
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, null, Id.type.public_key,
|
||||||
// setListAdapter(mAdapter);
|
USER_ID_INDEX);
|
||||||
// stickyList.setAdapter(mAdapter);
|
mStickyList.setAdapter(mAdapter);
|
||||||
|
|
||||||
// Prepare the loader. Either re-connect with an existing one,
|
// Prepare the loader. Either re-connect with an existing one,
|
||||||
// or start a new one.
|
// or start a new one.
|
||||||
@ -111,6 +102,8 @@ public class KeyListPublicFragment extends SherlockFragment implements
|
|||||||
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 };
|
||||||
|
|
||||||
|
static final int USER_ID_INDEX = 2;
|
||||||
|
|
||||||
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -128,20 +121,17 @@ public class KeyListPublicFragment extends SherlockFragment implements
|
|||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||||
// Swap the new cursor in. (The framework will take care of closing the
|
// Swap the new cursor in. (The framework will take care of closing the
|
||||||
// old cursor once we return.)
|
// old cursor once we return.)
|
||||||
// mAdapter.swapCursor(data);
|
mAdapter.swapCursor(data);
|
||||||
int userIdIndex = data.getColumnIndex(UserIds.USER_ID);
|
|
||||||
|
|
||||||
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, data, Id.type.public_key,
|
|
||||||
userIdIndex);
|
|
||||||
|
|
||||||
mStickyList.setAdapter(mAdapter);
|
mStickyList.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
// NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading
|
||||||
// The list should now be shown.
|
// The list should now be shown.
|
||||||
if (isResumed()) {
|
// if (isResumed()) {
|
||||||
// setListShown(true);
|
// setListShown(true);
|
||||||
} else {
|
// } else {
|
||||||
// setListShownNoAnimation(true);
|
// setListShownNoAnimation(true);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,13 +33,11 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* - implements StickyListHeadersAdapter from library - uses view holder pattern for performance
|
* Implements StickyListHeadersAdapter from library
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class KeyListPublicAdapter extends CursorAdapter implements StickyListHeadersAdapter {
|
public class KeyListPublicAdapter extends CursorAdapter implements StickyListHeadersAdapter {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
|
private int mSectionColumnIndex;
|
||||||
int mSectionColumnIndex;
|
|
||||||
|
|
||||||
public KeyListPublicAdapter(Context context, Cursor c, int flags, int sectionColumnIndex) {
|
public KeyListPublicAdapter(Context context, Cursor c, int flags, int sectionColumnIndex) {
|
||||||
super(context, c, flags);
|
super(context, c, flags);
|
||||||
@ -48,9 +46,14 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
mSectionColumnIndex = sectionColumnIndex;
|
mSectionColumnIndex = sectionColumnIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind cursor data to the item list view
|
||||||
|
*
|
||||||
|
* NOTE: CursorAdapter already implements the ViewHolder pattern in its getView() method. Thus
|
||||||
|
* no ViewHolder is required here.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
public void bindView(View view, Context context, Cursor cursor) {
|
||||||
// TODO: view holder pattern?
|
|
||||||
int userIdIndex = cursor.getColumnIndex(UserIds.USER_ID);
|
int userIdIndex = cursor.getColumnIndex(UserIds.USER_ID);
|
||||||
|
|
||||||
TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
|
TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
|
||||||
@ -84,6 +87,13 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
return mInflater.inflate(R.layout.key_list_item, null);
|
return mInflater.inflate(R.layout.key_list_item, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new header view and binds the section headers to it. It uses the ViewHolder
|
||||||
|
* pattern. Most functionality is similar to getView() from Android's CursorAdapter.
|
||||||
|
*
|
||||||
|
* NOTE: The variables mDataValid and mCursor are available due to the super class
|
||||||
|
* CursorAdapter.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View getHeaderView(int position, View convertView, ViewGroup parent) {
|
public View getHeaderView(int position, View convertView, ViewGroup parent) {
|
||||||
HeaderViewHolder holder;
|
HeaderViewHolder holder;
|
||||||
@ -96,14 +106,12 @@ 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!");
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
// similar to getView in CursorAdapter
|
|
||||||
if (!mCursor.moveToPosition(position)) {
|
if (!mCursor.moveToPosition(position)) {
|
||||||
throw new IllegalStateException("couldn't move cursor to position " + position);
|
throw new IllegalStateException("couldn't move cursor to position " + position);
|
||||||
}
|
}
|
||||||
@ -119,14 +127,12 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
*/
|
*/
|
||||||
@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!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// similar to getView in CursorAdapter
|
|
||||||
if (!mCursor.moveToPosition(position)) {
|
if (!mCursor.moveToPosition(position)) {
|
||||||
throw new IllegalStateException("couldn't move cursor to position " + position);
|
throw new IllegalStateException("couldn't move cursor to position " + position);
|
||||||
}
|
}
|
||||||
@ -140,9 +146,4 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
TextView text;
|
TextView text;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewHolder {
|
|
||||||
TextView mainUserId;
|
|
||||||
TextView mainUserIdRest;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user