From 7c87ec2cbe54b562d5e38bd0679dc7d487ecece4 Mon Sep 17 00:00:00 2001 From: Albert Canales Ros Date: Sat, 8 Jun 2024 23:02:59 +0200 Subject: [PATCH] feat: clicking the song's title opens the album on player --- .../fragment/PlayerBottomSheetFragment.java | 1 + .../ui/fragment/PlayerControllerFragment.java | 14 ++++++++++++ .../viewmodel/PlayerBottomSheetViewModel.java | 22 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerBottomSheetFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerBottomSheetFragment.java index 8e40b3e8..dafd1507 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerBottomSheetFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerBottomSheetFragment.java @@ -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)); diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerControllerFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerControllerFragment.java index a3260917..1d474db9 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerControllerFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/PlayerControllerFragment.java @@ -76,6 +76,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, initQuickActionView(); initCoverLyricsSlideView(); initMediaListenable(); + initMediaLabelButton(); initArtistLabelButton(); return view; @@ -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) { diff --git a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/PlayerBottomSheetViewModel.java b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/PlayerBottomSheetViewModel.java index d1efd694..3e712479 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/viewmodel/PlayerBottomSheetViewModel.java +++ b/app/src/main/java/com/cappielloantonio/tempo/viewmodel/PlayerBottomSheetViewModel.java @@ -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; @@ -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; @@ -48,6 +51,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel { private final MutableLiveData lyricsListLiveData = new MutableLiveData<>(null); private final MutableLiveData descriptionLiveData = new MutableLiveData<>(null); private final MutableLiveData liveMedia = new MutableLiveData<>(null); + private final MutableLiveData liveAlbum = new MutableLiveData<>(null); private final MutableLiveData liveArtist = new MutableLiveData<>(null); private final MutableLiveData> instantMix = new MutableLiveData<>(null); private boolean lyricsSyncState = true; @@ -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(); @@ -162,6 +167,23 @@ public void setLiveMedia(LifecycleOwner owner, String mediaType, String mediaId) } } + public LiveData 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 getLiveArtist() { return liveArtist; }