Search in sources :

Example 1 with ImageFileFilter

use of org.horaapps.leafpic.data.base.ImageFileFilter in project LeafPic by HoraApps.

the class StorageProvider method checkAndAddFolder.

private void checkAndAddFolder(Context context, File dir, ArrayList<Album> albumArrayList) {
    File[] files = dir.listFiles(new ImageFileFilter(includeVideo));
    if (files != null && files.length > 0) {
        //valid folder
        Album asd = new Album(context, dir.getAbsolutePath(), -1, dir.getName(), files.length);
        long lastMod = Long.MIN_VALUE;
        File choice = null;
        for (File file : files) {
            if (file.lastModified() > lastMod) {
                choice = file;
                lastMod = file.lastModified();
            }
        }
        if (choice != null)
            asd.addMedia(new Media(choice.getAbsolutePath(), choice.lastModified()));
        albumArrayList.add(asd);
    }
}
Also used : Media(org.horaapps.leafpic.data.Media) Album(org.horaapps.leafpic.data.Album) ImageFileFilter(org.horaapps.leafpic.data.base.ImageFileFilter) File(java.io.File)

Example 2 with ImageFileFilter

use of org.horaapps.leafpic.data.base.ImageFileFilter in project LeafPic by HoraApps.

the class MediaStoreProvider method getHiddenAlbums.

private static ArrayList<Album> getHiddenAlbums(Context context) {
    ArrayList<Album> list = new ArrayList<Album>();
    String[] projection = new String[] { MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.PARENT };
    String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE + " and " + MediaStore.Files.FileColumns.DATA + " LIKE '%.nomedia'";
    Cursor cur = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, selection, null, null);
    if (cur != null && cur.moveToFirst()) {
        do {
            File folder = new File(cur.getString(0)).getParentFile();
            File[] files = folder.listFiles(new ImageFileFilter(true));
            if (files != null && files.length > 0) {
                Album album = new Album(context, folder.getAbsolutePath(), -1, folder.getName(), files.length);
                // TODO: 21/08/16 sort and find?
                long lastMod = Long.MIN_VALUE;
                File f = null;
                for (File file : files) {
                    if (file.lastModified() > lastMod) {
                        f = file;
                        lastMod = file.lastModified();
                    }
                }
                if (f != null && !isExcluded(f.getPath())) {
                    album.addMedia(new Media(f.getPath(), f.lastModified()));
                    list.add(album);
                }
            }
        } while (cur.moveToNext());
        cur.close();
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Media(org.horaapps.leafpic.data.Media) Album(org.horaapps.leafpic.data.Album) Cursor(android.database.Cursor) File(java.io.File) ImageFileFilter(org.horaapps.leafpic.data.base.ImageFileFilter)

Example 3 with ImageFileFilter

use of org.horaapps.leafpic.data.base.ImageFileFilter in project LeafPic by HoraApps.

the class StorageProvider method getMedia.

public static ArrayList<Media> getMedia(String path, boolean includeVideo) {
    ArrayList<Media> list = new ArrayList<Media>();
    File[] images = new File(path).listFiles(new ImageFileFilter(includeVideo));
    for (File image : images) list.add(new Media(image));
    return list;
}
Also used : ArrayList(java.util.ArrayList) Media(org.horaapps.leafpic.data.Media) File(java.io.File) ImageFileFilter(org.horaapps.leafpic.data.base.ImageFileFilter)

Aggregations

File (java.io.File)3 Media (org.horaapps.leafpic.data.Media)3 ImageFileFilter (org.horaapps.leafpic.data.base.ImageFileFilter)3 ArrayList (java.util.ArrayList)2 Album (org.horaapps.leafpic.data.Album)2 Cursor (android.database.Cursor)1