Search in sources :

Example 1 with PreferenceUtil

use of org.horaapps.leafpic.util.PreferenceUtil in project LeafPic by HoraApps.

the class Album method getMedia.

private ArrayList<Media> getMedia(Context context) {
    PreferenceUtil SP = PreferenceUtil.getInstance(context);
    ArrayList<Media> mediaArrayList = new ArrayList<Media>();
    // TODO: 18/08/16
    if (isFromMediaStore()) {
        mediaArrayList.addAll(MediaStoreProvider.getMedia(context, id, SP.getBoolean("set_include_video", true)));
    } else {
        mediaArrayList.addAll(StorageProvider.getMedia(getPath(), SP.getBoolean("set_include_video", true)));
    }
    return mediaArrayList;
}
Also used : PreferenceUtil(org.horaapps.leafpic.util.PreferenceUtil) ArrayList(java.util.ArrayList)

Example 2 with PreferenceUtil

use of org.horaapps.leafpic.util.PreferenceUtil in project LeafPic by HoraApps.

the class MediaStoreProvider method getAlbums.

private static ArrayList<Album> getAlbums(Context context) {
    ArrayList<Album> list = new ArrayList<Album>();
    String[] projection = new String[] { MediaStore.Files.FileColumns.PARENT, MediaStore.Images.Media.BUCKET_DISPLAY_NAME };
    String selection, selectionArgs[];
    PreferenceUtil SP = PreferenceUtil.getInstance(context);
    boolean includeVideo = SP.getBoolean("set_include_video", true);
    if (includeVideo) {
        selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? or " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?" + " ) GROUP BY ( " + MediaStore.Files.FileColumns.PARENT + " ";
        selectionArgs = new String[] { String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE), String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO) };
    } else {
        selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ) GROUP BY ( " + MediaStore.Files.FileColumns.PARENT + " ";
        selectionArgs = new String[] { String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE) };
    }
    Cursor cur = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, selection, selectionArgs, null);
    if (cur != null) {
        if (cur.moveToFirst()) {
            int idColumn = cur.getColumnIndex(MediaStore.Files.FileColumns.PARENT);
            int nameColumn = cur.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
            do {
                Media media = getLastMedia(context, cur.getLong(idColumn));
                if (media != null && media.getPath() != null) {
                    String path = StringUtils.getBucketPathByImagePath(media.getPath());
                    boolean excluded = isExcluded(path);
                    if (!excluded) {
                        Album album = new Album(context, path, cur.getLong(idColumn), cur.getString(nameColumn), getAlbumCount(context, cur.getLong(idColumn)));
                        if (album.addMedia(getLastMedia(context, album.getId())))
                            list.add(album);
                    }
                }
            } while (cur.moveToNext());
        }
        cur.close();
    }
    return list;
}
Also used : PreferenceUtil(org.horaapps.leafpic.util.PreferenceUtil) ArrayList(java.util.ArrayList) Media(org.horaapps.leafpic.data.Media) Album(org.horaapps.leafpic.data.Album) Cursor(android.database.Cursor)

Aggregations

ArrayList (java.util.ArrayList)2 PreferenceUtil (org.horaapps.leafpic.util.PreferenceUtil)2 Cursor (android.database.Cursor)1 Album (org.horaapps.leafpic.data.Album)1 Media (org.horaapps.leafpic.data.Media)1