mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -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;
|
||||
|
||||
/**
|
||||
* Public key list with sticky list headers.
|
||||
*
|
||||
* - uses StickyListHeaders library
|
||||
*
|
||||
* - custom adapter: KeyListPublicAdapter
|
||||
*
|
||||
* TODO: - fix view holder in adapter, fix loader
|
||||
*
|
||||
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
|
||||
* StickyListHeaders library which does not extend upon ListView.
|
||||
*/
|
||||
public class KeyListPublicFragment extends SherlockFragment implements
|
||||
AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor> {
|
||||
@ -79,9 +73,6 @@ public class KeyListPublicFragment extends SherlockFragment implements
|
||||
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
|
||||
|
||||
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.setDrawingListUnderStickyHeader(false);
|
||||
mStickyList.setFastScrollEnabled(true);
|
||||
@ -90,17 +81,17 @@ public class KeyListPublicFragment extends SherlockFragment implements
|
||||
} catch (ApiLevelTooLowException e) {
|
||||
}
|
||||
|
||||
// Give some text to display if there is no data. In a real
|
||||
// application this would come from a resource.
|
||||
// setEmptyText(getString(R.string.list_empty));
|
||||
// this view is made visible if no data is available
|
||||
mStickyList.setEmptyView(getActivity().findViewById(R.id.empty));
|
||||
|
||||
// NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading
|
||||
// Start out with a progress indicator.
|
||||
// setListShown(false);
|
||||
|
||||
// Create an empty adapter we will use to display the loaded data.
|
||||
// mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, null, Id.type.public_key);
|
||||
// setListAdapter(mAdapter);
|
||||
// stickyList.setAdapter(mAdapter);
|
||||
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, null, Id.type.public_key,
|
||||
USER_ID_INDEX);
|
||||
mStickyList.setAdapter(mAdapter);
|
||||
|
||||
// Prepare the loader. Either re-connect with an existing 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,
|
||||
UserIds.USER_ID };
|
||||
|
||||
static final int USER_ID_INDEX = 2;
|
||||
|
||||
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
||||
|
||||
@Override
|
||||
@ -128,20 +121,17 @@ public class KeyListPublicFragment extends SherlockFragment implements
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||
// Swap the new cursor in. (The framework will take care of closing the
|
||||
// old cursor once we return.)
|
||||
// mAdapter.swapCursor(data);
|
||||
int userIdIndex = data.getColumnIndex(UserIds.USER_ID);
|
||||
|
||||
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, data, Id.type.public_key,
|
||||
userIdIndex);
|
||||
mAdapter.swapCursor(data);
|
||||
|
||||
mStickyList.setAdapter(mAdapter);
|
||||
|
||||
// NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading
|
||||
// The list should now be shown.
|
||||
if (isResumed()) {
|
||||
// setListShown(true);
|
||||
} else {
|
||||
// setListShownNoAnimation(true);
|
||||
}
|
||||
// if (isResumed()) {
|
||||
// setListShown(true);
|
||||
// } else {
|
||||
// setListShownNoAnimation(true);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,13 +33,11 @@ import android.view.ViewGroup;
|
||||
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 {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
int mSectionColumnIndex;
|
||||
private int mSectionColumnIndex;
|
||||
|
||||
public KeyListPublicAdapter(Context context, Cursor c, int flags, int sectionColumnIndex) {
|
||||
super(context, c, flags);
|
||||
@ -48,9 +46,14 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
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
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
// TODO: view holder pattern?
|
||||
int userIdIndex = cursor.getColumnIndex(UserIds.USER_ID);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
public View getHeaderView(int position, View convertView, ViewGroup parent) {
|
||||
HeaderViewHolder holder;
|
||||
@ -96,14 +106,12 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
holder = (HeaderViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
// similar to getView in CursorAdapter
|
||||
if (!mDataValid) {
|
||||
// no data available at this point
|
||||
Log.d(Constants.TAG, "getHeaderView: No data available at this point!");
|
||||
return convertView;
|
||||
}
|
||||
|
||||
// similar to getView in CursorAdapter
|
||||
if (!mCursor.moveToPosition(position)) {
|
||||
throw new IllegalStateException("couldn't move cursor to position " + position);
|
||||
}
|
||||
@ -119,14 +127,12 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
*/
|
||||
@Override
|
||||
public long getHeaderId(int position) {
|
||||
// similar to getView in CursorAdapter
|
||||
if (!mDataValid) {
|
||||
// no data available at this point
|
||||
Log.d(Constants.TAG, "getHeaderView: No data available at this point!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// similar to getView in CursorAdapter
|
||||
if (!mCursor.moveToPosition(position)) {
|
||||
throw new IllegalStateException("couldn't move cursor to position " + position);
|
||||
}
|
||||
@ -140,9 +146,4 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
TextView text;
|
||||
}
|
||||
|
||||
class ViewHolder {
|
||||
TextView mainUserId;
|
||||
TextView mainUserIdRest;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user