diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/PodcastEpisodeAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/PodcastEpisodeAdapter.java index fd0fb953..e870a2f7 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/PodcastEpisodeAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/PodcastEpisodeAdapter.java @@ -15,7 +15,8 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.cappielloantonio.play.R; import com.cappielloantonio.play.glide.CustomGlideRequest; -import com.cappielloantonio.play.model.PodcastEpisode; +import com.cappielloantonio.play.model.Media; +import com.cappielloantonio.play.service.MediaManager; import com.cappielloantonio.play.ui.activity.MainActivity; import com.cappielloantonio.play.util.MusicUtil; import com.google.common.util.concurrent.ListenableFuture; @@ -32,7 +33,7 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter mediaBrowserListenableFuture; - private List podcastEpisodes; + private List podcastEpisodes; public PodcastEpisodeAdapter(MainActivity activity, Context context) { this.activity = activity; @@ -50,11 +51,11 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter podcastEpisodes) { + public void setItems(List podcastEpisodes) { this.podcastEpisodes = podcastEpisodes; notifyDataSetChanged(); } @@ -104,8 +105,8 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter episodes; + protected List episodes; public PodcastChannel(com.cappielloantonio.play.subsonic.models.PodcastChannel podcastChannel) { this.id = podcastChannel.getId(); @@ -27,7 +27,7 @@ public class PodcastChannel { this.episodes = MappingUtil.mapPodcastEpisode(podcastChannel.getEpisodes()); } - public PodcastChannel(String id, String url, String title, String description, String coverArtId, String originalImageUrl, String status, String errorMessage, List episodes) { + public PodcastChannel(String id, String url, String title, String description, String coverArtId, String originalImageUrl, String status, String errorMessage, List episodes) { this.id = id; this.url = url; this.title = title; @@ -103,11 +103,11 @@ public class PodcastChannel { this.errorMessage = errorMessage; } - public List getEpisodes() { + public List getEpisodes() { return episodes; } - public void setEpisodes(List episodes) { + public void setEpisodes(List episodes) { this.episodes = episodes; } } diff --git a/app/src/main/java/com/cappielloantonio/play/repository/PodcastRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/PodcastRepository.java index 6e961423..9c267a0e 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/PodcastRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/PodcastRepository.java @@ -7,8 +7,8 @@ import androidx.annotation.NonNull; import androidx.lifecycle.MutableLiveData; import com.cappielloantonio.play.App; +import com.cappielloantonio.play.model.Media; import com.cappielloantonio.play.model.PodcastChannel; -import com.cappielloantonio.play.model.PodcastEpisode; import com.cappielloantonio.play.subsonic.models.SubsonicResponse; import com.cappielloantonio.play.util.MappingUtil; @@ -50,8 +50,8 @@ public class PodcastRepository { return livePodcastChannel; } - public MutableLiveData> getNewestPodcastEpisodes(int count) { - MutableLiveData> liveNewestPodcastEpisodes = new MutableLiveData<>(); + public MutableLiveData> getNewestPodcastEpisodes(int count) { + MutableLiveData> liveNewestPodcastEpisodes = new MutableLiveData<>(); App.getSubsonicClientInstance(application, false) .getPodcastClient() diff --git a/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java index 3944f477..20bfaa34 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/QueueRepository.java @@ -28,43 +28,43 @@ public class QueueRepository { return queueDao.getAll(); } - public List getSongs() { - List songs = new ArrayList<>(); + public List getMedia() { + List media = new ArrayList<>(); - GetSongsThreadSafe getSongs = new GetSongsThreadSafe(queueDao); - Thread thread = new Thread(getSongs); + GetMediaThreadSafe getMedia = new GetMediaThreadSafe(queueDao); + Thread thread = new Thread(getMedia); thread.start(); try { thread.join(); - songs = getSongs.getSongs(); + media = getMedia.getMedia(); } catch (InterruptedException e) { e.printStackTrace(); } - return songs; + return media; } - public void insert(Media song, boolean reset, int afterIndex) { + public void insert(Media media, boolean reset, int afterIndex) { try { - List songs = new ArrayList<>(); + List mediaList = new ArrayList<>(); if (!reset) { - GetSongsThreadSafe getSongsThreadSafe = new GetSongsThreadSafe(queueDao); - Thread getSongsThread = new Thread(getSongsThreadSafe); - getSongsThread.start(); - getSongsThread.join(); + GetMediaThreadSafe getMediaThreadSafe = new GetMediaThreadSafe(queueDao); + Thread getMediaThread = new Thread(getMediaThreadSafe); + getMediaThread.start(); + getMediaThread.join(); - songs = getSongsThreadSafe.getSongs(); + mediaList = getMediaThreadSafe.getMedia(); } - songs.add(afterIndex, song); + mediaList.add(afterIndex, media); Thread delete = new Thread(new DeleteAllThreadSafe(queueDao)); delete.start(); delete.join(); - Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs)); + Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, mediaList)); insertAll.start(); insertAll.join(); } catch (InterruptedException e) { @@ -74,24 +74,24 @@ public class QueueRepository { public void insertAll(List toAdd, boolean reset, int afterIndex) { try { - List songs = new ArrayList<>(); + List media = new ArrayList<>(); if (!reset) { - GetSongsThreadSafe getSongsThreadSafe = new GetSongsThreadSafe(queueDao); - Thread getSongsThread = new Thread(getSongsThreadSafe); - getSongsThread.start(); - getSongsThread.join(); + GetMediaThreadSafe getMediaThreadSafe = new GetMediaThreadSafe(queueDao); + Thread getMediaThread = new Thread(getMediaThreadSafe); + getMediaThread.start(); + getMediaThread.join(); - songs = getSongsThreadSafe.getSongs(); + media = getMediaThreadSafe.getMedia(); } - songs.addAll(afterIndex, toAdd); + media.addAll(afterIndex, toAdd); Thread delete = new Thread(new DeleteAllThreadSafe(queueDao)); delete.start(); delete.join(); - Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, songs)); + Thread insertAll = new Thread(new InsertAllThreadSafe(queueDao, media)); insertAll.start(); insertAll.join(); } catch (InterruptedException e) { @@ -140,16 +140,16 @@ public class QueueRepository { thread.start(); } - public int getLastPlayedSongIndex() { + public int getLastPlayedMediaIndex() { int index = 0; - GetLastPlayedSongThreadSafe getLastPlayedSongThreadSafe = new GetLastPlayedSongThreadSafe(queueDao); - Thread thread = new Thread(getLastPlayedSongThreadSafe); + GetLastPlayedMediaThreadSafe getLastPlayedMediaThreadSafe = new GetLastPlayedMediaThreadSafe(queueDao); + Thread thread = new Thread(getLastPlayedMediaThreadSafe); thread.start(); try { thread.join(); - index = getLastPlayedSongThreadSafe.getIndex(); + index = getLastPlayedMediaThreadSafe.getIndex(); } catch (InterruptedException e) { e.printStackTrace(); } @@ -157,16 +157,16 @@ public class QueueRepository { return index; } - public long getLastPlayedSongTimestamp() { + public long getLastPlayedMediaTimestamp() { long timestamp = 0; - GetLastPlayedSongTimestampThreadSafe getLastPlayedSongTimestampThreadSafe = new GetLastPlayedSongTimestampThreadSafe(queueDao); - Thread thread = new Thread(getLastPlayedSongTimestampThreadSafe); + GetLastPlayedMediaTimestampThreadSafe getLastPlayedMediaTimestampThreadSafe = new GetLastPlayedMediaTimestampThreadSafe(queueDao); + Thread thread = new Thread(getLastPlayedMediaTimestampThreadSafe); thread.start(); try { thread.join(); - timestamp = getLastPlayedSongTimestampThreadSafe.getTimestamp(); + timestamp = getLastPlayedMediaTimestampThreadSafe.getTimestamp(); } catch (InterruptedException e) { e.printStackTrace(); } @@ -174,36 +174,36 @@ public class QueueRepository { return timestamp; } - private static class GetSongsThreadSafe implements Runnable { + private static class GetMediaThreadSafe implements Runnable { private final QueueDao queueDao; - private List songs; + private List media; - public GetSongsThreadSafe(QueueDao queueDao) { + public GetMediaThreadSafe(QueueDao queueDao) { this.queueDao = queueDao; } @Override public void run() { - songs = MappingUtil.mapQueue(queueDao.getAllSimple()); + media = MappingUtil.mapQueue(queueDao.getAllSimple()); } - public List getSongs() { - return songs; + public List getMedia() { + return media; } } private static class InsertAllThreadSafe implements Runnable { private final QueueDao queueDao; - private final List songs; + private final List media; - public InsertAllThreadSafe(QueueDao queueDao, List songs) { + public InsertAllThreadSafe(QueueDao queueDao, List media) { this.queueDao = queueDao; - this.songs = songs; + this.media = media; } @Override public void run() { - queueDao.insertAll(MappingUtil.mapSongsToQueue(songs)); + queueDao.insertAll(MappingUtil.mapMediaToQueue(media)); } } @@ -255,41 +255,41 @@ public class QueueRepository { private static class SetLastPlayedTimestampThreadSafe implements Runnable { private final QueueDao queueDao; - private final String songId; + private final String mediaId; - public SetLastPlayedTimestampThreadSafe(QueueDao queueDao, String songId) { + public SetLastPlayedTimestampThreadSafe(QueueDao queueDao, String mediaId) { this.queueDao = queueDao; - this.songId = songId; + this.mediaId = mediaId; } @Override public void run() { - queueDao.setLastPlay(songId, Instant.now().toEpochMilli()); + queueDao.setLastPlay(mediaId, Instant.now().toEpochMilli()); } } private static class SetPlayingPausedTimestampThreadSafe implements Runnable { private final QueueDao queueDao; - private final String songId; + private final String mediaId; private final long ms; - public SetPlayingPausedTimestampThreadSafe(QueueDao queueDao, String songId, long ms) { + public SetPlayingPausedTimestampThreadSafe(QueueDao queueDao, String mediaId, long ms) { this.queueDao = queueDao; - this.songId = songId; + this.mediaId = mediaId; this.ms = ms; } @Override public void run() { - queueDao.setPlayingChanged(songId, ms); + queueDao.setPlayingChanged(mediaId, ms); } } - private static class GetLastPlayedSongThreadSafe implements Runnable { + private static class GetLastPlayedMediaThreadSafe implements Runnable { private final QueueDao queueDao; private int index; - public GetLastPlayedSongThreadSafe(QueueDao queueDao) { + public GetLastPlayedMediaThreadSafe(QueueDao queueDao) { this.queueDao = queueDao; } @@ -303,11 +303,11 @@ public class QueueRepository { } } - private static class GetLastPlayedSongTimestampThreadSafe implements Runnable { + private static class GetLastPlayedMediaTimestampThreadSafe implements Runnable { private final QueueDao queueDao; private long timestamp; - public GetLastPlayedSongTimestampThreadSafe(QueueDao queueDao) { + public GetLastPlayedMediaTimestampThreadSafe(QueueDao queueDao) { this.queueDao = queueDao; } diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerBottomSheetFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerBottomSheetFragment.java index e4d8fe99..f12ac1ee 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerBottomSheetFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerBottomSheetFragment.java @@ -133,18 +133,19 @@ public class PlayerBottomSheetFragment extends Fragment { }); } + @SuppressLint("UnsafeOptInUsageError") private void setMetadata(MediaMetadata mediaMetadata) { - if (mediaMetadata.extras != null) playerBottomSheetViewModel.setLiveSong(requireActivity(), mediaMetadata.extras.getString("id")); - if (mediaMetadata.extras != null) playerBottomSheetViewModel.setLiveArtist(requireActivity(), mediaMetadata.extras.getString("artistId")); + if (mediaMetadata.extras != null) playerBottomSheetViewModel.setLiveMedia(requireActivity(), mediaMetadata.extras.getString("mediaType"), mediaMetadata.extras.getString("id")); + if (mediaMetadata.extras != null) playerBottomSheetViewModel.setLiveArtist(requireActivity(), mediaMetadata.extras.getString("mediaType"), mediaMetadata.extras.getString("artistId")); - bind.playerHeaderLayout.playerHeaderSongTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title))); - bind.playerHeaderLayout.playerHeaderSongArtistLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.artist))); + bind.playerHeaderLayout.playerHeaderMediaTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title))); + bind.playerHeaderLayout.playerHeaderMediaArtistLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.artist))); if (mediaMetadata.extras != null) CustomGlideRequest.Builder .from(requireContext(), mediaMetadata.extras.getString("id"), CustomGlideRequest.SONG_PIC, null) .build() .transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS)) - .into(bind.playerHeaderLayout.playerHeaderSongCoverImage); + .into(bind.playerHeaderLayout.playerHeaderMediaCoverImage); } private void setContentDuration(long duration) { @@ -165,12 +166,12 @@ public class PlayerBottomSheetFragment extends Fragment { } }); - bind.playerHeaderLayout.playerHeaderNextSongButton.setOnClickListener(view -> bind.getRoot().findViewById(R.id.exo_next).performClick()); + bind.playerHeaderLayout.playerHeaderNextMediaButton.setOnClickListener(view -> bind.getRoot().findViewById(R.id.exo_next).performClick()); } private void setHeaderNextButtonState(boolean isEnabled) { - bind.playerHeaderLayout.playerHeaderNextSongButton.setEnabled(isEnabled); - bind.playerHeaderLayout.playerHeaderNextSongButton.setAlpha(isEnabled ? (float) 1.0 : (float) 0.3); + bind.playerHeaderLayout.playerHeaderNextMediaButton.setEnabled(isEnabled); + bind.playerHeaderLayout.playerHeaderNextMediaButton.setAlpha(isEnabled ? (float) 1.0 : (float) 0.3); } public View getPlayerHeader() { diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerControllerFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerControllerFragment.java index a5e00285..753e7e91 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerControllerFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerControllerFragment.java @@ -7,7 +7,6 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.ToggleButton; @@ -38,9 +37,9 @@ public class PlayerControllerFragment extends Fragment { private InnerFragmentPlayerControllerBinding bind; private ImageView playerMoveDownBottomSheet; - private ViewPager2 playerSongCoverViewPager; + private ViewPager2 playerMediaCoverViewPager; private ToggleButton buttonFavorite; - private TextView playerSongTitleLabel; + private TextView playerMediaTitleLabel; private TextView playerArtistNameLabel; private MainActivity activity; @@ -87,9 +86,9 @@ public class PlayerControllerFragment extends Fragment { @SuppressLint("UnsafeOptInUsageError") private void init() { playerMoveDownBottomSheet = bind.getRoot().findViewById(R.id.player_move_down_bottom_sheet); - playerSongCoverViewPager = bind.getRoot().findViewById(R.id.player_song_cover_view_pager); + playerMediaCoverViewPager = bind.getRoot().findViewById(R.id.player_media_cover_view_pager); buttonFavorite = bind.getRoot().findViewById(R.id.button_favorite); - playerSongTitleLabel = bind.getRoot().findViewById(R.id.player_song_title_label); + playerMediaTitleLabel = bind.getRoot().findViewById(R.id.player_media_title_label); playerArtistNameLabel = bind.getRoot().findViewById(R.id.player_artist_name_label); playerMoveDownBottomSheet.setOnClickListener(view -> activity.collapseBottomSheet()); @@ -110,7 +109,7 @@ public class PlayerControllerFragment extends Fragment { try { MediaBrowser mediaBrowser = mediaBrowserListenableFuture.get(); - bind.nowPlayingSongControllerView.setPlayer(mediaBrowser); + bind.nowPlayingMediaControllerView.setPlayer(mediaBrowser); setMediaControllerListener(mediaBrowser); } catch (Exception e) { @@ -131,19 +130,20 @@ public class PlayerControllerFragment extends Fragment { }); } + @SuppressLint("UnsafeOptInUsageError") private void setMetadata(MediaMetadata mediaMetadata) { - playerSongTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title))); + playerMediaTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title))); playerArtistNameLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.artist))); - playerSongTitleLabel.setSelected(true); + playerMediaTitleLabel.setSelected(true); playerArtistNameLabel.setSelected(true); } private void initCoverLyricsSlideView() { - playerSongCoverViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL); - playerSongCoverViewPager.setAdapter(new PlayerControllerHorizontalPager(this)); + playerMediaCoverViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL); + playerMediaCoverViewPager.setAdapter(new PlayerControllerHorizontalPager(this)); - playerSongCoverViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { + playerMediaCoverViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override public void onPageSelected(int position) { super.onPageSelected(position); @@ -158,15 +158,15 @@ public class PlayerControllerFragment extends Fragment { } private void initMediaListenable() { - playerBottomSheetViewModel.getLiveSong().observe(requireActivity(), song -> { - if (song != null) { - buttonFavorite.setChecked(song.isFavorite()); + playerBottomSheetViewModel.getLiveMedia().observe(requireActivity(), media -> { + if (media != null) { + buttonFavorite.setChecked(media.isStarred()); - buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext(), song)); + buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext(), media)); buttonFavorite.setOnLongClickListener(v -> { Bundle bundle = new Bundle(); - bundle.putParcelable("song_object", song); + bundle.putParcelable("song_object", media); RatingDialog dialog = new RatingDialog(); dialog.setArguments(bundle); @@ -176,7 +176,7 @@ public class PlayerControllerFragment extends Fragment { }); if (getActivity() != null) { - playerBottomSheetViewModel.refreshSongInfo(requireActivity(), song); + playerBottomSheetViewModel.refreshMediaInfo(requireActivity(), media); } } }); @@ -196,10 +196,10 @@ public class PlayerControllerFragment extends Fragment { } public void goToControllerPage() { - playerSongCoverViewPager.setCurrentItem(0, false); + playerMediaCoverViewPager.setCurrentItem(0, false); } public void goToLyricsPage() { - playerSongCoverViewPager.setCurrentItem(1, true); + playerMediaCoverViewPager.setCurrentItem(1, true); } } \ No newline at end of file diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerCoverFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerCoverFragment.java index cc4f8568..d005192f 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerCoverFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/PlayerCoverFragment.java @@ -92,7 +92,7 @@ public class PlayerCoverFragment extends Fragment { } private void initInnerButton() { - playerBottomSheetViewModel.getLiveSong().observe(requireActivity(), song -> { + playerBottomSheetViewModel.getLiveMedia().observe(requireActivity(), song -> { if (song != null && bind != null) { bind.innerButtonTopLeft.setOnClickListener(view -> { DownloadUtil.getDownloadTracker(requireContext()).download( @@ -172,6 +172,7 @@ public class PlayerCoverFragment extends Fragment { }); } + @SuppressLint("UnsafeOptInUsageError") private void setCover(MediaMetadata mediaMetadata) { CustomGlideRequest.Builder .from(requireContext(), mediaMetadata.extras != null ? mediaMetadata.extras.getString("id") : null, CustomGlideRequest.SONG_PIC, null) diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java index f9b2f74c..161ac309 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java @@ -11,9 +11,8 @@ import androidx.lifecycle.MutableLiveData; import com.cappielloantonio.play.App; import com.cappielloantonio.play.model.Album; import com.cappielloantonio.play.model.Artist; -import com.cappielloantonio.play.model.Playlist; -import com.cappielloantonio.play.model.PodcastEpisode; import com.cappielloantonio.play.model.Media; +import com.cappielloantonio.play.model.Playlist; import com.cappielloantonio.play.repository.AlbumRepository; import com.cappielloantonio.play.repository.ArtistRepository; import com.cappielloantonio.play.repository.PlaylistRepository; @@ -47,7 +46,7 @@ public class HomeViewModel extends AndroidViewModel { private final MutableLiveData> years = new MutableLiveData<>(null); private final MutableLiveData> recentlyAddedAlbumSample = new MutableLiveData<>(null); private final MutableLiveData> pinnedPlaylists = new MutableLiveData<>(null); - private final MutableLiveData> newestPodcastEpisodes = new MutableLiveData<>(null); + private final MutableLiveData> newestPodcastEpisodes = new MutableLiveData<>(null); public HomeViewModel(@NonNull Application application) { super(application); @@ -134,7 +133,7 @@ public class HomeViewModel extends AndroidViewModel { return playlistRepository.getPlaylistSongs(playlistId); } - public LiveData> getNewestPodcastEpisodes(LifecycleOwner owner) { + public LiveData> getNewestPodcastEpisodes(LifecycleOwner owner) { podcastRepository.getNewestPodcastEpisodes(20).observe(owner, newestPodcastEpisodes::postValue); return newestPodcastEpisodes; } diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java index e9271bbd..1b8bbc99 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java @@ -9,7 +9,6 @@ import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; -import com.cappielloantonio.play.model.Album; import com.cappielloantonio.play.model.Artist; import com.cappielloantonio.play.model.Queue; import com.cappielloantonio.play.model.Media; @@ -31,8 +30,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel { private final MutableLiveData lyricsLiveData = new MutableLiveData<>(null); - private final MutableLiveData liveSong = new MutableLiveData<>(null); - private final MutableLiveData liveAlbum = new MutableLiveData<>(null); + private final MutableLiveData liveMedia = new MutableLiveData<>(null); private final MutableLiveData liveArtist = new MutableLiveData<>(null); public PlayerBottomSheetViewModel(@NonNull Application application) { @@ -47,19 +45,19 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel { return queueRepository.getLiveQueue(); } - public void setFavorite(Context context, Media song) { - if (song != null) { - if (song.isFavorite()) { - songRepository.unstar(song.getId()); - song.setFavorite(false); + public void setFavorite(Context context, Media media) { + if (media != null) { + if (media.isStarred()) { + songRepository.unstar(media.getId()); + media.setStarred(false); } else { - songRepository.star(song.getId()); - song.setFavorite(true); + songRepository.star(media.getId()); + media.setStarred(true); if (PreferenceUtil.getInstance(context).isStarredSyncEnabled()) { DownloadUtil.getDownloadTracker(context).download( - MappingUtil.mapMediaItem(context, song, false), - MappingUtil.mapDownload(song, null, null) + MappingUtil.mapMediaItem(context, media, false), + MappingUtil.mapDownload(media, null, null) ); } } @@ -70,23 +68,41 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel { return lyricsLiveData; } - public void refreshSongInfo(LifecycleOwner owner, Media song) { - songRepository.getSongLyrics(song).observe(owner, lyricsLiveData::postValue); + public void refreshMediaInfo(LifecycleOwner owner, Media media) { + songRepository.getSongLyrics(media).observe(owner, lyricsLiveData::postValue); } - public LiveData getLiveSong() { - return liveSong; + public LiveData getLiveMedia() { + return liveMedia; } - public void setLiveSong(LifecycleOwner owner, String songId) { - songRepository.getSong(songId).observe(owner, liveSong::postValue); + public void setLiveMedia(LifecycleOwner owner, String mediaType, String mediaId) { + if(mediaType != null) { + switch (mediaType) { + case Media.MEDIA_TYPE_MUSIC: + songRepository.getSong(mediaId).observe(owner, liveMedia::postValue); + break; + case Media.MEDIA_TYPE_PODCAST: + liveMedia.postValue(null); + break; + } + } } public LiveData getLiveArtist() { return liveArtist; } - public void setLiveArtist(LifecycleOwner owner, String ArtistId) { - artistRepository.getArtist(ArtistId).observe(owner, liveArtist::postValue); + public void setLiveArtist(LifecycleOwner owner, String mediaType, String ArtistId) { + if(mediaType != null) { + switch (mediaType) { + case Media.MEDIA_TYPE_MUSIC: + artistRepository.getArtist(ArtistId).observe(owner, liveArtist::postValue); + break; + case Media.MEDIA_TYPE_PODCAST: + liveArtist.postValue(null); + break; + } + } } } diff --git a/app/src/main/res/layout/inner_fragment_player_controller.xml b/app/src/main/res/layout/inner_fragment_player_controller.xml index f135997b..8e7214fd 100644 --- a/app/src/main/res/layout/inner_fragment_player_controller.xml +++ b/app/src/main/res/layout/inner_fragment_player_controller.xml @@ -1,7 +1,7 @@ @@ -44,7 +44,7 @@ + app:layout_constraintTop_toTopOf="@+id/player_media_title_label" /> + app:layout_constraintTop_toBottomOf="@+id/player_media_title_label" /> + app:layout_constraintStart_toEndOf="@+id/player_header_media_cover_image" + app:layout_constraintTop_toBottomOf="@+id/player_header_media_title_label" />