package com.dyhpoon.fodex.contentFragment;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

import com.dyhpoon.fodex.fodexView.FodexBaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by darrenpoon on 8/12/14.
 */
public class RecentPhotosPageFragment extends FodexBaseFragment<RecentPhotosPageFragment.PhotoMedia> {

    @Override
    protected void onClickFloatingActionButton() {
        // TODO: implement
    }

    @Override
    protected Uri imageUriForItems(PhotoMedia item) {
        return ContentUris.withAppendedId(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                Integer.parseInt(item.id));
    }

    @Override
    protected List<PhotoMedia> itemsForAdapters() {
        ContentResolver resolver = getActivity().getContentResolver();
        String[] projection = new String[]{
                MediaStore.Images.Media._ID,
                MediaStore.Images.Media.DATA,
                MediaStore.Images.Media.DATE_TAKEN,
        };
        Cursor cursor = resolver.query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                projection,
                null,
                null,
                null
        );

        List<PhotoMedia> items = new ArrayList<PhotoMedia>();
        if (cursor.moveToLast()) {
            final int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
            final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            final int dateColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN);

            do {
                final String id = cursor.getString(idColumn);
                final String data = cursor.getString(dataColumn);
                final String date = cursor.getString(dateColumn);

                items.add(new PhotoMedia(id, data, date));
            } while (cursor.moveToPrevious());

        }
        cursor.close();
        return items;
    }

    public class PhotoMedia {
        public String id;
        public String data;
        public String date;

        public PhotoMedia(String id, String data, String date) {
            this.id = id;
            this.data = data;
            this.date = date;
        }
    }

}

@@ -41,48 +41,8 @@
 t;%0A%0A
-import android.content.ContentResolver;%0A
 impo
@@ -166,16 +166,59 @@
 Store;%0A%0A
+import com.dyhpoon.fodex.data.FodexCursor;%0A
 import c
@@ -867,471 +867,64 @@
    C
-ontentResolver resolver = getActivity().getContentResolver();%0A        String%5B%5D projection = new String%5B%5D%7B%0A                MediaStore.Images.Media._ID,%0A                MediaStore.Images.Media.DATA,%0A                MediaStore.Images.Media.DATE_TAKEN,%0A        %7D;%0A        Cursor cursor = resolver.query(%0A                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,%0A                projection,%0A                null,%0A                null,%0A                null%0A        
+ursor cursor = FodexCursor.allPhotosCursor(getActivity()
 );%0A%0A
@@ -1014,10 +1014,11 @@
 veTo
-La
+Fir
 st()
@@ -1129,404 +1129,74 @@
     
-final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);%0A            final int dateColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN);%0A%0A            do %7B%0A                final String id = cursor.getString(idColumn);%0A                final String data = cursor.getString(dataColumn);%0A                final String date = cursor.getString(dateColumn);%0A
+do %7B%0A                final String id = cursor.getString(idColumn);
 %0A   
@@ -1239,20 +1239,8 @@
 a(id
-, data, date
 ));%0A
@@ -1277,16 +1277,12 @@
 veTo
-Previous
+Next
 ());
@@ -1405,64 +1405,8 @@
  id;
-%0A        public String data;%0A        public String date;
 %0A%0A  
@@ -1442,34 +1442,8 @@
 g id
-, String data, String date
 ) %7B%0A
@@ -1472,68 +1472,8 @@
 id;%0A
-            this.data = data;%0A            this.date = date;%0A
     

Revise cursor implementation. remove unused code.