Loaders sort returne data, not including playlist songs since they should be ordered by added time. Java's collection sorting uses quick sort so there shouldn't be noticeable hits to performance.
This commit is contained in:
parent
ad627943fb
commit
5671f651e5
9 changed files with 53 additions and 28 deletions
|
|
@ -7,7 +7,7 @@ import java.util.Comparator;
|
|||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
class AlbumAlphabeticComparator implements Comparator<Album> {
|
||||
public class AlbumAlphabeticComparator implements Comparator<Album> {
|
||||
@Override
|
||||
public int compare(Album lhs, Album rhs) {
|
||||
return lhs.title.trim().compareToIgnoreCase(rhs.title.trim());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package com.kabouzeid.gramophone.comparator;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class PlaylistAlphabeticComparator implements Comparator<Playlist> {
|
||||
@Override
|
||||
public int compare(Playlist lhs, Playlist rhs) {
|
||||
return lhs.name.trim().compareToIgnoreCase(rhs.name.trim());
|
||||
}
|
||||
}
|
||||
|
|
@ -5,10 +5,12 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.comparator.AlbumAlphabeticComparator;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -32,10 +34,10 @@ public class AlbumLoader {
|
|||
albums.add(album);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(albums, new AlbumAlphabeticComparator());
|
||||
return albums;
|
||||
}
|
||||
|
||||
|
|
@ -100,6 +102,7 @@ public class AlbumLoader {
|
|||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(albums, new AlbumAlphabeticComparator());
|
||||
return albums;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.comparator.SongAlphabeticComparator;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
||||
|
|
@ -17,13 +18,11 @@ import java.util.Comparator;
|
|||
*/
|
||||
public class AlbumSongLoader {
|
||||
|
||||
public static ArrayList<Song> getAlbumSongList(final Context context, final int albumId, Comparator<Song> comparator) {
|
||||
ArrayList<Song> songs = getAlbumSongList(context, albumId);
|
||||
Collections.sort(songs, comparator);
|
||||
return songs;
|
||||
public static ArrayList<Song> getAlbumSongList(final Context context, final int albumId) {
|
||||
return getAlbumSongList(context, albumId, null);
|
||||
}
|
||||
|
||||
public static ArrayList<Song> getAlbumSongList(final Context context, final int albumId) {
|
||||
public static ArrayList<Song> getAlbumSongList(final Context context, final int albumId, Comparator<Song> comparator) {
|
||||
Cursor cursor = makeAlbumSongCursor(context, albumId);
|
||||
ArrayList<Song> songs = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
|
|
@ -40,10 +39,11 @@ public class AlbumSongLoader {
|
|||
songs.add(song);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
if (comparator == null)
|
||||
comparator = new SongAlphabeticComparator();
|
||||
Collections.sort(songs, comparator);
|
||||
return songs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,16 +5,19 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.comparator.AlbumAlphabeticComparator;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistAlbumLoader {
|
||||
|
||||
public static List<Album> getArtistAlbumList(final Context context, final int artistId) {
|
||||
Cursor cursor = makeArtistAlbumCursor(context, artistId);
|
||||
List<Album> albums = new ArrayList<>();
|
||||
|
|
@ -30,10 +33,9 @@ public class ArtistAlbumLoader {
|
|||
albums.add(album);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(albums, new AlbumAlphabeticComparator());
|
||||
return albums;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.comparator.ArtistAlphabeticComparator;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -30,10 +32,9 @@ public class ArtistLoader {
|
|||
artists.add(artist);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(artists, new ArtistAlphabeticComparator());
|
||||
return artists;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.comparator.SongAlphabeticComparator;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
|
@ -32,10 +34,9 @@ public class ArtistSongLoader {
|
|||
songs.add(song);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(songs, new SongAlphabeticComparator());
|
||||
return songs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ import android.provider.BaseColumns;
|
|||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.PlaylistsColumns;
|
||||
|
||||
import com.kabouzeid.gramophone.comparator.PlaylistAlphabeticComparator;
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistLoader {
|
||||
|
||||
public static Playlist getPlaylist(final Context context, final int playlistId) {
|
||||
Playlist playlist = new Playlist();
|
||||
Cursor cursor = makePlaylistCursor(context, BaseColumns._ID + "=?", new String[]{String.valueOf(playlistId)});
|
||||
|
|
@ -21,9 +24,8 @@ public class PlaylistLoader {
|
|||
final String name = cursor.getString(1);
|
||||
playlist = new Playlist(id, name);
|
||||
}
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return playlist;
|
||||
}
|
||||
|
||||
|
|
@ -39,9 +41,9 @@ public class PlaylistLoader {
|
|||
playlists.add(playlist);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(playlists, new PlaylistAlphabeticComparator());
|
||||
return playlists;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.comparator.SongAlphabeticComparator;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -35,10 +37,9 @@ public class SongLoader {
|
|||
songs.add(song);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(songs, new SongAlphabeticComparator());
|
||||
return songs;
|
||||
}
|
||||
|
||||
|
|
@ -92,9 +93,9 @@ public class SongLoader {
|
|||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
Collections.sort(songs, new SongAlphabeticComparator());
|
||||
return songs;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue