diff --git a/project/app/src/main/java/com/iven/musicplayergo/MainActivity.java b/project/app/src/main/java/com/iven/musicplayergo/MainActivity.java index b9cf76ce1..ed0736faf 100644 --- a/project/app/src/main/java/com/iven/musicplayergo/MainActivity.java +++ b/project/app/src/main/java/com/iven/musicplayergo/MainActivity.java @@ -311,7 +311,7 @@ private void initializeSettings() { public void shuffleSongs(@NonNull final View v) { final List songs = sArtistDiscographyExpanded ? mSelectedArtistSongs : SongProvider.getAllDeviceSongs(); Collections.shuffle(songs); - onSongSelected(songs.get(0), songs); + onSongSelected(songs.get(0), songs, true); } private void setArtistsRecyclerView(@NonNull final List data) { @@ -439,7 +439,6 @@ private boolean checkIsPlayer() { } private void initializeColorsSettings() { - final RecyclerView colorsRecyclerView = mSettingsView.findViewById(R.id.colors_rv); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); colorsRecyclerView.setLayoutManager(linearLayoutManager); @@ -596,7 +595,7 @@ protected void onDestroy() { } @Override - public void onSongSelected(@NonNull final Song playedSong, @NonNull final List songsForPlayedArtist) { + public void onSongSelected(@NonNull final Song playedSong, @NonNull final List songsForPlayedArtist, final boolean shuffleMode) { if (!mSeekBarAudio.isEnabled()) { mSeekBarAudio.setEnabled(true); } @@ -634,7 +633,7 @@ public void onAlbumSelected(@NonNull final Album album) { } else { mSongsLayoutManager = new LinearLayoutManager(this); mSongsRecyclerView.setLayoutManager(mSongsLayoutManager); - mSongsAdapter = new SongsAdapter(this, mPlayerAdapter, album); + mSongsAdapter = new SongsAdapter(this, album); mSongsRecyclerView.setAdapter(mSongsAdapter); } } @@ -650,19 +649,20 @@ private Pair> scrollToPlayedAlbumPosition(final boolean setAr } private Pair playedAlbumPosition(@NonNull final List playedArtistAlbums) { - Album playedAlbum = mPlayerAdapter.getPlayedAlbum(); + Album playedAlbum = mPlayerAdapter.getCurrentSong().getSongAlbum(); return new Pair<>(playedAlbum, playedArtistAlbums.indexOf(playedAlbum)); } public void expandArtistDetails(@NonNull final View v) { + if (mPlayerAdapter.getCurrentSong() != null && !mPlayerAdapter.getCurrentSong().artistName.equals(mNavigationArtist)) { // if we come from different artist show the played artist page onArtistSelected(mPlayerAdapter.getCurrentSong().artistName, true); - if (mPlayerAdapter.getPlayedAlbum() != null) { + if (mPlayerAdapter.getCurrentSong() != null) { scrollToPlayedAlbumPosition(false); } } else if (sArtistDiscographyExpanded) { - if (mPlayerAdapter.getCurrentSong() != null && mPlayerAdapter.getCurrentSong().artistName.equals(mNavigationArtist) && !mPlayerAdapter.getNavigationAlbum().equals(mPlayerAdapter.getPlayedAlbum())) { + if (mPlayerAdapter.getCurrentSong() != null && mPlayerAdapter.getCurrentSong().artistName.equals(mNavigationArtist) && !mPlayerAdapter.getNavigationAlbum().equals(mPlayerAdapter.getCurrentSong().getSongAlbum())) { // if the played artist details are already expanded (but not on played album) // and we are playing one of his albums, the show the played album mPlayerAdapter.setNavigationAlbum(scrollToPlayedAlbumPosition(true).first); diff --git a/project/app/src/main/java/com/iven/musicplayergo/adapters/AlbumsAdapter.java b/project/app/src/main/java/com/iven/musicplayergo/adapters/AlbumsAdapter.java index 83be661f0..107563402 100644 --- a/project/app/src/main/java/com/iven/musicplayergo/adapters/AlbumsAdapter.java +++ b/project/app/src/main/java/com/iven/musicplayergo/adapters/AlbumsAdapter.java @@ -30,7 +30,7 @@ public AlbumsAdapter(@NonNull final Activity activity, @NonNull final PlayerAdap mPlayerAdapter = playerAdapter; mAlbums = albums; mAlbumSelectedListener = (AlbumSelectedListener) mActivity; - mSelectedAlbum = showPlayedArtist ? mPlayerAdapter.getPlayedAlbum() : mPlayerAdapter.getNavigationAlbum() != null ? mPlayerAdapter.getNavigationAlbum() : mAlbums.get(0); + mSelectedAlbum = showPlayedArtist ? mPlayerAdapter.getCurrentSong().getSongAlbum() : mPlayerAdapter.getNavigationAlbum() != null ? mPlayerAdapter.getNavigationAlbum() : mAlbums.get(0); mAlbumSelectedListener.onAlbumSelected(mSelectedAlbum); } diff --git a/project/app/src/main/java/com/iven/musicplayergo/adapters/SongsAdapter.java b/project/app/src/main/java/com/iven/musicplayergo/adapters/SongsAdapter.java index e3ecac696..ad30986c7 100644 --- a/project/app/src/main/java/com/iven/musicplayergo/adapters/SongsAdapter.java +++ b/project/app/src/main/java/com/iven/musicplayergo/adapters/SongsAdapter.java @@ -14,7 +14,6 @@ import com.iven.musicplayergo.R; import com.iven.musicplayergo.models.Album; import com.iven.musicplayergo.models.Song; -import com.iven.musicplayergo.playback.PlayerAdapter; import java.util.List; @@ -22,13 +21,11 @@ public class SongsAdapter extends RecyclerView.Adapter mSongs; private Album mAlbum; - public SongsAdapter(@NonNull final Activity activity, @NonNull final PlayerAdapter playerAdapter, @NonNull final Album album) { + public SongsAdapter(@NonNull final Activity activity, @NonNull final Album album) { mActivity = activity; - mPlayerAdapter = playerAdapter; mAlbum = album; mSongs = mAlbum.songs; mSongSelectedListener = (SongSelectedListener) activity; @@ -72,7 +69,7 @@ public int getItemCount() { } public interface SongSelectedListener { - void onSongSelected(@NonNull final Song song, @NonNull final List songs); + void onSongSelected(@NonNull final Song song, @NonNull final List songs, final boolean shuffleMode); } class SimpleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { @@ -94,8 +91,7 @@ class SimpleViewHolder extends RecyclerView.ViewHolder implements View.OnClickLi @Override public void onClick(@NonNull final View v) { final Song song = mSongs.get(getAdapterPosition()); - mPlayerAdapter.setPlayedAlbum(mAlbum); - mSongSelectedListener.onSongSelected(song, mAlbum.songs); + mSongSelectedListener.onSongSelected(song, mAlbum.songs, false); } } } \ No newline at end of file diff --git a/project/app/src/main/java/com/iven/musicplayergo/loaders/AlbumProvider.java b/project/app/src/main/java/com/iven/musicplayergo/loaders/AlbumProvider.java index e50638cb1..c075f8345 100644 --- a/project/app/src/main/java/com/iven/musicplayergo/loaders/AlbumProvider.java +++ b/project/app/src/main/java/com/iven/musicplayergo/loaders/AlbumProvider.java @@ -17,7 +17,9 @@ static List retrieveAlbums(@Nullable final List songs) { final List albums = new ArrayList<>(); if (songs != null) { for (Song song : songs) { - getAlbum(albums, song.albumName).songs.add(song); + Album album = getAlbum(albums, song.albumName); + album.songs.add(song); + song.setSongAlbum(album); } } if (albums.size() > 1) { diff --git a/project/app/src/main/java/com/iven/musicplayergo/models/Song.java b/project/app/src/main/java/com/iven/musicplayergo/models/Song.java index a9a659301..142e53c98 100644 --- a/project/app/src/main/java/com/iven/musicplayergo/models/Song.java +++ b/project/app/src/main/java/com/iven/musicplayergo/models/Song.java @@ -17,6 +17,7 @@ public class Song { public final int artistId; public final String artistName; final int year; + private Album mSongAlbum; public Song(@NonNull final String title, final int trackNumber, final int year, final int duration, final String path, final String albumName, final int artistId, final String artistName) { this.title = title; @@ -43,4 +44,12 @@ public static int formatTrack(final int trackNumber) { } return formatted; } + + public Album getSongAlbum() { + return mSongAlbum; + } + + public void setSongAlbum(@NonNull final Album album) { + mSongAlbum = album; + } } diff --git a/project/app/src/main/java/com/iven/musicplayergo/playback/MediaPlayerHolder.java b/project/app/src/main/java/com/iven/musicplayergo/playback/MediaPlayerHolder.java index 04f9a1496..46614547b 100644 --- a/project/app/src/main/java/com/iven/musicplayergo/playback/MediaPlayerHolder.java +++ b/project/app/src/main/java/com/iven/musicplayergo/playback/MediaPlayerHolder.java @@ -45,7 +45,7 @@ public final class MediaPlayerHolder implements PlayerAdapter, MediaPlayer.OnCom private final MusicService mMusicService; private final AudioManager mAudioManager; private String mNavigationArtist; - private Album mPlayedAlbum, mNavigationAlbum; + private Album mNavigationAlbum; private MediaPlayer mMediaPlayer; private PlaybackInfoListener mPlaybackInfoListener; private ScheduledExecutorService mExecutor; @@ -124,31 +124,23 @@ private void unregisterActionsReceiver() { } } - @Override - public final Album getPlayedAlbum() { - return mPlayedAlbum; - } - - @Override - public final void setPlayedAlbum(@NonNull final Album album) { - mPlayedAlbum = album; - } - @Override public final String getNavigationArtist() { return mNavigationArtist; } @Override - public final void setNavigationArtist(@NonNull final String navigationArtist) { + public void setNavigationArtist(@NonNull final String navigationArtist) { mNavigationArtist = navigationArtist; } + @Override public final Album getNavigationAlbum() { return mNavigationAlbum; } - public final void setNavigationAlbum(@Nullable final Album navigationAlbum) { + @Override + public void setNavigationAlbum(@Nullable final Album navigationAlbum) { mNavigationAlbum = navigationAlbum; } diff --git a/project/app/src/main/java/com/iven/musicplayergo/playback/PlayerAdapter.java b/project/app/src/main/java/com/iven/musicplayergo/playback/PlayerAdapter.java index 97ec41ded..8203de0bc 100644 --- a/project/app/src/main/java/com/iven/musicplayergo/playback/PlayerAdapter.java +++ b/project/app/src/main/java/com/iven/musicplayergo/playback/PlayerAdapter.java @@ -50,10 +50,6 @@ public interface PlayerAdapter { Song getCurrentSong(); - Album getPlayedAlbum(); - - void setPlayedAlbum(@NonNull final Album album); - String getNavigationArtist(); void setNavigationArtist(@NonNull final String navigationArtist);