mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Implementation of the display of song lyrics where present
This commit is contained in:
parent
12ce97836d
commit
40cbf289af
8 changed files with 148 additions and 14 deletions
|
|
@ -264,4 +264,27 @@ public class SongRepository {
|
|||
|
||||
return song;
|
||||
}
|
||||
|
||||
public MutableLiveData<String> getSongLyrics(Song song) {
|
||||
MutableLiveData<String> lyrics = new MutableLiveData<>(null);
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getMediaRetrievalClient()
|
||||
.getLyrics(song.getArtistName(), song.getTitle())
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getLyrics() != null) {
|
||||
lyrics.setValue(response.body().getLyrics().getContent());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return lyrics;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package com.cappielloantonio.play.subsonic.models;
|
||||
|
||||
import com.tickaroo.tikxml.annotation.Attribute;
|
||||
import com.tickaroo.tikxml.annotation.TextContent;
|
||||
import com.tickaroo.tikxml.annotation.Xml;
|
||||
|
||||
@Xml
|
||||
@Xml(name = "lyrics")
|
||||
public class Lyrics {
|
||||
@Attribute(name = "value")
|
||||
@TextContent
|
||||
protected String content;
|
||||
@Attribute
|
||||
protected String artist;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public class SubsonicResponse {
|
|||
private InternetRadioStations internetRadioStations;
|
||||
private NewestPodcasts newestPodcasts;
|
||||
private Podcasts podcasts;
|
||||
@Element(name = "lyrics")
|
||||
private Lyrics lyrics;
|
||||
@Element(name = "songsByGenre")
|
||||
private Songs songsByGenre;
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
playerBottomSheetViewModel = new ViewModelProvider(requireActivity()).get(PlayerBottomSheetViewModel.class);
|
||||
|
||||
init();
|
||||
initLyricsView();
|
||||
initQueueSlideView();
|
||||
initQueueRecyclerView();
|
||||
initFavoriteButtonClick();
|
||||
|
|
@ -122,10 +123,25 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
}
|
||||
|
||||
private void init() {
|
||||
bodyBind.playerMoveDownBottomSheet.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
activity.collapseBottomSheet();
|
||||
bodyBind.playerMoveDownBottomSheet.setOnClickListener(view -> activity.collapseBottomSheet());
|
||||
}
|
||||
|
||||
private void initLyricsView() {
|
||||
playerBottomSheetViewModel.getLyrics().observe(requireActivity(), lyrics -> {
|
||||
if (lyrics != null && !lyrics.trim().equals("")) {
|
||||
bodyBind.playerSongLyricsCardview.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
bodyBind.playerSongLyricsCardview.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
bodyBind.playerSongLyricsTextView.setText(MusicUtil.getReadableString(lyrics));
|
||||
});
|
||||
|
||||
bodyBind.playerSongLyricsLabelClickable.setOnClickListener(view -> {
|
||||
if (bodyBind.playerSongLyricsTextView.getVisibility() == View.INVISIBLE || bodyBind.playerSongLyricsTextView.getVisibility() == View.GONE) {
|
||||
setLyricsTextViewVisibility(true);
|
||||
} else {
|
||||
setLyricsTextViewVisibility(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -236,7 +252,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
}
|
||||
|
||||
private void initFavoriteButtonClick() {
|
||||
bodyBind.buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext() ));
|
||||
bodyBind.buttonFavorite.setOnClickListener(v -> playerBottomSheetViewModel.setFavorite(requireContext()));
|
||||
bodyBind.buttonFavorite.setOnLongClickListener(v -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("song_object", playerBottomSheetViewModel.getCurrentSong());
|
||||
|
|
@ -301,6 +317,9 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
}
|
||||
|
||||
private void setSongInfo(Song song) {
|
||||
setLyricsTextViewVisibility(false);
|
||||
playerBottomSheetViewModel.refreshSongLyrics(requireActivity(), song);
|
||||
|
||||
bodyBind.playerSongTitleLabel.setText(MusicUtil.getReadableString(song.getTitle()));
|
||||
bodyBind.playerArtistNameLabel.setText(MusicUtil.getReadableString(song.getArtistName()));
|
||||
|
||||
|
|
@ -316,6 +335,16 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
bodyBind.buttonFavorite.setChecked(song.isFavorite());
|
||||
}
|
||||
|
||||
private void setLyricsTextViewVisibility(boolean isVisible) {
|
||||
if(isVisible) {
|
||||
bodyBind.playerSongLyricsTextView.setVisibility(View.VISIBLE);
|
||||
bodyBind.playerSongLyricsLabelClickable.setText(R.string.player_hide_lyrics_button);
|
||||
} else {
|
||||
bodyBind.playerSongLyricsTextView.setVisibility(View.GONE);
|
||||
bodyBind.playerSongLyricsLabelClickable.setText(R.string.player_show_lyrics_button);
|
||||
}
|
||||
}
|
||||
|
||||
protected void updatePlayPauseState() {
|
||||
headerBind.playerHeaderButton.setChecked(!MusicPlayerRemote.isPlaying());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ import android.content.Context;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
|
|
@ -27,6 +29,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
private final ArtistRepository artistRepository;
|
||||
private final QueueRepository queueRepository;
|
||||
|
||||
private final MutableLiveData<String> songLyrics = new MutableLiveData<>(null);
|
||||
private final LiveData<List<Queue>> queueSong;
|
||||
|
||||
public PlayerBottomSheetViewModel(@NonNull Application application) {
|
||||
|
|
@ -77,4 +80,12 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
Song song = getCurrentSong();
|
||||
return artistRepository.getArtist(song.getArtistId());
|
||||
}
|
||||
|
||||
public LiveData<String> getLyrics() {
|
||||
return songLyrics;
|
||||
}
|
||||
|
||||
public void refreshSongLyrics(LifecycleOwner owner, Song song) {
|
||||
songRepository.getSongLyrics(song).observe(owner, songLyrics::postValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue