Search in sources :

Example 21 with Album

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

the class SortUtil method sortAlbums.

public static void sortAlbums(Activity context, ArrayList<Album> albums) {
    Settings settings = Settings.getInstance(context);
    int sortAlbumBy = settings.sortAlbumBy();
    for (int i = 0; i < albums.size(); i++) {
        sort(albums.get(i).getAlbumItems(), sortAlbumBy);
    }
    int sortAlbumsBy = settings.sortAlbumsBy();
    switch(sortAlbumsBy) {
        case BY_NAME:
        case BY_DATE:
            sort(albums, sortAlbumsBy);
            return;
        case BY_SIZE:
            // Sorting
            Collections.sort(albums, new Comparator<Album>() {

                @Override
                public int compare(Album a1, Album a2) {
                    if (a1 != null && a2 != null) {
                        if (a1.pinned() ^ a2.pinned()) {
                            return a2.pinned() ? 1 : -1;
                        }
                        Integer a1_size = a1.getAlbumItems().size();
                        Integer a2_size = a2.getAlbumItems().size();
                        return a2_size.compareTo(a1_size);
                    }
                    return 0;
                }
            });
            break;
        default:
            break;
    }
}
Also used : Album(us.koller.cameraroll.data.models.Album) Settings(us.koller.cameraroll.data.Settings)

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