mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
Implemented rating system for song, album and artist (album and artist do not retrieve rating from server)
This commit is contained in:
parent
055ac44cf6
commit
e2ddbdf6c9
15 changed files with 303 additions and 7 deletions
|
|
@ -35,6 +35,11 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
return queueSong;
|
||||
}
|
||||
|
||||
public Song getCurrentSong() {
|
||||
return MusicPlayerRemote.getCurrentSong();
|
||||
}
|
||||
|
||||
|
||||
public void setFavorite() {
|
||||
Song song = MusicPlayerRemote.getCurrentSong();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
package com.cappielloantonio.play.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
||||
public class RatingViewModel extends AndroidViewModel {
|
||||
private SongRepository songRepository;
|
||||
private AlbumRepository albumRepository;
|
||||
private ArtistRepository artistRepository;
|
||||
|
||||
private Song song;
|
||||
private Album album;
|
||||
private Artist artist;
|
||||
|
||||
public RatingViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
songRepository = new SongRepository(application);
|
||||
albumRepository = new AlbumRepository(application);
|
||||
artistRepository = new ArtistRepository(application);
|
||||
}
|
||||
|
||||
public Song getSong() {
|
||||
return song;
|
||||
}
|
||||
|
||||
public LiveData<Song> getLiveSong() {
|
||||
return songRepository.getSong(song.getId());
|
||||
}
|
||||
|
||||
public void setSong(Song song) {
|
||||
this.song = song;
|
||||
this.album = null;
|
||||
this.artist = null;
|
||||
}
|
||||
|
||||
public Album getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public LiveData<Album> getLiveAlbum() {
|
||||
return albumRepository.getAlbum(album.getId());
|
||||
}
|
||||
|
||||
public void setAlbum(Album album) {
|
||||
this.song = null;
|
||||
this.album = album;
|
||||
this.artist = null;
|
||||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public LiveData<Artist> getLiveArtist() {
|
||||
return artistRepository.getArtist(artist.getId());
|
||||
}
|
||||
|
||||
public void setArtist(Artist artist) {
|
||||
this.song = null;
|
||||
this.album = null;
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public int getItemRating() {
|
||||
if (song != null) {
|
||||
return song.getRating();
|
||||
} else if (album != null) {
|
||||
return 0;
|
||||
} else if (artist != null) {
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void rate(int star) {
|
||||
if (song != null) {
|
||||
songRepository.setRating(song.getId(), star);
|
||||
} else if (album != null) {
|
||||
albumRepository.setRating(album.getId(), star);
|
||||
} else if (artist != null) {
|
||||
artistRepository.setRating(artist.getId(), star);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue