Added Nullity Annotations
This commit is contained in:
parent
1dcc447e52
commit
5317c51400
102 changed files with 772 additions and 404 deletions
|
|
@ -7,6 +7,8 @@ import android.provider.BaseColumns;
|
|||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.AlbumColumns;
|
||||
import android.provider.MediaStore.Audio.AudioColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
|
@ -18,22 +20,26 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class AlbumLoader {
|
||||
|
||||
public static ArrayList<Album> getAllAlbums(final Context context) {
|
||||
@NonNull
|
||||
public static ArrayList<Album> getAllAlbums(@NonNull final Context context) {
|
||||
Cursor cursor = makeAlbumCursor(context, null, null);
|
||||
return getAlbums(cursor);
|
||||
}
|
||||
|
||||
public static ArrayList<Album> getAlbums(final Context context, String query) {
|
||||
@NonNull
|
||||
public static ArrayList<Album> getAlbums(@NonNull final Context context, String query) {
|
||||
Cursor cursor = makeAlbumCursor(context, AlbumColumns.ALBUM + " LIKE ?", new String[]{"%" + query + "%"});
|
||||
return getAlbums(cursor);
|
||||
}
|
||||
|
||||
public static Album getAlbum(final Context context, int albumId) {
|
||||
@NonNull
|
||||
public static Album getAlbum(@NonNull final Context context, int albumId) {
|
||||
Cursor cursor = makeAlbumCursor(context, BaseColumns._ID + "=?", new String[]{String.valueOf(albumId)});
|
||||
return getAlbum(cursor);
|
||||
}
|
||||
|
||||
public static ArrayList<Album> getAlbums(final Cursor cursor) {
|
||||
@NonNull
|
||||
public static ArrayList<Album> getAlbums(@Nullable final Cursor cursor) {
|
||||
ArrayList<Album> albums = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
|
|
@ -46,7 +52,8 @@ public class AlbumLoader {
|
|||
return albums;
|
||||
}
|
||||
|
||||
public static Album getAlbum(final Cursor cursor) {
|
||||
@NonNull
|
||||
public static Album getAlbum(@Nullable final Cursor cursor) {
|
||||
Album album = new Album();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
album = getAlbumFromCursorImpl(cursor);
|
||||
|
|
@ -58,7 +65,8 @@ public class AlbumLoader {
|
|||
return album;
|
||||
}
|
||||
|
||||
private static Album getAlbumFromCursorImpl(final Cursor cursor) {
|
||||
@NonNull
|
||||
private static Album getAlbumFromCursorImpl(@NonNull final Cursor cursor) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String albumName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
|
|
@ -69,15 +77,15 @@ public class AlbumLoader {
|
|||
return new Album(id, albumName, artist, artistId, songCount, year);
|
||||
}
|
||||
|
||||
public static Cursor makeAlbumCursor(final Context context, final String selection, final String[] values) {
|
||||
public static Cursor makeAlbumCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||
return makeAlbumCursor(context, selection, values, PreferenceUtils.getInstance(context).getAlbumSortOrder());
|
||||
}
|
||||
|
||||
public static Cursor makeAlbumCursor(final Context context, final String selection, final String[] values, final String sortOrder) {
|
||||
public static Cursor makeAlbumCursor(@NonNull final Context context, final String selection, final String[] values, final String sortOrder) {
|
||||
return makeAlbumCursor(context, MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, selection, values, sortOrder);
|
||||
}
|
||||
|
||||
public static Cursor makeAlbumCursor(final Context context, final Uri contentUri, final String selection, final String[] values, final String sortOrder) {
|
||||
public static Cursor makeAlbumCursor(@NonNull final Context context, @NonNull final Uri contentUri, final String selection, final String[] values, final String sortOrder) {
|
||||
return context.getContentResolver().query(contentUri,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
|
@ -14,11 +15,12 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class AlbumSongLoader {
|
||||
|
||||
public static ArrayList<Song> getAlbumSongList(final Context context, final int albumId) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getAlbumSongList(@NonNull final Context context, final int albumId) {
|
||||
return SongLoader.getSongs(makeAlbumSongCursor(context, albumId));
|
||||
}
|
||||
|
||||
public static Cursor makeAlbumSongCursor(final Context context, final int albumId) {
|
||||
public static Cursor makeAlbumSongCursor(@NonNull final Context context, final int albumId) {
|
||||
return SongLoader.makeSongCursor(
|
||||
context,
|
||||
MediaStore.Audio.AudioColumns.ALBUM_ID + "=?",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
|
@ -14,11 +15,12 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class ArtistAlbumLoader {
|
||||
|
||||
public static ArrayList<Album> getArtistAlbumList(final Context context, final int artistId) {
|
||||
@NonNull
|
||||
public static ArrayList<Album> getArtistAlbumList(@NonNull final Context context, final int artistId) {
|
||||
return AlbumLoader.getAlbums(makeArtistAlbumCursor(context, artistId));
|
||||
}
|
||||
|
||||
public static Cursor makeArtistAlbumCursor(final Context context, final int artistId) {
|
||||
public static Cursor makeArtistAlbumCursor(@NonNull final Context context, final int artistId) {
|
||||
return AlbumLoader.makeAlbumCursor(context,
|
||||
MediaStore.Audio.Artists.Albums.getContentUri("external", artistId),
|
||||
null,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.ArtistColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
|
@ -16,22 +18,26 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class ArtistLoader {
|
||||
|
||||
public static ArrayList<Artist> getAllArtists(Context context) {
|
||||
@NonNull
|
||||
public static ArrayList<Artist> getAllArtists(@NonNull Context context) {
|
||||
Cursor cursor = makeArtistCursor(context, null, null);
|
||||
return getArtists(cursor);
|
||||
}
|
||||
|
||||
public static ArrayList<Artist> getArtists(Context context, String query) {
|
||||
@NonNull
|
||||
public static ArrayList<Artist> getArtists(@NonNull Context context, String query) {
|
||||
Cursor cursor = makeArtistCursor(context, ArtistColumns.ARTIST + " LIKE ?", new String[]{"%" + query + "%"});
|
||||
return getArtists(cursor);
|
||||
}
|
||||
|
||||
public static Artist getArtist(Context context, int artistId) {
|
||||
@NonNull
|
||||
public static Artist getArtist(@NonNull Context context, int artistId) {
|
||||
Cursor cursor = makeArtistCursor(context, BaseColumns._ID + "=?", new String[]{String.valueOf(artistId)});
|
||||
return getArtist(cursor);
|
||||
}
|
||||
|
||||
public static ArrayList<Artist> getArtists(Cursor cursor) {
|
||||
@NonNull
|
||||
public static ArrayList<Artist> getArtists(@Nullable Cursor cursor) {
|
||||
ArrayList<Artist> artists = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
|
|
@ -45,7 +51,8 @@ public class ArtistLoader {
|
|||
return artists;
|
||||
}
|
||||
|
||||
public static Artist getArtist(Cursor cursor) {
|
||||
@NonNull
|
||||
public static Artist getArtist(@Nullable Cursor cursor) {
|
||||
Artist artist = new Artist();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
artist = getArtistFromCursorImpl(cursor);
|
||||
|
|
@ -57,7 +64,8 @@ public class ArtistLoader {
|
|||
return artist;
|
||||
}
|
||||
|
||||
private static Artist getArtistFromCursorImpl(Cursor cursor) {
|
||||
@NonNull
|
||||
private static Artist getArtistFromCursorImpl(@NonNull Cursor cursor) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String artistName = cursor.getString(1);
|
||||
final int albumCount = cursor.getInt(2);
|
||||
|
|
@ -66,7 +74,7 @@ public class ArtistLoader {
|
|||
return new Artist(id, artistName, albumCount, songCount);
|
||||
}
|
||||
|
||||
public static Cursor makeArtistCursor(final Context context, final String selection, final String[] values) {
|
||||
public static Cursor makeArtistCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
|
@ -14,11 +15,12 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class ArtistSongLoader {
|
||||
|
||||
public static ArrayList<Song> getArtistSongList(final Context context, final int artistId) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getArtistSongList(@NonNull final Context context, final int artistId) {
|
||||
return SongLoader.getSongs(makeArtistSongCursor(context, artistId));
|
||||
}
|
||||
|
||||
public static Cursor makeArtistSongCursor(final Context context, final int artistId) {
|
||||
public static Cursor makeArtistSongCursor(@NonNull final Context context, final int artistId) {
|
||||
return SongLoader.makeSongCursor(
|
||||
context,
|
||||
MediaStore.Audio.AudioColumns.ARTIST_ID + "=?",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.loader;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
|
@ -11,11 +12,12 @@ import java.util.ArrayList;
|
|||
|
||||
public class LastAddedLoader {
|
||||
|
||||
public static ArrayList<Song> getLastAddedSongs(Context context) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getLastAddedSongs(@NonNull Context context) {
|
||||
return SongLoader.getSongs(makeLastAddedCursor(context));
|
||||
}
|
||||
|
||||
public static Cursor makeLastAddedCursor(final Context context) {
|
||||
public static Cursor makeLastAddedCursor(@NonNull final Context context) {
|
||||
long fourWeeksAgo = (System.currentTimeMillis() / 1000) - (4 * 3600 * 24 * 7);
|
||||
// possible saved timestamp caused by user "clearing" the last added playlist
|
||||
long cutoff = PreferenceUtils.getInstance(context).getLastAddedCutOffTimestamp() / 1000;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.PlaylistsColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
|
||||
|
|
@ -13,11 +15,13 @@ import java.util.List;
|
|||
|
||||
public class PlaylistLoader {
|
||||
|
||||
public static List<Playlist> getAllPlaylists(final Context context) {
|
||||
@NonNull
|
||||
public static List<Playlist> getAllPlaylists(@NonNull final Context context) {
|
||||
return getAllPlaylists(makePlaylistCursor(context, null, null));
|
||||
}
|
||||
|
||||
public static Playlist getPlaylist(final Context context, final int playlistId) {
|
||||
@NonNull
|
||||
public static Playlist getPlaylist(@NonNull final Context context, final int playlistId) {
|
||||
return getPlaylist(makePlaylistCursor(
|
||||
context,
|
||||
BaseColumns._ID + "=?",
|
||||
|
|
@ -27,7 +31,8 @@ public class PlaylistLoader {
|
|||
));
|
||||
}
|
||||
|
||||
public static Playlist getPlaylist(final Context context, final String playlistName) {
|
||||
@NonNull
|
||||
public static Playlist getPlaylist(@NonNull final Context context, final String playlistName) {
|
||||
return getPlaylist(makePlaylistCursor(
|
||||
context,
|
||||
PlaylistsColumns.NAME + "=?",
|
||||
|
|
@ -37,7 +42,8 @@ public class PlaylistLoader {
|
|||
));
|
||||
}
|
||||
|
||||
public static Playlist getPlaylist(final Cursor cursor) {
|
||||
@NonNull
|
||||
public static Playlist getPlaylist(@Nullable final Cursor cursor) {
|
||||
Playlist playlist = new Playlist();
|
||||
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
|
|
@ -48,7 +54,8 @@ public class PlaylistLoader {
|
|||
return playlist;
|
||||
}
|
||||
|
||||
public static List<Playlist> getAllPlaylists(final Cursor cursor) {
|
||||
@NonNull
|
||||
public static List<Playlist> getAllPlaylists(@Nullable final Cursor cursor) {
|
||||
List<Playlist> playlists = new ArrayList<>();
|
||||
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
|
|
@ -61,13 +68,14 @@ public class PlaylistLoader {
|
|||
return playlists;
|
||||
}
|
||||
|
||||
private static Playlist getPlaylistFromCursorImpl(final Cursor cursor) {
|
||||
@NonNull
|
||||
private static Playlist getPlaylistFromCursorImpl(@NonNull final Cursor cursor) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String name = cursor.getString(1);
|
||||
return new Playlist(id, name);
|
||||
}
|
||||
|
||||
public static Cursor makePlaylistCursor(final Context context, final String selection, final String[] values) {
|
||||
public static Cursor makePlaylistCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.AudioColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.model.PlaylistSong;
|
||||
|
||||
|
|
@ -11,7 +12,8 @@ import java.util.ArrayList;
|
|||
|
||||
public class PlaylistSongLoader {
|
||||
|
||||
public static ArrayList<PlaylistSong> getPlaylistSongList(final Context context, final int playlistId) {
|
||||
@NonNull
|
||||
public static ArrayList<PlaylistSong> getPlaylistSongList(@NonNull final Context context, final int playlistId) {
|
||||
ArrayList<PlaylistSong> songs = new ArrayList<>();
|
||||
Cursor cursor = makePlaylistSongCursor(context, playlistId);
|
||||
|
||||
|
|
@ -26,7 +28,8 @@ public class PlaylistSongLoader {
|
|||
return songs;
|
||||
}
|
||||
|
||||
private static PlaylistSong getPlaylistSongFromCursorImpl(Cursor cursor) {
|
||||
@NonNull
|
||||
private static PlaylistSong getPlaylistSongFromCursorImpl(@NonNull Cursor cursor) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String songName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
|
|
@ -42,7 +45,7 @@ public class PlaylistSongLoader {
|
|||
return new PlaylistSong(id, albumId, artistId, songName, artist, album, duration, trackNumber, data, playlistId, idInPlaylist);
|
||||
}
|
||||
|
||||
public static Cursor makePlaylistSongCursor(final Context context, final int playlistId) {
|
||||
public static Cursor makePlaylistSongCursor(@NonNull final Context context, final int playlistId) {
|
||||
return context.getContentResolver().query(
|
||||
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
|
||||
new String[]{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import android.database.Cursor;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.AudioColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtils;
|
||||
|
|
@ -17,22 +19,26 @@ import java.util.ArrayList;
|
|||
public class SongLoader {
|
||||
protected static final String BASE_SELECTION = AudioColumns.IS_MUSIC + "=1" + " AND " + AudioColumns.TITLE + " != ''";
|
||||
|
||||
public static ArrayList<Song> getAllSongs(Context context) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getAllSongs(@NonNull Context context) {
|
||||
Cursor cursor = makeSongCursor(context, null, null);
|
||||
return getSongs(cursor);
|
||||
}
|
||||
|
||||
public static ArrayList<Song> getSongs(final Context context, final String query) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getSongs(@NonNull final Context context, final String query) {
|
||||
Cursor cursor = makeSongCursor(context, AudioColumns.TITLE + " LIKE ?", new String[]{"%" + query + "%"});
|
||||
return getSongs(cursor);
|
||||
}
|
||||
|
||||
public static Song getSong(final Context context, final int queryId) {
|
||||
@NonNull
|
||||
public static Song getSong(@NonNull final Context context, final int queryId) {
|
||||
Cursor cursor = makeSongCursor(context, AudioColumns._ID + "=?", new String[]{String.valueOf(queryId)});
|
||||
return getSong(cursor);
|
||||
}
|
||||
|
||||
public static ArrayList<Song> getSongs(final Cursor cursor) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getSongs(@Nullable final Cursor cursor) {
|
||||
ArrayList<Song> songs = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
|
|
@ -45,7 +51,8 @@ public class SongLoader {
|
|||
return songs;
|
||||
}
|
||||
|
||||
public static Song getSong(Cursor cursor) {
|
||||
@NonNull
|
||||
public static Song getSong(@Nullable Cursor cursor) {
|
||||
Song song = new Song();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
song = getSongFromCursorImpl(cursor);
|
||||
|
|
@ -56,7 +63,8 @@ public class SongLoader {
|
|||
return song;
|
||||
}
|
||||
|
||||
private static Song getSongFromCursorImpl(Cursor cursor) {
|
||||
@NonNull
|
||||
private static Song getSongFromCursorImpl(@NonNull Cursor cursor) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String songName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
|
|
@ -69,11 +77,11 @@ public class SongLoader {
|
|||
return new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber, data);
|
||||
}
|
||||
|
||||
public static Cursor makeSongCursor(final Context context, final String selection, final String[] values) {
|
||||
public static Cursor makeSongCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||
return makeSongCursor(context, selection, values, PreferenceUtils.getInstance(context).getSongSortOrder());
|
||||
}
|
||||
|
||||
public static Cursor makeSongCursor(final Context context, final String selection, final String[] values, final String sortOrder) {
|
||||
public static Cursor makeSongCursor(@NonNull final Context context, @Nullable final String selection, final String[] values, final String sortOrder) {
|
||||
String baseSelection = BASE_SELECTION;
|
||||
if (selection != null && !selection.trim().equals("")) {
|
||||
baseSelection += " AND " + selection;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ package com.kabouzeid.gramophone.loader;
|
|||
|
||||
import android.database.AbstractCursor;
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -30,6 +32,7 @@ import java.util.List;
|
|||
*/
|
||||
public class SortedCursor extends AbstractCursor {
|
||||
// cursor to wrap
|
||||
@Nullable
|
||||
private final Cursor mCursor;
|
||||
// the map of external indices to internal indices
|
||||
private ArrayList<Integer> mOrderedPositions;
|
||||
|
|
@ -45,8 +48,8 @@ public class SortedCursor extends AbstractCursor {
|
|||
* @param order the list of unique ids in sorted order to display
|
||||
* @param columnName the column name of the id to look up in the internal cursor
|
||||
*/
|
||||
public SortedCursor(final Cursor cursor, final long[] order, final String columnName,
|
||||
final List<? extends Object> extraData) {
|
||||
public SortedCursor(@Nullable final Cursor cursor, final long[] order, final String columnName,
|
||||
final List<?> extraData) {
|
||||
if (cursor == null) {
|
||||
throw new IllegalArgumentException("Non-null cursor is needed");
|
||||
}
|
||||
|
|
@ -63,14 +66,15 @@ public class SortedCursor extends AbstractCursor {
|
|||
* @param extraData Extra data we want to add to the cursor
|
||||
* @return returns the ids that aren't found in the underlying cursor
|
||||
*/
|
||||
private ArrayList<Long> buildCursorPositionMapping(final long[] order,
|
||||
final String columnName, final List<? extends Object> extraData) {
|
||||
ArrayList<Long> missingIds = new ArrayList<Long>();
|
||||
@NonNull
|
||||
private ArrayList<Long> buildCursorPositionMapping(@Nullable final long[] order,
|
||||
final String columnName, @Nullable final List<?> extraData) {
|
||||
ArrayList<Long> missingIds = new ArrayList<>();
|
||||
|
||||
mOrderedPositions = new ArrayList<Integer>(mCursor.getCount());
|
||||
mExtraData = new ArrayList<Object>();
|
||||
mOrderedPositions = new ArrayList<>(mCursor.getCount());
|
||||
mExtraData = new ArrayList<>();
|
||||
|
||||
mMapCursorPositions = new HashMap<Long, Integer>(mCursor.getCount());
|
||||
mMapCursorPositions = new HashMap<>(mCursor.getCount());
|
||||
final int idPosition = mCursor.getColumnIndex(columnName);
|
||||
|
||||
if (mCursor.moveToFirst()) {
|
||||
|
|
@ -110,6 +114,7 @@ public class SortedCursor extends AbstractCursor {
|
|||
/**
|
||||
* @return the list of ids that were in the underlying cursor but not part of the ordered list
|
||||
*/
|
||||
@NonNull
|
||||
public Collection<Long> getExtraIds() {
|
||||
return mMapCursorPositions.keySet();
|
||||
}
|
||||
|
|
@ -117,6 +122,7 @@ public class SortedCursor extends AbstractCursor {
|
|||
/**
|
||||
* @return the extra object data that was passed in to be attached to the current row
|
||||
*/
|
||||
@Nullable
|
||||
public Object getExtraData() {
|
||||
int position = getPosition();
|
||||
return position < mExtraData.size() ? mExtraData.get(position) : null;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package com.kabouzeid.gramophone.loader;
|
|||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.provider.RecentlyPlayedStore;
|
||||
|
|
@ -29,15 +31,18 @@ import java.util.ArrayList;
|
|||
public class TopAndRecentlyPlayedTracksLoader {
|
||||
public static final int NUMBER_OF_TOP_TRACKS = 99;
|
||||
|
||||
public static ArrayList<Song> getRecentlyPlayedTracks(Context context) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getRecentlyPlayedTracks(@NonNull Context context) {
|
||||
return SongLoader.getSongs(makeRecentTracksCursorAndClearUpDatabase(context));
|
||||
}
|
||||
|
||||
public static ArrayList<Song> getTopTracks(Context context) {
|
||||
@NonNull
|
||||
public static ArrayList<Song> getTopTracks(@NonNull Context context) {
|
||||
return SongLoader.getSongs(makeTopTracksCursorAndClearUpDatabase(context));
|
||||
}
|
||||
|
||||
public static Cursor makeRecentTracksCursorAndClearUpDatabase(final Context context) {
|
||||
@Nullable
|
||||
public static Cursor makeRecentTracksCursorAndClearUpDatabase(@NonNull final Context context) {
|
||||
SortedCursor retCursor = makeRecentTracksCursorImpl(context);
|
||||
|
||||
// clean up the databases with any ids not found
|
||||
|
|
@ -52,7 +57,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
|||
return retCursor;
|
||||
}
|
||||
|
||||
public static Cursor makeTopTracksCursorAndClearUpDatabase(final Context context) {
|
||||
@Nullable
|
||||
public static Cursor makeTopTracksCursorAndClearUpDatabase(@NonNull final Context context) {
|
||||
SortedCursor retCursor = makeTopTracksCursorImpl(context);
|
||||
|
||||
// clean up the databases with any ids not found
|
||||
|
|
@ -67,7 +73,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
|||
return retCursor;
|
||||
}
|
||||
|
||||
private static SortedCursor makeRecentTracksCursorImpl(final Context context) {
|
||||
@Nullable
|
||||
private static SortedCursor makeRecentTracksCursorImpl(@NonNull final Context context) {
|
||||
// first get the top results ids from the internal database
|
||||
Cursor songs = RecentlyPlayedStore.getInstance(context).queryRecentIds();
|
||||
|
||||
|
|
@ -81,7 +88,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private static SortedCursor makeTopTracksCursorImpl(final Context context) {
|
||||
@Nullable
|
||||
private static SortedCursor makeTopTracksCursorImpl(@NonNull final Context context) {
|
||||
// first get the top results ids from the internal database
|
||||
Cursor songs = SongPlayCountStore.getInstance(context).getTopPlayedResults(NUMBER_OF_TOP_TRACKS);
|
||||
|
||||
|
|
@ -95,7 +103,8 @@ public class TopAndRecentlyPlayedTracksLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private static SortedCursor makeSortedCursor(final Context context, final Cursor cursor,
|
||||
@Nullable
|
||||
private static SortedCursor makeSortedCursor(@NonNull final Context context, @Nullable final Cursor cursor,
|
||||
final int idColumn) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
// create the list of ids to select against
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue