Search in sources :

Example 6 with Album

use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.

the class MediaProvider method getAlbumsWithVirtualDirectories.

public static ArrayList<Album> getAlbumsWithVirtualDirectories(Activity context) {
    Settings s = Settings.getInstance(context);
    boolean virtualDirs = s.getVirtualDirectories();
    if (!virtualDirs) {
        return getAlbums();
    }
    ArrayList<VirtualAlbum> virtualAlbums = getVirtualAlbums(context);
    ArrayList<Album> albums = getAlbums();
    if (albums == null || virtualAlbums == null) {
        return albums;
    }
    // noinspection unchecked
    albums = (ArrayList<Album>) getAlbums().clone();
    ArrayList<Album> albumsWithVirtualDirs = new ArrayList<>();
    for (int i = virtualAlbums.size() - 1; i >= 0; i--) {
        VirtualAlbum virtualAlbum = virtualAlbums.get(i);
        if (virtualAlbum.getDirectories().size() > 0) {
            virtualAlbum.create(context, albums);
            if (virtualAlbum.getAlbumItems().size() > 0) {
                albumsWithVirtualDirs.add(virtualAlbum);
            }
        }
    }
    albumsWithVirtualDirs.addAll(albums);
    for (int i = albumsWithVirtualDirs.size() - 1; i >= 0; i--) {
        Album album = albumsWithVirtualDirs.get(i);
        if (!(album instanceof VirtualAlbum)) {
            for (int k = 0; k < virtualAlbums.size(); k++) {
                if (virtualAlbums.get(k).contains(album.getPath())) {
                    albumsWithVirtualDirs.remove(i);
                    break;
                }
            }
        }
    }
    SortUtil.sortAlbums(context, albumsWithVirtualDirs);
    return albumsWithVirtualDirs;
}
Also used : ArrayList(java.util.ArrayList) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Settings(us.koller.cameraroll.data.Settings)

Example 7 with Album

use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.

the class MediaProvider method getErrorAlbum.

public static Album getErrorAlbum() {
    // Error album
    Album album = new Album().setPath("ERROR");
    album.getAlbumItems().add(AlbumItem.getErrorItem());
    return album;
}
Also used : VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album)

Example 8 with Album

use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.

the class MediaProvider method loadAlbum.

public static void loadAlbum(final Activity context, final String path, final OnAlbumLoadedCallback callback) {
    if (path == null) {
        context.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                callback.onAlbumLoaded(null);
            }
        });
        return;
    }
    if (albums == null) {
        Settings s = Settings.getInstance(context);
        boolean hiddenFolders = s.getHiddenFolders();
        new MediaProvider(context).loadAlbums(context, hiddenFolders, new OnMediaLoadedCallback() {

            @Override
            public void onMediaLoaded(ArrayList<Album> albums) {
                loadAlbum(context, path, callback);
            }

            @Override
            public void timeout() {
                callback.onAlbumLoaded(getErrorAlbum());
            }

            @Override
            public void needPermission() {
                callback.onAlbumLoaded(getErrorAlbum());
            }
        });
    } else {
        if (path.startsWith(VirtualAlbum.VIRTUAL_ALBUMS_DIR)) {
            ArrayList<VirtualAlbum> virtualDirectories = getVirtualAlbums(context);
            for (int i = 0; i < virtualDirectories.size(); i++) {
                if (virtualDirectories.get(i).getPath().equals(path)) {
                    final VirtualAlbum album = virtualDirectories.get(i);
                    album.create(context, albums);
                    context.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            callback.onAlbumLoaded(album);
                        }
                    });
                    return;
                }
            }
        } else if (path.equals(SINGLE_FOLDER_PATH)) {
            final Album album = new Album().setPath(MediaProvider.SINGLE_FOLDER_PATH);
            for (int i = 0; i < albums.size(); i++) {
                album.getAlbumItems().addAll(albums.get(i).getAlbumItems());
            }
            int sortBy = Settings.getInstance(context).sortAlbumsBy();
            SortUtil.sort(album.getAlbumItems(), sortBy);
            context.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    callback.onAlbumLoaded(album);
                }
            });
        } else {
            for (int i = 0; i < albums.size(); i++) {
                if (albums.get(i).getPath().equals(path)) {
                    final Album album = albums.get(i);
                    context.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            callback.onAlbumLoaded(album);
                        }
                    });
                    return;
                }
            }
        }
    }
}
Also used : VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Settings(us.koller.cameraroll.data.Settings)

Example 9 with Album

use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.

the class MediaStoreRetriever method checkHiddenFolders.

private ArrayList<Album> checkHiddenFolders(final Activity context) {
    ArrayList<Album> hiddenAlbums = new ArrayList<>();
    // Scan all no Media files
    String nonMediaCondition = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
    // Files with name contain .nomedia
    String selection = nonMediaCondition + " AND " + MediaStore.Files.FileColumns.TITLE + " LIKE ?";
    String[] params = new String[] { "%" + MediaProvider.FILE_TYPE_NO_MEDIA + "%" };
    // make query for non media files with file title contain ".nomedia" as
    // text on External Media URI
    Cursor cursor = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), new String[] { MediaStore.Files.FileColumns.DATA }, selection, params, MediaStore.Images.Media.DATE_TAKEN);
    if (cursor == null || cursor.getCount() == 0) {
        return hiddenAlbums;
    }
    if (cursor.moveToFirst()) {
        int pathColumn = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
        do {
            String path = cursor.getString(pathColumn);
            path = path.replace(MediaProvider.FILE_TYPE_NO_MEDIA, "");
            File dir = new File(path);
            final Album album = new Album().setPath(path);
            File[] files = dir.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    AlbumItem albumItem = AlbumItem.getInstance(files[i].getPath());
                    if (albumItem != null) {
                        album.getAlbumItems().add(albumItem);
                    }
                }
            }
            if (album.getAlbumItems().size() > 0) {
                hiddenAlbums.add(album);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return hiddenAlbums;
}
Also used : ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Cursor(android.database.Cursor) File(java.io.File)

Example 10 with Album

use of us.koller.cameraroll.data.models.Album in project Camera-Roll-Android-App by kollerlukas.

the class MediaStoreRetriever method loadAlbums.

@Override
void loadAlbums(final Activity context, boolean hiddenFolders) {
    final long startTime = System.currentTimeMillis();
    final ArrayList<Album> albums = new ArrayList<>();
    // Return only video and image metadata.
    String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
    Uri queryUri = MediaStore.Files.getContentUri("external");
    CursorLoader cursorLoader = new CursorLoader(context, queryUri, projection, selection, // Selection args (none).
    null, MediaStore.Files.FileColumns.DATE_ADDED);
    final Cursor cursor = cursorLoader.loadInBackground();
    if (cursor == null) {
        return;
    }
    // search hiddenFolders
    if (hiddenFolders) {
        ArrayList<Album> hiddenAlbums = checkHiddenFolders(context);
        albums.addAll(hiddenAlbums);
    }
    AsyncTask.execute(new Runnable() {

        @Override
        public void run() {
            if (cursor.moveToFirst()) {
                String path;
                long dateTaken, id;
                int pathColumn = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
                int idColumn = cursor.getColumnIndex(BaseColumns._ID);
                do {
                    path = cursor.getString(pathColumn);
                    AlbumItem albumItem = AlbumItem.getInstance(context, path);
                    if (albumItem != null) {
                        // set dateTaken
                        int dateTakenColumn = cursor.getColumnIndex(!(albumItem instanceof Video) ? MediaStore.Images.ImageColumns.DATE_TAKEN : MediaStore.Video.VideoColumns.DATE_TAKEN);
                        dateTaken = cursor.getLong(dateTakenColumn);
                        albumItem.setDate(dateTaken);
                        id = cursor.getLong(idColumn);
                        Uri uri = ContentUris.withAppendedId(MediaStore.Files.getContentUri("external"), id);
                        albumItem.setUri(uri);
                        // search bucket
                        boolean foundBucket = false;
                        for (int i = 0; i < albums.size(); i++) {
                            if (albums.get(i).getPath().equals(FileOperation.Util.getParentPath(path))) {
                                albums.get(i).getAlbumItems().add(0, albumItem);
                                foundBucket = true;
                                break;
                            }
                        }
                        if (!foundBucket) {
                            // no bucket found
                            String bucketPath = FileOperation.Util.getParentPath(path);
                            if (bucketPath != null) {
                                albums.add(new Album().setPath(bucketPath));
                                albums.get(albums.size() - 1).getAlbumItems().add(0, albumItem);
                            }
                        }
                    }
                } while (cursor.moveToNext());
            }
            cursor.close();
            // done loading media with content resolver
            MediaProvider.OnMediaLoadedCallback callback = getCallback();
            if (callback != null) {
                callback.onMediaLoaded(albums);
            }
            Log.d("MediaStoreRetriever", "onMediaLoaded(): " + String.valueOf(System.currentTimeMillis() - startTime) + " ms");
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Cursor(android.database.Cursor) Uri(android.net.Uri) CursorLoader(android.support.v4.content.CursorLoader) Video(us.koller.cameraroll.data.models.Video)

Aggregations

Album (us.koller.cameraroll.data.models.Album)21 MediaProvider (us.koller.cameraroll.data.provider.MediaProvider)8 Intent (android.content.Intent)7 RecyclerView (android.support.v7.widget.RecyclerView)7 View (android.view.View)6 ArrayList (java.util.ArrayList)6 VirtualAlbum (us.koller.cameraroll.data.models.VirtualAlbum)5 Context (android.content.Context)4 Settings (us.koller.cameraroll.data.Settings)4 Activity (android.app.Activity)3 BroadcastReceiver (android.content.BroadcastReceiver)3 Uri (android.net.Uri)3 RequiresApi (android.support.annotation.RequiresApi)3 ActionBar (android.support.v7.app.ActionBar)3 SpannableString (android.text.SpannableString)3 AlbumItem (us.koller.cameraroll.data.models.AlbumItem)3 FastScrollerRecyclerView (us.koller.cameraroll.ui.widget.FastScrollerRecyclerView)3 Cursor (android.database.Cursor)2 Handler (android.os.Handler)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2