@@ -0,0 +1,2872 @@
+/*%0A * Copyright (C) 2012 Antew %7C antewcode@gmail.com%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.antew.redditinpictures.library.adapter;%0A%0Aimport android.database.Cursor;%0Aimport android.support.v4.app.FixedFragmentStatePagerAdapter;%0Aimport android.support.v4.app.Fragment;%0Aimport android.support.v4.app.FragmentManager;%0A%0Aimport com.antew.redditinpictures.library.provider.RedditProvider;%0Aimport com.antew.redditinpictures.library.reddit.RedditApi.PostData;%0Aimport com.antew.redditinpictures.library.ui.ImageDetailFragment;%0A%0A/**%0A * The main adapter that backs the ViewPager. A subclass of FragmentStatePagerAdapter as there%0A * could be a large number of items in the ViewPager and we don't want to retain them all in%0A * memory at once but create/destroy them on the fly.%0A */%0Apublic class CursorPagerAdapter extends FixedFragmentStatePagerAdapter %7B%0A    private Cursor mCursor;%0A    %0A    public CursorPagerAdapter(FragmentManager fm, Cursor cursor) %7B%0A        super(fm);%0A        this.mCursor = cursor;%0A    %7D%0A%0A    @Override%0A    public int getCount() %7B%0A        if (mCursor == null)%0A            return 0;%0A        %0A        return mCursor.getCount();%0A    %7D%0A%0A    public void swapCursor(Cursor newCursor) %7B%0A        if (mCursor == newCursor)%0A            return;%0A        %0A        mCursor = newCursor;%0A        notifyDataSetChanged();%0A    %7D%0A    @Override%0A    public Fragment getItem(int position) %7B%0A        if (mCursor != null && mCursor.moveToPosition(position)) %7B%0A            return getImageDetailFragment(RedditProvider.cursorToPostData(mCursor));%0A        %7D%0A        %0A        return null;%0A    %7D%0A    %0A%0A    /**%0A     * The PostData at the input position%0A     * @param position The position%0A     * @return PostData at the input position%0A     */%0A    public PostData getPost(int position) %7B%0A        if (mCursor != null && mCursor.moveToPosition(position)) %7B%0A            return RedditProvider.cursorToPostData(mCursor);%0A        %7D%0A        %0A        return null;%0A    %7D%0A    %0A    /**%0A     * Returns an %7B@link ImageDetailFragment%7D for the input %7B@link PostData%7D object%0A     * @param p The %7B@link PostData%7D object to pass to the new %7B@link ImageDetailFragment%7D%0A     * @return A new %7B@link ImageDetailFragment%7D for the input %7B@link PostData%7D%0A     */%0A    public Fragment getImageDetailFragment(PostData p) %7B%0A        return ImageDetailFragment.newInstance(p);%0A    %7D%0A    %0A%7D%0A

Add ViewPager implementation that can be backed by a Cursor.