Renamed package to gramophone
This commit is contained in:
parent
200c50babf
commit
c28a75c61a
95 changed files with 412 additions and 415 deletions
|
|
@ -0,0 +1,104 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 29.12.14.
|
||||
*/
|
||||
public class AlbumLoader {
|
||||
|
||||
public static List<Album> getAllAlbums(Context context) {
|
||||
Cursor cursor = makeAlbumCursor(context);
|
||||
List<Album> albums = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final int id = cursor.getInt(0);
|
||||
final String albumName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
final int artistId = cursor.getInt(3);
|
||||
final int songCount = cursor.getInt(4);
|
||||
final int year = cursor.getInt(5);
|
||||
|
||||
final Album album = new Album(id, albumName, artist, artistId, songCount, year);
|
||||
albums.add(album);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return albums;
|
||||
}
|
||||
|
||||
public static final Cursor makeAlbumCursor(final Context context) {
|
||||
return makeAlbumCursor(context, null);
|
||||
}
|
||||
|
||||
public static final Cursor makeAlbumCursor(final Context context, String selection) {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
BaseColumns._ID,
|
||||
/* 1 */
|
||||
MediaStore.Audio.AlbumColumns.ALBUM,
|
||||
/* 2 */
|
||||
MediaStore.Audio.AlbumColumns.ARTIST,
|
||||
/* 3 */
|
||||
MediaStore.Audio.Media.ARTIST_ID,
|
||||
/* 4 */
|
||||
MediaStore.Audio.AlbumColumns.NUMBER_OF_SONGS,
|
||||
/* 5 */
|
||||
MediaStore.Audio.AlbumColumns.FIRST_YEAR
|
||||
}, selection, null, null);
|
||||
}
|
||||
|
||||
public static Album getAlbum(Context context, int albumId) {
|
||||
Cursor cursor = makeAlbumCursor(context, BaseColumns._ID + "=" + albumId);
|
||||
Album album = new Album();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String albumName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
final int artistId = cursor.getInt(3);
|
||||
final int songCount = cursor.getInt(4);
|
||||
final int year = cursor.getInt(5);
|
||||
|
||||
album = new Album(id, albumName, artist, artistId, songCount, year);
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return album;
|
||||
}
|
||||
|
||||
public static List<Album> getAlbums(Context context, String query) {
|
||||
Cursor cursor = makeAlbumCursor(context, MediaStore.Audio.AlbumColumns.ALBUM + " LIKE '%" + query + "%'");
|
||||
List<Album> albums = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final String albumName = cursor.getString(1);
|
||||
final int id = cursor.getInt(0);
|
||||
final String artist = cursor.getString(2);
|
||||
final int artistId = cursor.getInt(3);
|
||||
final int songCount = cursor.getInt(4);
|
||||
final int year = cursor.getInt(5);
|
||||
|
||||
final Album album = new Album(id, albumName, artist, artistId, songCount, year);
|
||||
albums.add(album);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return albums;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 29.12.14.
|
||||
*/
|
||||
public class AlbumSongLoader {
|
||||
|
||||
public static List<Song> getAlbumSongList(final Context context, final int albumId, Comparator<Song> comparator) {
|
||||
List<Song> songs = getAlbumSongList(context, albumId);
|
||||
Collections.sort(songs, comparator);
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static List<Song> getAlbumSongList(final Context context, final int albumId) {
|
||||
Cursor cursor = makeAlbumSongCursor(context, albumId);
|
||||
List<Song> songs = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final int id = cursor.getInt(0);
|
||||
final String songName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
final String album = cursor.getString(3);
|
||||
final long duration = cursor.getLong(4);
|
||||
final int trackNumber = cursor.getInt(5);
|
||||
final int artistId = cursor.getInt(6);
|
||||
|
||||
final Song song = new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber);
|
||||
songs.add(song);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static final Cursor makeAlbumSongCursor(final Context context, final int albumId) {
|
||||
final StringBuilder selection = new StringBuilder();
|
||||
selection.append(MediaStore.Audio.AudioColumns.IS_MUSIC + "=1");
|
||||
selection.append(" AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''");
|
||||
selection.append(" AND " + MediaStore.Audio.AudioColumns.ALBUM_ID + "=" + albumId);
|
||||
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
BaseColumns._ID,
|
||||
/* 1 */
|
||||
MediaStore.Audio.AudioColumns.TITLE,
|
||||
/* 2 */
|
||||
MediaStore.Audio.AudioColumns.ARTIST,
|
||||
/* 3 */
|
||||
MediaStore.Audio.AudioColumns.ALBUM,
|
||||
/* 4 */
|
||||
MediaStore.Audio.AudioColumns.DURATION,
|
||||
/* 5 */
|
||||
MediaStore.Audio.AudioColumns.TRACK,
|
||||
/* 6 */
|
||||
MediaStore.Audio.AudioColumns.ARTIST_ID
|
||||
}, selection.toString(), null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 04.01.15.
|
||||
*/
|
||||
public class ArtistAlbumLoader {
|
||||
public static List<Album> getArtistAlbumList(final Context context, final int artistId) {
|
||||
Cursor cursor = makeArtistAlbumCursor(context, artistId);
|
||||
List<Album> albums = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final int id = cursor.getInt(0);
|
||||
final String albumName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
final int songCount = cursor.getInt(3);
|
||||
final int year = cursor.getInt(4);
|
||||
|
||||
final Album album = new Album(id, albumName, artist, artistId, songCount, year);
|
||||
albums.add(album);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return albums;
|
||||
}
|
||||
|
||||
public static Cursor makeArtistAlbumCursor(final Context context, final int artistId) {
|
||||
if (artistId == -1) return null;
|
||||
return context.getContentResolver().query(
|
||||
MediaStore.Audio.Artists.Albums.getContentUri("external", artistId), new String[]{
|
||||
/* 0 */
|
||||
BaseColumns._ID,
|
||||
/* 1 */
|
||||
MediaStore.Audio.AlbumColumns.ALBUM,
|
||||
/* 2 */
|
||||
MediaStore.Audio.AlbumColumns.ARTIST,
|
||||
/* 3 */
|
||||
MediaStore.Audio.AlbumColumns.NUMBER_OF_SONGS,
|
||||
/* 4 */
|
||||
MediaStore.Audio.AlbumColumns.FIRST_YEAR
|
||||
}, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 29.12.14.
|
||||
*/
|
||||
public class ArtistLoader {
|
||||
|
||||
public static List<Artist> getAllArtists(Context context) {
|
||||
Cursor cursor = makeArtistCursor(context);
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final int id = cursor.getInt(0);
|
||||
final String artistName = cursor.getString(1);
|
||||
final int albumCount = cursor.getInt(2);
|
||||
final int songCount = cursor.getInt(3);
|
||||
|
||||
final Artist artist = new Artist(id, artistName, albumCount, songCount);
|
||||
artists.add(artist);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return artists;
|
||||
}
|
||||
|
||||
public static final Cursor makeArtistCursor(final Context context) {
|
||||
return makeArtistCursor(context, null);
|
||||
}
|
||||
|
||||
public static final Cursor makeArtistCursor(final Context context, String selection) {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
BaseColumns._ID,
|
||||
/* 1 */
|
||||
MediaStore.Audio.ArtistColumns.ARTIST,
|
||||
/* 2 */
|
||||
MediaStore.Audio.ArtistColumns.NUMBER_OF_ALBUMS,
|
||||
/* 3 */
|
||||
MediaStore.Audio.ArtistColumns.NUMBER_OF_TRACKS
|
||||
}, selection, null, null);
|
||||
}
|
||||
|
||||
public static Artist getArtist(Context context, int artistId) {
|
||||
Cursor cursor = makeArtistCursor(context, BaseColumns._ID + "=" + artistId);
|
||||
Artist artist = new Artist();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String artistName = cursor.getString(1);
|
||||
final int albumCount = cursor.getInt(2);
|
||||
final int songCount = cursor.getInt(3);
|
||||
|
||||
artist = new Artist(id, artistName, albumCount, songCount);
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return artist;
|
||||
}
|
||||
|
||||
public static List<Artist> getArtists(Context context, String query) {
|
||||
Cursor cursor = makeArtistCursor(context, MediaStore.Audio.ArtistColumns.ARTIST + " LIKE '%" + query + "%'");
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final String artistName = cursor.getString(1);
|
||||
final int id = cursor.getInt(0);
|
||||
final int albumCount = cursor.getInt(2);
|
||||
final int songCount = cursor.getInt(3);
|
||||
|
||||
final Artist artist = new Artist(id, artistName, albumCount, songCount);
|
||||
artists.add(artist);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return artists;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 01.01.15.
|
||||
*/
|
||||
public class ArtistSongLoader {
|
||||
public static List<Song> getArtistSongList(final Context context, final int artistId) {
|
||||
Cursor cursor = makeArtistSongCursor(context, artistId);
|
||||
List<Song> songs = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final int id = cursor.getInt(0);
|
||||
final String songName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
final String album = cursor.getString(3);
|
||||
final long duration = cursor.getLong(4);
|
||||
final int trackNumber = cursor.getInt(5);
|
||||
final int albumId = cursor.getInt(6);
|
||||
|
||||
final Song song = new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber);
|
||||
songs.add(song);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static Cursor makeArtistSongCursor(final Context context, final int artistId) {
|
||||
final StringBuilder selection = new StringBuilder();
|
||||
selection.append(MediaStore.Audio.AudioColumns.IS_MUSIC + "=1");
|
||||
selection.append(" AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''");
|
||||
selection.append(" AND " + MediaStore.Audio.AudioColumns.ARTIST_ID + "=" + artistId);
|
||||
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
BaseColumns._ID,
|
||||
/* 1 */
|
||||
MediaStore.Audio.AudioColumns.TITLE,
|
||||
/* 2 */
|
||||
MediaStore.Audio.AudioColumns.ARTIST,
|
||||
/* 3 */
|
||||
MediaStore.Audio.AudioColumns.ALBUM,
|
||||
/* 4 */
|
||||
MediaStore.Audio.AudioColumns.DURATION,
|
||||
/* 5 */
|
||||
MediaStore.Audio.AudioColumns.TRACK,
|
||||
/* 6 */
|
||||
MediaStore.Audio.AudioColumns.ALBUM_ID
|
||||
}, selection.toString(), null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 11.01.15.
|
||||
*/
|
||||
public class SongFilePathLoader {
|
||||
public static final String TAG = SongFilePathLoader.class.getSimpleName();
|
||||
|
||||
public static List<String> getSongFilePaths(Context context, int[] queryIds) {
|
||||
StringBuilder selectionBuilder = new StringBuilder();
|
||||
selectionBuilder.append(BaseColumns._ID).append(" IN(");
|
||||
for (int i = 0; i < queryIds.length; i++) {
|
||||
selectionBuilder.append(queryIds[i]);
|
||||
if (i < queryIds.length - 1) {
|
||||
selectionBuilder.append(",");
|
||||
}
|
||||
}
|
||||
selectionBuilder.append(")");
|
||||
Cursor cursor = makeSongFilePathCursor(context, selectionBuilder.toString());
|
||||
List<String> songFiles = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
songFiles.add(cursor.getString(0));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return songFiles;
|
||||
}
|
||||
|
||||
public static String getSongFilePath(Context context, int queryId){
|
||||
try {
|
||||
return getSongFilePaths(context, new int[]{queryId}).get(0);
|
||||
} catch (Exception e){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static final Cursor makeSongFilePathCursor(final Context context) {
|
||||
return makeSongFilePathCursor(context, null);
|
||||
}
|
||||
|
||||
public static final Cursor makeSongFilePathCursor(final Context context, String selection) {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
MediaStore.Audio.AudioColumns.DATA,
|
||||
}, selection, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by karim on 29.12.14.
|
||||
*/
|
||||
public class SongLoader {
|
||||
public static List<Song> getAllSongs(Context context) {
|
||||
Cursor cursor = makeSongCursor(context);
|
||||
List<Song> songs = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final int id = cursor.getInt(0);
|
||||
final String songName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
final String album = cursor.getString(3);
|
||||
final long duration = cursor.getLong(4);
|
||||
final int trackNumber = cursor.getInt(5);
|
||||
final int artistId = cursor.getInt(6);
|
||||
final int albumId = cursor.getInt(7);
|
||||
|
||||
final Song song = new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber);
|
||||
songs.add(song);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static final Cursor makeSongCursor(final Context context) {
|
||||
return makeSongCursor(context, (MediaStore.Audio.AudioColumns.IS_MUSIC + "=1"));
|
||||
}
|
||||
|
||||
public static final Cursor makeSongCursor(final Context context, final String selection) {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
BaseColumns._ID,
|
||||
/* 1 */
|
||||
MediaStore.Audio.AudioColumns.TITLE,
|
||||
/* 2 */
|
||||
MediaStore.Audio.AudioColumns.ARTIST,
|
||||
/* 3 */
|
||||
MediaStore.Audio.AudioColumns.ALBUM,
|
||||
/* 4 */
|
||||
MediaStore.Audio.AudioColumns.DURATION,
|
||||
/* 5 */
|
||||
MediaStore.Audio.AudioColumns.TRACK,
|
||||
/* 6 */
|
||||
MediaStore.Audio.AudioColumns.ARTIST_ID,
|
||||
/* 7 */
|
||||
MediaStore.Audio.AudioColumns.ALBUM_ID
|
||||
}, selection, null, null);
|
||||
}
|
||||
|
||||
public static List<Song> getSongs(Context context, String query) {
|
||||
Cursor cursor = makeSongCursor(context, MediaStore.Audio.AudioColumns.TITLE + " LIKE '%" + query + "%'");
|
||||
List<Song> songs = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
final String songName = cursor.getString(1);
|
||||
final int id = cursor.getInt(0);
|
||||
final String artist = cursor.getString(2);
|
||||
final String album = cursor.getString(3);
|
||||
final long duration = cursor.getLong(4);
|
||||
final int trackNumber = cursor.getInt(5);
|
||||
final int artistId = cursor.getInt(6);
|
||||
final int albumId = cursor.getInt(7);
|
||||
|
||||
final Song song = new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber);
|
||||
songs.add(song);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static Song getSong(Context context, int queryId) {
|
||||
Cursor cursor = makeSongCursor(context, MediaStore.Audio.AudioColumns._ID + "=" + queryId);
|
||||
Song song = null;
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String songName = cursor.getString(1);
|
||||
final String artist = cursor.getString(2);
|
||||
final String album = cursor.getString(3);
|
||||
final long duration = cursor.getLong(4);
|
||||
final int trackNumber = cursor.getInt(5);
|
||||
final int artistId = cursor.getInt(6);
|
||||
final int albumId = cursor.getInt(7);
|
||||
song = new Song(id, albumId, artistId, songName, artist, album, duration, trackNumber);
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return song;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue