diff options
Diffstat (limited to 'photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java')
-rw-r--r-- | photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java b/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java index 848d79a..ae2c92e 100644 --- a/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java +++ b/photoviewer/src/com/android/ex/photo/adapters/BaseCursorPagerAdapter.java @@ -38,13 +38,12 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { private static final String TAG = "BaseCursorPagerAdapter"; Context mContext; - private boolean mDataValid; private Cursor mCursor; private int mRowIDColumn; /** Mapping of row ID to cursor position */ private SparseIntArray mItemPosition; /** Mapping of instantiated object to row ID */ - private HashMap<Object, Integer> mObjectRowMap = new HashMap<Object, Integer>(); + private final HashMap<Object, Integer> mObjectRowMap = new HashMap<Object, Integer>(); /** * Constructor that always enables auto-requery. @@ -67,9 +66,11 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { */ public abstract Fragment getItem(Context context, Cursor cursor, int position); + // TODO: This shouldn't just return null - maybe it needs to wait for a cursor to be supplied? + // See b/7103023 @Override public Fragment getItem(int position) { - if (mDataValid && moveCursorTo(position)) { + if (mCursor != null && moveCursorTo(position)) { return getItem(mContext, mCursor, position); } return null; @@ -77,7 +78,7 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { @Override public int getCount() { - if (mDataValid && mCursor != null) { + if (mCursor != null) { return mCursor.getCount(); } else { return 0; @@ -86,7 +87,7 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { @Override public Object instantiateItem(View container, int position) { - if (!mDataValid) { + if (mCursor == null) { throw new IllegalStateException("this should only be called when the cursor is valid"); } @@ -127,7 +128,7 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { * @return true if data is valid */ public boolean isDataValid() { - return mDataValid; + return mCursor != null; } /** @@ -141,7 +142,7 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { * Returns the data item associated with the specified position in the data set. */ public Object getDataItem(int position) { - if (mDataValid && moveCursorTo(position)) { + if (mCursor != null && moveCursorTo(position)) { return mCursor; } else { return null; @@ -152,7 +153,7 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { * Returns the row id associated with the specified position in the list. */ public long getItemId(int position) { - if (mDataValid && moveCursorTo(position)) { + if (mCursor != null && moveCursorTo(position)) { return mCursor.getString(mRowIDColumn).hashCode(); } else { return 0; @@ -180,10 +181,8 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { mCursor = newCursor; if (newCursor != null) { mRowIDColumn = newCursor.getColumnIndex(PhotoContract.PhotoViewColumns.URI); - mDataValid = true; } else { mRowIDColumn = -1; - mDataValid = false; } setItemPosition(); @@ -231,7 +230,6 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { private void init(Context context, Cursor c) { boolean cursorPresent = c != null; mCursor = c; - mDataValid = cursorPresent; mContext = context; mRowIDColumn = cursorPresent ? mCursor.getColumnIndex(PhotoContract.PhotoViewColumns.URI) : -1; @@ -242,7 +240,7 @@ public abstract class BaseCursorPagerAdapter extends BaseFragmentPagerAdapter { * row id to cursor position. */ private void setItemPosition() { - if (!mDataValid || mCursor == null || mCursor.isClosed()) { + if (mCursor == null || mCursor.isClosed()) { mItemPosition = null; return; } |