Skip to content

Commit

Permalink
Merge pull request #251 from albertcanales/main
Browse files Browse the repository at this point in the history
feat: open album when clicking the song's title on player
  • Loading branch information
CappielloAntonio authored Aug 30, 2024
2 parents f967df8 + 7c87ec2 commit 6c6d56f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void onEvents(Player player, Player.Events events) {
private void setMetadata(MediaMetadata mediaMetadata) {
if (mediaMetadata.extras != null) {
playerBottomSheetViewModel.setLiveMedia(getViewLifecycleOwner(), mediaMetadata.extras.getString("type"), mediaMetadata.extras.getString("id"));
playerBottomSheetViewModel.setLiveAlbum(getViewLifecycleOwner(), mediaMetadata.extras.getString("type"), mediaMetadata.extras.getString("albumId"));
playerBottomSheetViewModel.setLiveArtist(getViewLifecycleOwner(), mediaMetadata.extras.getString("type"), mediaMetadata.extras.getString("artistId"));
playerBottomSheetViewModel.setLiveDescription(mediaMetadata.extras.getString("description", null));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
initQuickActionView();
initCoverLyricsSlideView();
initMediaListenable();
initMediaLabelButton();
initArtistLabelButton();

return view;
Expand Down Expand Up @@ -299,6 +300,19 @@ private void initMediaListenable() {
});
}

private void initMediaLabelButton() {
playerBottomSheetViewModel.getLiveAlbum().observe(getViewLifecycleOwner(), album -> {
if (album != null) {
playerMediaTitleLabel.setOnClickListener(view -> {
Bundle bundle = new Bundle();
bundle.putParcelable(Constants.ALBUM_OBJECT, album);
NavHostFragment.findNavController(this).navigate(R.id.albumPageFragment, bundle);
activity.collapseBottomSheetDelayed();
});
}
});
}

private void initArtistLabelButton() {
playerBottomSheetViewModel.getLiveArtist().observe(getViewLifecycleOwner(), artist -> {
if (artist != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import com.cappielloantonio.tempo.interfaces.StarCallback;
import com.cappielloantonio.tempo.model.Download;
import com.cappielloantonio.tempo.model.Queue;
import com.cappielloantonio.tempo.repository.AlbumRepository;
import com.cappielloantonio.tempo.repository.ArtistRepository;
import com.cappielloantonio.tempo.repository.FavoriteRepository;
import com.cappielloantonio.tempo.repository.OpenRepository;
import com.cappielloantonio.tempo.repository.QueueRepository;
import com.cappielloantonio.tempo.repository.SongRepository;
import com.cappielloantonio.tempo.subsonic.models.AlbumID3;
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
import com.cappielloantonio.tempo.subsonic.models.Child;
import com.cappielloantonio.tempo.subsonic.models.LyricsList;
Expand All @@ -40,6 +42,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
private static final String TAG = "PlayerBottomSheetViewModel";

private final SongRepository songRepository;
private final AlbumRepository albumRepository;
private final ArtistRepository artistRepository;
private final QueueRepository queueRepository;
private final FavoriteRepository favoriteRepository;
Expand All @@ -48,6 +51,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
private final MutableLiveData<LyricsList> lyricsListLiveData = new MutableLiveData<>(null);
private final MutableLiveData<String> descriptionLiveData = new MutableLiveData<>(null);
private final MutableLiveData<Child> liveMedia = new MutableLiveData<>(null);
private final MutableLiveData<AlbumID3> liveAlbum = new MutableLiveData<>(null);
private final MutableLiveData<ArtistID3> liveArtist = new MutableLiveData<>(null);
private final MutableLiveData<List<Child>> instantMix = new MutableLiveData<>(null);
private boolean lyricsSyncState = true;
Expand All @@ -57,6 +61,7 @@ public PlayerBottomSheetViewModel(@NonNull Application application) {
super(application);

songRepository = new SongRepository();
albumRepository = new AlbumRepository();
artistRepository = new ArtistRepository();
queueRepository = new QueueRepository();
favoriteRepository = new FavoriteRepository();
Expand Down Expand Up @@ -162,6 +167,23 @@ public void setLiveMedia(LifecycleOwner owner, String mediaType, String mediaId)
}
}

public LiveData<AlbumID3> getLiveAlbum() {
return liveAlbum;
}

public void setLiveAlbum(LifecycleOwner owner, String mediaType, String AlbumId) {
if (mediaType != null) {
switch (mediaType) {
case Constants.MEDIA_TYPE_MUSIC:
albumRepository.getAlbum(AlbumId).observe(owner, liveAlbum::postValue);
break;
case Constants.MEDIA_TYPE_PODCAST:
liveAlbum.postValue(null);
break;
}
}
}

public LiveData<ArtistID3> getLiveArtist() {
return liveArtist;
}
Expand Down

0 comments on commit 6c6d56f

Please sign in to comment.