mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Implemented lyrics loading logic
This commit is contained in:
parent
c046533d49
commit
d526b3163f
2 changed files with 47 additions and 27 deletions
|
|
@ -84,7 +84,7 @@ public class PlayerBottomSheetFragment extends Fragment {
|
||||||
init();
|
init();
|
||||||
initCoverLyricsSlideView();
|
initCoverLyricsSlideView();
|
||||||
initQueueRecyclerView();
|
initQueueRecyclerView();
|
||||||
initFavoriteButtonClick();
|
initMediaListenable();
|
||||||
initMusicCommandUnfoldButton();
|
initMusicCommandUnfoldButton();
|
||||||
initArtistLabelButton();
|
initArtistLabelButton();
|
||||||
|
|
||||||
|
|
@ -184,14 +184,17 @@ public class PlayerBottomSheetFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMetadata(MediaMetadata mediaMetadata) {
|
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"));
|
||||||
|
|
||||||
bind.playerHeaderLayout.playerHeaderSongTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title)));
|
bind.playerHeaderLayout.playerHeaderSongTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title)));
|
||||||
bind.playerHeaderLayout.playerHeaderSongArtistLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.artist)));
|
bind.playerHeaderLayout.playerHeaderSongArtistLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.artist)));
|
||||||
|
|
||||||
playerSongTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title)));
|
playerSongTitleLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.title)));
|
||||||
playerArtistNameLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.artist)));
|
playerArtistNameLabel.setText(MusicUtil.getReadableString(String.valueOf(mediaMetadata.artist)));
|
||||||
|
|
||||||
CustomGlideRequest.Builder
|
if (mediaMetadata.extras != null) CustomGlideRequest.Builder
|
||||||
.from(requireContext(), mediaMetadata.extras != null ? mediaMetadata.extras.getString("id") : null, CustomGlideRequest.SONG_PIC, null)
|
.from(requireContext(), mediaMetadata.extras.getString("id"), CustomGlideRequest.SONG_PIC, null)
|
||||||
.build()
|
.build()
|
||||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||||
.into(bind.playerHeaderLayout.playerHeaderSongCoverImage);
|
.into(bind.playerHeaderLayout.playerHeaderSongCoverImage);
|
||||||
|
|
@ -305,17 +308,26 @@ public class PlayerBottomSheetFragment extends Fragment {
|
||||||
}).attachToRecyclerView(playerQueueRecyclerView);
|
}).attachToRecyclerView(playerQueueRecyclerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFavoriteButtonClick() {
|
private void initMediaListenable() {
|
||||||
buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext()));
|
playerBottomSheetViewModel.getLiveSong().observe(requireActivity(), song -> {
|
||||||
buttonFavorite.setOnLongClickListener(v -> {
|
if (song != null) {
|
||||||
Bundle bundle = new Bundle();
|
buttonFavorite.setChecked(song.isFavorite());
|
||||||
bundle.putParcelable("song_object", playerBottomSheetViewModel.getCurrentSong());
|
|
||||||
|
|
||||||
RatingDialog dialog = new RatingDialog();
|
buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext(), song));
|
||||||
dialog.setArguments(bundle);
|
|
||||||
dialog.show(requireActivity().getSupportFragmentManager(), null);
|
|
||||||
|
|
||||||
return true;
|
buttonFavorite.setOnLongClickListener(v -> {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("song_object", song);
|
||||||
|
|
||||||
|
RatingDialog dialog = new RatingDialog();
|
||||||
|
dialog.setArguments(bundle);
|
||||||
|
dialog.show(requireActivity().getSupportFragmentManager(), null);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
playerBottomSheetViewModel.refreshSongInfo(requireActivity(), song);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,7 +342,7 @@ public class PlayerBottomSheetFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initArtistLabelButton() {
|
private void initArtistLabelButton() {
|
||||||
playerArtistNameLabel.setOnClickListener(view -> playerBottomSheetViewModel.getArtist().observe(requireActivity(), artist -> {
|
playerArtistNameLabel.setOnClickListener(view -> playerBottomSheetViewModel.getLiveArtist().observe(requireActivity(), artist -> {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putParcelable("artist_object", artist);
|
bundle.putParcelable("artist_object", artist);
|
||||||
NavHostFragment.findNavController(this).navigate(R.id.artistPageFragment, bundle);
|
NavHostFragment.findNavController(this).navigate(R.id.artistPageFragment, bundle);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.model.Album;
|
||||||
import com.cappielloantonio.play.model.Artist;
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.model.Queue;
|
import com.cappielloantonio.play.model.Queue;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
|
|
@ -27,7 +28,10 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
||||||
private final QueueRepository queueRepository;
|
private final QueueRepository queueRepository;
|
||||||
|
|
||||||
private final MutableLiveData<String> lyricsLiveData = new MutableLiveData<>(null);
|
private final MutableLiveData<String> lyricsLiveData = new MutableLiveData<>(null);
|
||||||
private final MutableLiveData<Song> songLiveData = new MutableLiveData<>(null);
|
|
||||||
|
private final MutableLiveData<Song> liveSong = new MutableLiveData<>(null);
|
||||||
|
private final MutableLiveData<Album> liveAlbum = new MutableLiveData<>(null);
|
||||||
|
private final MutableLiveData<Artist> liveArtist = new MutableLiveData<>(null);
|
||||||
|
|
||||||
public PlayerBottomSheetViewModel(@NonNull Application application) {
|
public PlayerBottomSheetViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
@ -46,9 +50,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFavorite(Context context) {
|
public void setFavorite(Context context, Song song) {
|
||||||
Song song = getCurrentSong();
|
|
||||||
|
|
||||||
if (song != null) {
|
if (song != null) {
|
||||||
if (song.isFavorite()) {
|
if (song.isFavorite()) {
|
||||||
songRepository.unstar(song.getId());
|
songRepository.unstar(song.getId());
|
||||||
|
|
@ -64,22 +66,28 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Artist> getArtist() {
|
|
||||||
Song song = getCurrentSong();
|
|
||||||
return artistRepository.getArtist(song.getArtistId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<Song> getLiveSong() {
|
|
||||||
return songLiveData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<String> getLiveLyrics() {
|
public LiveData<String> getLiveLyrics() {
|
||||||
return lyricsLiveData;
|
return lyricsLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshSongInfo(LifecycleOwner owner, Song song) {
|
public void refreshSongInfo(LifecycleOwner owner, Song song) {
|
||||||
songLiveData.postValue(song);
|
// songLiveData.postValue(song);
|
||||||
songRepository.getSongLyrics(song).observe(owner, lyricsLiveData::postValue);
|
songRepository.getSongLyrics(song).observe(owner, lyricsLiveData::postValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Song> getLiveSong() {
|
||||||
|
return liveSong;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLiveSong(LifecycleOwner owner, String songId) {
|
||||||
|
songRepository.getSong(songId).observe(owner, liveSong::postValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Artist> getLiveArtist() {
|
||||||
|
return liveArtist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLiveArtist(LifecycleOwner owner, String ArtistId) {
|
||||||
|
artistRepository.getArtist(ArtistId).observe(owner, liveArtist::postValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue