Improved the artist loading mechanism.
This commit is contained in:
parent
ca238fc69a
commit
8a4d364c14
19 changed files with 160 additions and 240 deletions
|
|
@ -83,15 +83,15 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
|||
break;
|
||||
case ARTIST:
|
||||
final Artist artist = (Artist) dataSet.get(position);
|
||||
holder.title.setText(artist.name);
|
||||
holder.title.setText(artist.getName());
|
||||
holder.text.setText(MusicUtil.getArtistInfoString(activity, artist));
|
||||
Glide.with(activity)
|
||||
.load(new ArtistImage(artist.name, false))
|
||||
.load(new ArtistImage(artist.getName(), false))
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.placeholder(R.drawable.default_artist_image)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.priority(Priority.LOW)
|
||||
.signature(ArtistSignatureUtil.getInstance(activity).getArtistSignature(artist.name))
|
||||
.signature(ArtistSignatureUtil.getInstance(activity).getArtistSignature(artist.getName()))
|
||||
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
|
||||
.into(holder.image);
|
||||
break;
|
||||
|
|
@ -169,7 +169,7 @@ public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder
|
|||
break;
|
||||
case ARTIST:
|
||||
NavigationUtil.goToArtist(activity,
|
||||
((Artist) item).id,
|
||||
((Artist) item).getId(),
|
||||
Pair.create(image,
|
||||
activity.getResources().getString(R.string.transition_artist_image)
|
||||
));
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
|||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.menu.SongsMenuHelper;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.loader.ArtistSongLoader;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.ArtistSignatureUtil;
|
||||
|
|
@ -74,7 +73,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return dataSet.get(position).id;
|
||||
return dataSet.get(position).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -105,7 +104,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
}
|
||||
|
||||
if (holder.title != null) {
|
||||
holder.title.setText(artist.name);
|
||||
holder.title.setText(artist.getName());
|
||||
}
|
||||
if (holder.text != null) {
|
||||
holder.text.setText(MusicUtil.getArtistInfoString(activity, artist));
|
||||
|
|
@ -130,14 +129,14 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
protected void loadArtistImage(Artist artist, final ViewHolder holder) {
|
||||
if (holder.image == null) return;
|
||||
Glide.with(activity)
|
||||
.load(new ArtistImage(artist.name, false))
|
||||
.load(new ArtistImage(artist.getName(), false))
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(activity), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.placeholder(R.drawable.default_artist_image)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.priority(Priority.LOW)
|
||||
.signature(ArtistSignatureUtil.getInstance(activity).getArtistSignature(artist.name))
|
||||
.signature(ArtistSignatureUtil.getInstance(activity).getArtistSignature(artist.getName()))
|
||||
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
|
||||
.into(new PhonographColoredTarget(holder.image) {
|
||||
@Override
|
||||
|
|
@ -168,7 +167,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
|
||||
@Override
|
||||
protected String getName(Artist artist) {
|
||||
return artist.name;
|
||||
return artist.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -180,7 +179,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
private ArrayList<Song> getSongList(@NonNull List<Artist> artists) {
|
||||
final ArrayList<Song> songs = new ArrayList<>();
|
||||
for (Artist artist : artists) {
|
||||
songs.addAll(ArtistSongLoader.getArtistSongList(activity, artist.id)); // maybe async in future?
|
||||
songs.addAll(artist.getSongs()); // maybe async in future?
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
|
@ -188,7 +187,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
@NonNull
|
||||
@Override
|
||||
public String getSectionName(int position) {
|
||||
return MusicUtil.getSectionName(dataSet.get(position).name);
|
||||
return MusicUtil.getSectionName(dataSet.get(position).getName());
|
||||
}
|
||||
|
||||
public class ViewHolder extends MediaEntryViewHolder {
|
||||
|
|
@ -210,7 +209,7 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
Pair.create(image,
|
||||
activity.getResources().getString(R.string.transition_artist_image)
|
||||
)};
|
||||
NavigationUtil.goToArtist(activity, dataSet.get(getAdapterPosition()).id, artistPairs);
|
||||
NavigationUtil.goToArtist(activity, dataSet.get(getAdapterPosition()).getId(), artistPairs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class ShuffleButtonSongAdapter extends SongAdapter {
|
|||
@Override
|
||||
protected Song getIdentifier(int position) {
|
||||
position--;
|
||||
if (position < 0) return new Song();
|
||||
if (position < 0) return Song.EMPTY_SONG;
|
||||
return super.getIdentifier(position);
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ public class ShuffleButtonSongAdapter extends SongAdapter {
|
|||
|
||||
@Override
|
||||
protected Song getSong() {
|
||||
if (getItemViewType() == SHUFFLE_BUTTON) return new Song();
|
||||
if (getItemViewType() == SHUFFLE_BUTTON) return Song.EMPTY_SONG;
|
||||
return dataSet.get(getAdapterPosition() - 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ public class MusicPlayerRemote {
|
|||
if (musicService != null) {
|
||||
return musicService.getCurrentSong();
|
||||
}
|
||||
return new Song();
|
||||
return Song.EMPTY_SONG;
|
||||
}
|
||||
|
||||
public static int getPosition() {
|
||||
|
|
|
|||
|
|
@ -144,16 +144,12 @@ public final class SortOrder {
|
|||
/* Artist album sort order Z-A */
|
||||
String ALBUM_Z_A = ALBUM_A_Z + " DESC";
|
||||
|
||||
/* Artist album sort order songs */
|
||||
String ALBUM_NUMBER_OF_SONGS = MediaStore.Audio.Artists.Albums.NUMBER_OF_SONGS
|
||||
/* Artist album sort order year */
|
||||
String ALBUM_YEAR = MediaStore.Audio.Media.YEAR
|
||||
+ " DESC";
|
||||
|
||||
/* Artist album sort order year */
|
||||
String ALBUM_YEAR = MediaStore.Audio.Artists.Albums.FIRST_YEAR
|
||||
+ " DESC";
|
||||
|
||||
/* Artist album sort order year */
|
||||
String ALBUM_YEAR_ASC = MediaStore.Audio.Artists.Albums.FIRST_YEAR
|
||||
String ALBUM_YEAR_ASC = MediaStore.Audio.Media.YEAR
|
||||
+ " ASC";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,23 +53,20 @@ public class AlbumLoader {
|
|||
ArrayList<Album> albums = new ArrayList<>();
|
||||
if (songs != null) {
|
||||
for (Song song : songs) {
|
||||
Album album = get(albums, song.albumId);
|
||||
if (album == null) {
|
||||
album = new Album();
|
||||
albums.add(album);
|
||||
}
|
||||
album.songs.add(song);
|
||||
getOrCreateAlbum(albums, song.albumId).songs.add(song);
|
||||
}
|
||||
}
|
||||
return albums;
|
||||
}
|
||||
|
||||
private static Album get(ArrayList<Album> albums, int albumId) {
|
||||
private static Album getOrCreateAlbum(ArrayList<Album> albums, int albumId) {
|
||||
for (Album album : albums) {
|
||||
if (!album.songs.isEmpty() && album.songs.get(0).albumId == albumId) {
|
||||
return album;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
Album album = new Album();
|
||||
albums.add(album);
|
||||
return album;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.helper.SortOrder;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistAlbumLoader extends AlbumLoader {
|
||||
|
||||
@NonNull
|
||||
public static ArrayList<Album> getAlbums(@NonNull final Context context, final int artistId) {
|
||||
ArrayList<Song> songs = SongLoader.getSongs(SongLoader.makeSongCursor(
|
||||
context,
|
||||
MediaStore.Audio.AudioColumns.ARTIST_ID + "=?",
|
||||
new String[]{String.valueOf(artistId)},
|
||||
SortOrder.SongSortOrder.SONG_YEAR + ", " + PreferenceUtil.getInstance(context).getAlbumSongSortOrder()
|
||||
));
|
||||
return splitIntoAlbums(songs);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.ArtistColumns;
|
||||
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.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -17,79 +16,62 @@ import java.util.ArrayList;
|
|||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ArtistLoader {
|
||||
|
||||
@NonNull
|
||||
public static ArrayList<Artist> getAllArtists(@NonNull Context context) {
|
||||
Cursor cursor = makeArtistCursor(context, null, null);
|
||||
return getArtists(cursor);
|
||||
public static String getSongLoaderSortOrder(Context context) {
|
||||
return PreferenceUtil.getInstance(context).getArtistSortOrder() + ", " + PreferenceUtil.getInstance(context).getArtistAlbumSortOrder() + ", " + PreferenceUtil.getInstance(context).getAlbumSongSortOrder();
|
||||
}
|
||||
|
||||
@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 ArrayList<Artist> getAllArtists(@NonNull final Context context) {
|
||||
ArrayList<Song> songs = SongLoader.getSongs(SongLoader.makeSongCursor(
|
||||
context,
|
||||
null,
|
||||
null,
|
||||
getSongLoaderSortOrder(context))
|
||||
);
|
||||
return splitIntoArtists(AlbumLoader.splitIntoAlbums(songs));
|
||||
}
|
||||
|
||||
@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(@NonNull final Context context, String query) {
|
||||
ArrayList<Song> songs = SongLoader.getSongs(SongLoader.makeSongCursor(
|
||||
context,
|
||||
AudioColumns.ARTIST + " LIKE ?",
|
||||
new String[]{"%" + query + "%"},
|
||||
getSongLoaderSortOrder(context))
|
||||
);
|
||||
return splitIntoArtists(AlbumLoader.splitIntoAlbums(songs));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ArrayList<Artist> getArtists(@Nullable Cursor cursor) {
|
||||
public static Artist getArtist(@NonNull final Context context, int artistId) {
|
||||
ArrayList<Song> songs = SongLoader.getSongs(SongLoader.makeSongCursor(
|
||||
context,
|
||||
AudioColumns.ARTIST_ID + "=?",
|
||||
new String[]{String.valueOf(artistId)},
|
||||
getSongLoaderSortOrder(context))
|
||||
);
|
||||
return new Artist(AlbumLoader.splitIntoAlbums(songs));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ArrayList<Artist> splitIntoArtists(@Nullable final ArrayList<Album> albums) {
|
||||
ArrayList<Artist> artists = new ArrayList<>();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
artists.add(getArtistFromCursorImpl(cursor));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
if (albums != null) {
|
||||
for (Album album : albums) {
|
||||
getOrCreateArtist(artists, album.getArtistId()).albums.add(album);
|
||||
}
|
||||
}
|
||||
return artists;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Artist getArtist(@Nullable Cursor cursor) {
|
||||
Artist artist = new Artist();
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
artist = getArtistFromCursorImpl(cursor);
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return artist;
|
||||
}
|
||||
|
||||
@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);
|
||||
final int songCount = cursor.getInt(3);
|
||||
|
||||
return new Artist(id, artistName, albumCount, songCount);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Cursor makeArtistCursor(@NonNull final Context context, final String selection, final String[] values) {
|
||||
try {
|
||||
return context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
|
||||
new String[]{
|
||||
/* 0 */
|
||||
BaseColumns._ID,
|
||||
/* 1 */
|
||||
ArtistColumns.ARTIST,
|
||||
/* 2 */
|
||||
ArtistColumns.NUMBER_OF_ALBUMS,
|
||||
/* 3 */
|
||||
ArtistColumns.NUMBER_OF_TRACKS
|
||||
}, selection, values, PreferenceUtil.getInstance(context).getArtistSortOrder());
|
||||
} catch (SecurityException e) {
|
||||
return null;
|
||||
private static Artist getOrCreateArtist(ArrayList<Artist> artists, int artistId) {
|
||||
for (Artist artist : artists) {
|
||||
if (!artist.albums.isEmpty() && !artist.albums.get(0).songs.isEmpty() && artist.albums.get(0).songs.get(0).artistId == artistId) {
|
||||
return artist;
|
||||
}
|
||||
}
|
||||
Artist album = new Artist();
|
||||
artists.add(album);
|
||||
return album;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class SongLoader {
|
|||
if (cursor != null && cursor.moveToFirst()) {
|
||||
song = getSongFromCursorImpl(cursor);
|
||||
} else {
|
||||
song = new Song();
|
||||
song = Song.EMPTY_SONG;
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
|
|
|
|||
|
|
@ -44,9 +44,13 @@ public class Album implements Parcelable {
|
|||
return safeGetFirstSong().dateModified;
|
||||
}
|
||||
|
||||
public int getSongCount() {
|
||||
return songs.size();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Song safeGetFirstSong() {
|
||||
return songs.isEmpty() ? new Song() : songs.get(0);
|
||||
return songs.isEmpty() ? Song.EMPTY_SONG : songs.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,28 +2,55 @@ package com.kabouzeid.gramophone.model;
|
|||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class Artist implements Parcelable {
|
||||
public final int id;
|
||||
public final String name;
|
||||
public final int albumCount;
|
||||
public final int songCount;
|
||||
public final ArrayList<Album> albums;
|
||||
|
||||
public Artist(final int id, final String name, final int albumCount, final int songCount) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.songCount = songCount;
|
||||
this.albumCount = albumCount;
|
||||
public Artist(ArrayList<Album> albums) {
|
||||
this.albums = albums;
|
||||
}
|
||||
|
||||
public Artist() {
|
||||
id = -1;
|
||||
name = "";
|
||||
songCount = -1;
|
||||
albumCount = -1;
|
||||
this.albums = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return safeGetFirstAlbum().getArtistId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return safeGetFirstAlbum().getArtistName();
|
||||
}
|
||||
|
||||
public int getSongCount() {
|
||||
int songCount = 0;
|
||||
for (Album album : albums) {
|
||||
songCount += album.getSongCount();
|
||||
}
|
||||
return songCount;
|
||||
}
|
||||
|
||||
public int getAlbumCount() {
|
||||
return albums.size();
|
||||
}
|
||||
|
||||
public ArrayList<Song> getSongs() {
|
||||
ArrayList<Song> songs = new ArrayList<>();
|
||||
for (Album album : albums) {
|
||||
songs.addAll(album.songs);
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Album safeGetFirstAlbum() {
|
||||
return albums.isEmpty() ? new Album() : albums.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -33,29 +60,19 @@ public class Artist implements Parcelable {
|
|||
|
||||
Artist artist = (Artist) o;
|
||||
|
||||
if (id != artist.id) return false;
|
||||
if (albumCount != artist.albumCount) return false;
|
||||
if (songCount != artist.songCount) return false;
|
||||
return name != null ? name.equals(artist.name) : artist.name == null;
|
||||
return albums != null ? albums.equals(artist.albums) : artist.albums == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id;
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + albumCount;
|
||||
result = 31 * result + songCount;
|
||||
return result;
|
||||
return albums != null ? albums.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Artist{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", albumCount=" + albumCount +
|
||||
", songCount=" + songCount +
|
||||
"albums=" + albums +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
|
@ -67,24 +84,20 @@ public class Artist implements Parcelable {
|
|||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(this.id);
|
||||
dest.writeString(this.name);
|
||||
dest.writeInt(this.albumCount);
|
||||
dest.writeInt(this.songCount);
|
||||
dest.writeTypedList(this.albums);
|
||||
}
|
||||
|
||||
protected Artist(Parcel in) {
|
||||
this.id = in.readInt();
|
||||
this.name = in.readString();
|
||||
this.albumCount = in.readInt();
|
||||
this.songCount = in.readInt();
|
||||
this.albums = in.createTypedArrayList(Album.CREATOR);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Artist> CREATOR = new Parcelable.Creator<Artist>() {
|
||||
@Override
|
||||
public Artist createFromParcel(Parcel source) {
|
||||
return new Artist(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Artist[] newArray(int size) {
|
||||
return new Artist[size];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.model;
|
|||
import android.os.Parcel;
|
||||
|
||||
public class PlaylistSong extends Song {
|
||||
public static final PlaylistSong EMPTY_PLAYLIST_SONG = new PlaylistSong(-1, "", -1, -1, -1, "", -1, -1, "", -1, "", -1, -1);
|
||||
|
||||
public final int playlistId;
|
||||
public final int idInPlayList;
|
||||
|
|
@ -13,12 +14,6 @@ public class PlaylistSong extends Song {
|
|||
this.idInPlayList = idInPlayList;
|
||||
}
|
||||
|
||||
public PlaylistSong() {
|
||||
super();
|
||||
playlistId = -1;
|
||||
idInPlayList = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import android.os.Parcelable;
|
|||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class Song implements Parcelable {
|
||||
public static final Song EMPTY_SONG = new Song(-1, "", -1, -1, -1, "", -1, -1, "", -1, "");
|
||||
|
||||
public final int id;
|
||||
public final String title;
|
||||
public final int trackNumber;
|
||||
|
|
@ -33,20 +35,6 @@ public class Song implements Parcelable {
|
|||
this.artistName = artistName;
|
||||
}
|
||||
|
||||
public Song() {
|
||||
this.id = -1;
|
||||
this.title = "";
|
||||
this.trackNumber = -1;
|
||||
this.year = -1;
|
||||
this.duration = -1;
|
||||
this.data = "";
|
||||
this.dateModified = -1;
|
||||
this.albumId = -1;
|
||||
this.albumName = "";
|
||||
this.artistId = -1;
|
||||
this.artistName = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
|||
|
|
@ -574,7 +574,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
if (position >= 0 && position < getPlayingQueue().size()) {
|
||||
return getPlayingQueue().get(position);
|
||||
} else {
|
||||
return new Song();
|
||||
return Song.EMPTY_SONG;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1233,7 +1233,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
public static final String TAG = SongPlayCountHelper.class.getSimpleName();
|
||||
|
||||
private StopWatch stopWatch = new StopWatch();
|
||||
private Song song = new Song();
|
||||
private Song song = Song.EMPTY_SONG;
|
||||
|
||||
public Song getSong() {
|
||||
return song;
|
||||
|
|
|
|||
|
|
@ -41,26 +41,20 @@ import com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder;
|
|||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.LoaderIds;
|
||||
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
||||
import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient;
|
||||
import com.kabouzeid.gramophone.lastfm.rest.model.LastFmArtist;
|
||||
import com.kabouzeid.gramophone.loader.ArtistAlbumLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistLoader;
|
||||
import com.kabouzeid.gramophone.loader.ArtistSongLoader;
|
||||
import com.kabouzeid.gramophone.interfaces.LoaderIds;
|
||||
import com.kabouzeid.gramophone.misc.SimpleObservableScrollViewCallbacks;
|
||||
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity;
|
||||
import com.kabouzeid.gramophone.util.ArtistSignatureUtil;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
||||
import com.kabouzeid.gramophone.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import retrofit2.Call;
|
||||
|
|
@ -70,7 +64,7 @@ import retrofit2.Response;
|
|||
/**
|
||||
* Be careful when changing things in this Activity!
|
||||
*/
|
||||
public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implements PaletteColorHolder, CabHolder, LoaderManager.LoaderCallbacks<ArtistDetailActivity.ArtistData> {
|
||||
public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implements PaletteColorHolder, CabHolder, LoaderManager.LoaderCallbacks<Artist> {
|
||||
|
||||
public static final String TAG = ArtistDetailActivity.class.getSimpleName();
|
||||
private static final int LOADER_ID = LoaderIds.ARTIST_DETAIL_ACTIVITY;
|
||||
|
|
@ -98,7 +92,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
private int toolbarColor;
|
||||
private float toolbarAlpha;
|
||||
|
||||
private ArtistData artistData;
|
||||
private Artist artist;
|
||||
@Nullable
|
||||
private Spanned biography;
|
||||
private HorizontalAlbumAdapter albumAdapter;
|
||||
|
|
@ -181,7 +175,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
songListView.setScrollViewCallbacks(observableScrollViewCallbacks);
|
||||
songListView.addHeaderView(songListHeader);
|
||||
|
||||
songAdapter = new ArtistSongAdapter(this, getArtistData().songs, this);
|
||||
songAdapter = new ArtistSongAdapter(this, getArtist().getSongs(), this);
|
||||
songListView.setAdapter(songAdapter);
|
||||
|
||||
final View contentView = getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
|
|
@ -200,7 +194,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
|
||||
private void setUpAlbumRecyclerView() {
|
||||
albumRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
|
||||
albumAdapter = new HorizontalAlbumAdapter(this, getArtistData().albums, this);
|
||||
albumAdapter = new HorizontalAlbumAdapter(this, getArtist().albums, this);
|
||||
albumRecyclerView.setAdapter(albumAdapter);
|
||||
albumAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
|
||||
@Override
|
||||
|
|
@ -216,7 +210,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
}
|
||||
|
||||
private void loadBiography() {
|
||||
lastFMRestClient.getApiService().getArtistInfo(getArtistData().artist.name, null).enqueue(new Callback<LastFmArtist>() {
|
||||
lastFMRestClient.getApiService().getArtistInfo(getArtist().getName(), null).enqueue(new Callback<LastFmArtist>() {
|
||||
@Override
|
||||
public void onResponse(Call<LastFmArtist> call, Response<LastFmArtist> response) {
|
||||
LastFmArtist lastFmArtist = response.body();
|
||||
|
|
@ -240,7 +234,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
|
||||
private MaterialDialog getBiographyDialog() {
|
||||
return new MaterialDialog.Builder(ArtistDetailActivity.this)
|
||||
.title(getArtistData().artist.name)
|
||||
.title(getArtist().getName())
|
||||
.content(biography != null ? biography : "")
|
||||
.positiveText(android.R.string.ok)
|
||||
.build();
|
||||
|
|
@ -248,15 +242,15 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
|
||||
private void loadArtistImage(final boolean forceDownload) {
|
||||
if (forceDownload) {
|
||||
ArtistSignatureUtil.getInstance(this).updateArtistSignature(getArtistData().artist.name);
|
||||
ArtistSignatureUtil.getInstance(this).updateArtistSignature(getArtist().getName());
|
||||
}
|
||||
Glide.with(this)
|
||||
.load(new ArtistImage(getArtistData().artist.name, forceDownload))
|
||||
.load(new ArtistImage(getArtist().getName(), forceDownload))
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(this), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.placeholder(R.drawable.default_artist_image)
|
||||
.signature(ArtistSignatureUtil.getInstance(this).getArtistSignature(getArtistData().artist.name))
|
||||
.signature(ArtistSignatureUtil.getInstance(this).getArtistSignature(getArtist().getName()))
|
||||
.dontAnimate()
|
||||
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
|
||||
.listener(new RequestListener<ArtistImage, BitmapPaletteWrapper>() {
|
||||
|
|
@ -399,39 +393,39 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
setLightStatusbar(false);
|
||||
}
|
||||
|
||||
private void setArtistData(ArtistData artistData) {
|
||||
this.artistData = artistData;
|
||||
private void setArtist(Artist artist) {
|
||||
this.artist = artist;
|
||||
loadArtistImage(false);
|
||||
loadBiography();
|
||||
artistName.setText(artistData.artist.name);
|
||||
songAdapter.swapDataSet(artistData.songs);
|
||||
albumAdapter.swapDataSet(artistData.albums);
|
||||
artistName.setText(artist.getName());
|
||||
songAdapter.swapDataSet(artist.getSongs());
|
||||
albumAdapter.swapDataSet(artist.albums);
|
||||
}
|
||||
|
||||
private ArtistData getArtistData() {
|
||||
if (artistData == null) artistData = new ArtistData();
|
||||
return artistData;
|
||||
private Artist getArtist() {
|
||||
if (artist == null) artist = new Artist();
|
||||
return artist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<ArtistData> onCreateLoader(int id, Bundle args) {
|
||||
public Loader<Artist> onCreateLoader(int id, Bundle args) {
|
||||
return new AsyncArtistDataLoader(this, args.getInt(EXTRA_ARTIST_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<ArtistData> loader, ArtistData data) {
|
||||
public void onLoadFinished(Loader<Artist> loader, Artist data) {
|
||||
supportStartPostponedEnterTransition();
|
||||
setArtistData(data);
|
||||
setArtist(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<ArtistData> loader) {
|
||||
this.artistData = new ArtistData();
|
||||
songAdapter.swapDataSet(artistData.songs);
|
||||
albumAdapter.swapDataSet(artistData.albums);
|
||||
public void onLoaderReset(Loader<Artist> loader) {
|
||||
this.artist = new Artist();
|
||||
songAdapter.swapDataSet(artist.getSongs());
|
||||
albumAdapter.swapDataSet(artist.albums);
|
||||
}
|
||||
|
||||
private static class AsyncArtistDataLoader extends WrappedAsyncTaskLoader<ArtistData> {
|
||||
private static class AsyncArtistDataLoader extends WrappedAsyncTaskLoader<Artist> {
|
||||
private final int artistId;
|
||||
|
||||
public AsyncArtistDataLoader(Context context, int artistId) {
|
||||
|
|
@ -440,29 +434,8 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public ArtistData loadInBackground() {
|
||||
Artist artist = ArtistLoader.getArtist(getContext(), artistId);
|
||||
ArrayList<Song> songs = ArtistSongLoader.getArtistSongList(getContext(), artist.id);
|
||||
ArrayList<Album> albums = ArtistAlbumLoader.getAlbums(getContext(), artist.id);
|
||||
return new ArtistData(artist, songs, albums);
|
||||
}
|
||||
}
|
||||
|
||||
static class ArtistData {
|
||||
public final Artist artist;
|
||||
public final ArrayList<Song> songs;
|
||||
public final ArrayList<Album> albums;
|
||||
|
||||
private ArtistData() {
|
||||
artist = new Artist();
|
||||
songs = new ArrayList<>();
|
||||
albums = new ArrayList<>();
|
||||
}
|
||||
|
||||
private ArtistData(Artist artist, ArrayList<Song> songs, ArrayList<Album> albums) {
|
||||
this.artist = artist;
|
||||
this.songs = songs;
|
||||
this.albums = albums;
|
||||
public Artist loadInBackground() {
|
||||
return ArtistLoader.getArtist(getContext(), artistId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -492,7 +492,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
@SuppressWarnings("ConstantConditions")
|
||||
private static class PortraitImpl extends BaseImpl {
|
||||
MediaEntryViewHolder currentSongViewHolder;
|
||||
Song currentSong = new Song();
|
||||
Song currentSong = Song.EMPTY_SONG;
|
||||
|
||||
public PortraitImpl(CardPlayerFragment fragment) {
|
||||
super(fragment);
|
||||
|
|
|
|||
|
|
@ -472,7 +472,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
@SuppressWarnings("ConstantConditions")
|
||||
private static class PortraitImpl extends BaseImpl {
|
||||
MediaEntryViewHolder currentSongViewHolder;
|
||||
Song currentSong = new Song();
|
||||
Song currentSong = Song.EMPTY_SONG;
|
||||
|
||||
public PortraitImpl(FlatPlayerFragment fragment) {
|
||||
super(fragment);
|
||||
|
|
|
|||
|
|
@ -90,9 +90,11 @@ public class MusicUtil {
|
|||
|
||||
@NonNull
|
||||
public static String getArtistInfoString(@NonNull final Context context, @NonNull final Artist artist) {
|
||||
String albumString = artist.albumCount == 1 ? context.getResources().getString(R.string.album) : context.getResources().getString(R.string.albums);
|
||||
String songString = artist.songCount == 1 ? context.getResources().getString(R.string.song) : context.getResources().getString(R.string.songs);
|
||||
return artist.albumCount + " " + albumString + " • " + artist.songCount + " " + songString;
|
||||
int albumCount = artist.getAlbumCount();
|
||||
int songCount = artist.getSongCount();
|
||||
String albumString = albumCount == 1 ? context.getResources().getString(R.string.album) : context.getResources().getString(R.string.albums);
|
||||
String songString = songCount == 1 ? context.getResources().getString(R.string.song) : context.getResources().getString(R.string.songs);
|
||||
return albumCount + " " + albumString + " • " + songCount + " " + songString;
|
||||
}
|
||||
|
||||
public static String getReadableDurationString(long songDurationMillis) {
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public final class PreferenceUtil {
|
|||
|
||||
public final String getArtistAlbumSortOrder() {
|
||||
return mPreferences.getString(ARTIST_ALBUM_SORT_ORDER,
|
||||
SortOrder.ArtistAlbumSortOrder.ALBUM_YEAR_ASC);
|
||||
SortOrder.ArtistAlbumSortOrder.ALBUM_YEAR);
|
||||
}
|
||||
|
||||
public final String getAlbumSortOrder() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue