Search in sources :

Example 1 with MediaStoreRetriever

use of us.koller.cameraroll.data.provider.retriever.MediaStoreRetriever in project Camera-Roll-Android-App by kollerlukas.

the class MediaProvider method loadAlbums.

public void loadAlbums(final Activity context, final boolean hiddenFolders, OnMediaLoadedCallback callback) {
    if (!MediaProvider.checkPermission(context)) {
        callback.needPermission();
        return;
    }
    int mode = getMode(context);
    switch(mode) {
        case MODE_STORAGE:
            retriever = new StorageRetriever();
            break;
        case MODE_MEDIASTORE:
            retriever = new MediaStoreRetriever();
            break;
        default:
            break;
    }
    if (retriever != null) {
        setCallback(callback);
        retriever.loadAlbums(context, hiddenFolders, new OnMediaLoadedCallback() {

            @Override
            public void onMediaLoaded(ArrayList<Album> albums) {
                // remove excluded albums
                for (int i = albums.size() - 1; i >= 0; i--) {
                    if (albums.get(i) == null || albums.get(i).excluded) {
                        albums.remove(i);
                    }
                }
                SortUtil.sortAlbums(context, albums);
                setAlbums(albums);
                OnMediaLoadedCallback callback = getCallback();
                if (callback != null) {
                    callback.onMediaLoaded(albums);
                }
            }

            @Override
            public void timeout() {
                OnMediaLoadedCallback callback = getCallback();
                if (callback != null) {
                    callback.timeout();
                }
            }

            @Override
            public void needPermission() {
                OnMediaLoadedCallback callback = getCallback();
                if (callback != null) {
                    callback.needPermission();
                }
            }
        });
    } else {
        if (callback != null) {
            callback.onMediaLoaded(null);
        }
    }
}
Also used : StorageRetriever(us.koller.cameraroll.data.provider.retriever.StorageRetriever) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) MediaStoreRetriever(us.koller.cameraroll.data.provider.retriever.MediaStoreRetriever)

Aggregations

Album (us.koller.cameraroll.data.models.Album)1 VirtualAlbum (us.koller.cameraroll.data.models.VirtualAlbum)1 MediaStoreRetriever (us.koller.cameraroll.data.provider.retriever.MediaStoreRetriever)1 StorageRetriever (us.koller.cameraroll.data.provider.retriever.StorageRetriever)1