mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
Refactor Song to Media
This commit is contained in:
parent
62f2723014
commit
d1d341ff9b
43 changed files with 242 additions and 274 deletions
|
|
@ -9,7 +9,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ public class AlbumBottomSheetViewModel extends AndroidViewModel {
|
|||
return artistRepository.getArtist(album.getArtistId());
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getAlbumTracks() {
|
||||
public MutableLiveData<List<Media>> getAlbumTracks() {
|
||||
return albumRepository.getAlbumTracks(album.getId());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.cappielloantonio.play.viewmodel;
|
|||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
|
@ -11,7 +10,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
|
|
@ -24,7 +23,7 @@ public class AlbumPageViewModel extends AndroidViewModel {
|
|||
private final ArtistRepository artistRepository;
|
||||
private final DownloadRepository downloadRepository;
|
||||
|
||||
private MutableLiveData<List<Song>> songLiveList = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Media>> songLiveList = new MutableLiveData<>();
|
||||
|
||||
private Album album;
|
||||
private boolean isOffline;
|
||||
|
|
@ -37,7 +36,7 @@ public class AlbumPageViewModel extends AndroidViewModel {
|
|||
downloadRepository = new DownloadRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getAlbumSongLiveList(LifecycleOwner owner) {
|
||||
public LiveData<List<Media>> getAlbumSongLiveList(LifecycleOwner owner) {
|
||||
if (isOffline) {
|
||||
downloadRepository.getLiveDownloadFromAlbum(album.getId()).observe(owner, downloads -> songLiveList.postValue(MappingUtil.mapDownloadToSong(downloads)));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ 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.model.Media;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ public class ArtistPageViewModel extends AndroidViewModel {
|
|||
return artistRepository.getArtistFullInfo(id);
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getArtistTopSongList(int count) {
|
||||
public LiveData<List<Media>> getArtistTopSongList(int count) {
|
||||
return artistRepository.getTopSongs(artist.getName(), count);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ public class DownloadViewModel extends AndroidViewModel {
|
|||
|
||||
private final MutableLiveData<List<Artist>> downloadedArtistSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> downloadedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> downloadedTrackSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> downloadedTrackSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Playlist>> downloadedPlaylistSample = new MutableLiveData<>(null);
|
||||
|
||||
public DownloadViewModel(@NonNull Application application) {
|
||||
|
|
@ -43,7 +43,7 @@ public class DownloadViewModel extends AndroidViewModel {
|
|||
return downloadedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getDownloadedTracks(LifecycleOwner owner, int size) {
|
||||
public LiveData<List<Media>> getDownloadedTracks(LifecycleOwner owner, int size) {
|
||||
downloadRepository.getLiveDownloadSample(size, false, false, true, false).observe(owner, downloads -> downloadedTrackSample.postValue(MappingUtil.mapDownloadToSong(downloads)));
|
||||
return downloadedTrackSample;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@ 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.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
import com.cappielloantonio.play.repository.PodcastRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.subsonic.models.NewestPodcasts;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
|
@ -36,11 +35,11 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final PlaylistRepository playlistRepository;
|
||||
private final PodcastRepository podcastRepository;
|
||||
|
||||
private final MutableLiveData<List<Song>> dicoverSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> dicoverSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> newReleasedAlbum = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> starredTracksSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> starredTracksSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtistsSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> mostPlayedAlbumSample = new MutableLiveData<>(null);
|
||||
|
|
@ -64,7 +63,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
artistRepository.getStarredArtists(true, 10).observeForever(starredArtistsSample::postValue);
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getDiscoverSongSample() {
|
||||
public LiveData<List<Media>> getDiscoverSongSample() {
|
||||
return dicoverSongSample;
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +78,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return newReleasedAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getStarredTracksSample() {
|
||||
public LiveData<List<Media>> getStarredTracksSample() {
|
||||
return starredTracksSample;
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +86,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return starredArtistsSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getStarredTracks(LifecycleOwner owner) {
|
||||
public LiveData<List<Media>> getStarredTracks(LifecycleOwner owner) {
|
||||
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||||
return starredTracks;
|
||||
}
|
||||
|
|
@ -131,7 +130,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return pinnedPlaylists;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getPlaylistSongLiveList(String playlistId) {
|
||||
public LiveData<List<Media>> getPlaylistSongLiveList(String playlistId) {
|
||||
return playlistRepository.getPlaylistSongs(playlistId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ 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.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
|
@ -31,7 +31,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
|
||||
private final MutableLiveData<String> lyricsLiveData = new MutableLiveData<>(null);
|
||||
|
||||
private final MutableLiveData<Song> liveSong = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<Media> liveSong = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<Album> liveAlbum = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<Artist> liveArtist = new MutableLiveData<>(null);
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
return queueRepository.getLiveQueue();
|
||||
}
|
||||
|
||||
public void setFavorite(Context context, Song song) {
|
||||
public void setFavorite(Context context, Media song) {
|
||||
if (song != null) {
|
||||
if (song.isFavorite()) {
|
||||
songRepository.unstar(song.getId());
|
||||
|
|
@ -70,11 +70,11 @@ public class PlayerBottomSheetViewModel extends AndroidViewModel {
|
|||
return lyricsLiveData;
|
||||
}
|
||||
|
||||
public void refreshSongInfo(LifecycleOwner owner, Song song) {
|
||||
public void refreshSongInfo(LifecycleOwner owner, Media song) {
|
||||
songRepository.getSongLyrics(song).observe(owner, lyricsLiveData::postValue);
|
||||
}
|
||||
|
||||
public LiveData<Song> getLiveSong() {
|
||||
public LiveData<Media> getLiveSong() {
|
||||
return liveSong;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import androidx.lifecycle.LiveData;
|
|||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -19,7 +19,7 @@ public class PlaylistChooserViewModel extends AndroidViewModel {
|
|||
private final PlaylistRepository playlistRepository;
|
||||
|
||||
private final MutableLiveData<List<Playlist>> playlists = new MutableLiveData<>(null);
|
||||
private Song toAdd;
|
||||
private Media toAdd;
|
||||
|
||||
public PlaylistChooserViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -38,11 +38,11 @@ public class PlaylistChooserViewModel extends AndroidViewModel {
|
|||
playlistRepository.addSongToPlaylist(playlistId, new ArrayList(Collections.singletonList(toAdd.getId())));
|
||||
}
|
||||
|
||||
public void setSongToAdd(Song song) {
|
||||
public void setSongToAdd(Media song) {
|
||||
toAdd = song;
|
||||
}
|
||||
|
||||
public Song getSongToAdd() {
|
||||
public Media getSongToAdd() {
|
||||
return toAdd;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.cappielloantonio.play.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
|
|
@ -9,7 +8,7 @@ import androidx.lifecycle.LiveData;
|
|||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -22,10 +21,10 @@ public class PlaylistEditorViewModel extends AndroidViewModel {
|
|||
|
||||
private final PlaylistRepository playlistRepository;
|
||||
|
||||
private Song toAdd;
|
||||
private Media toAdd;
|
||||
private Playlist toEdit;
|
||||
|
||||
private MutableLiveData<List<Song>> songLiveList = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Media>> songLiveList = new MutableLiveData<>();
|
||||
|
||||
public PlaylistEditorViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -46,11 +45,11 @@ public class PlaylistEditorViewModel extends AndroidViewModel {
|
|||
if (toEdit != null) playlistRepository.deletePlaylist(toEdit.getId());
|
||||
}
|
||||
|
||||
public Song getSongToAdd() {
|
||||
public Media getSongToAdd() {
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
public void setSongToAdd(Song song) {
|
||||
public void setSongToAdd(Media song) {
|
||||
this.toAdd = song;
|
||||
}
|
||||
|
||||
|
|
@ -68,26 +67,26 @@ public class PlaylistEditorViewModel extends AndroidViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getPlaylistSongLiveList() {
|
||||
public LiveData<List<Media>> getPlaylistSongLiveList() {
|
||||
return songLiveList;
|
||||
}
|
||||
|
||||
public void removeFromPlaylistSongLiveList(int position) {
|
||||
List<Song> songs = songLiveList.getValue();
|
||||
List<Media> songs = songLiveList.getValue();
|
||||
Objects.requireNonNull(songs).remove(position);
|
||||
songLiveList.postValue(songs);
|
||||
}
|
||||
|
||||
public void orderPlaylistSongLiveListAfterSwap(List<Song> songs) {
|
||||
public void orderPlaylistSongLiveListAfterSwap(List<Media> songs) {
|
||||
songLiveList.postValue(songs);
|
||||
}
|
||||
|
||||
private ArrayList<String> getPlaylistSongIds() {
|
||||
List<Song> songs = songLiveList.getValue();
|
||||
List<Media> songs = songLiveList.getValue();
|
||||
ArrayList<String> ids = new ArrayList<>();
|
||||
|
||||
if (songs != null && !songs.isEmpty()) {
|
||||
for (Song song : songs) {
|
||||
for (Media song : songs) {
|
||||
ids.add(song.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.cappielloantonio.play.viewmodel;
|
|||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
|
@ -11,7 +10,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
|
@ -23,7 +22,7 @@ public class PlaylistPageViewModel extends AndroidViewModel {
|
|||
private final PlaylistRepository playlistRepository;
|
||||
private final DownloadRepository downloadRepository;
|
||||
|
||||
private MutableLiveData<List<Song>> playlistSongLiveList = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Media>> playlistSongLiveList = new MutableLiveData<>();
|
||||
|
||||
private Playlist playlist;
|
||||
private boolean isOffline;
|
||||
|
|
@ -35,7 +34,7 @@ public class PlaylistPageViewModel extends AndroidViewModel {
|
|||
downloadRepository = new DownloadRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getPlaylistSongLiveList(LifecycleOwner owner) {
|
||||
public LiveData<List<Media>> getPlaylistSongLiveList(LifecycleOwner owner) {
|
||||
if (isOffline) {
|
||||
downloadRepository.getLiveDownloadFromPlaylist(playlist.getId()).observe(owner, downloads -> playlistSongLiveList.postValue(MappingUtil.mapDownloadToSong(downloads)));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ 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.model.Media;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
|
@ -18,7 +18,7 @@ public class RatingViewModel extends AndroidViewModel {
|
|||
private final AlbumRepository albumRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
|
||||
private Song song;
|
||||
private Media song;
|
||||
private Album album;
|
||||
private Artist artist;
|
||||
|
||||
|
|
@ -30,15 +30,15 @@ public class RatingViewModel extends AndroidViewModel {
|
|||
artistRepository = new ArtistRepository(application);
|
||||
}
|
||||
|
||||
public Song getSong() {
|
||||
public Media getSong() {
|
||||
return song;
|
||||
}
|
||||
|
||||
public LiveData<Song> getLiveSong() {
|
||||
public LiveData<Media> getLiveSong() {
|
||||
return songRepository.getSong(song.getId());
|
||||
}
|
||||
|
||||
public void setSong(Song song) {
|
||||
public void setSong(Media song) {
|
||||
this.song = song;
|
||||
this.album = null;
|
||||
this.artist = null;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import androidx.lifecycle.LiveData;
|
|||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.RecentSearch;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.SearchingRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -40,7 +40,7 @@ public class SearchViewModel extends AndroidViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> searchSong(String title) {
|
||||
public LiveData<List<Media>> searchSong(String title) {
|
||||
return searchingRepository.getSearchedSongs(title);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ 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.model.Media;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
|
@ -22,7 +22,7 @@ public class SongBottomSheetViewModel extends AndroidViewModel {
|
|||
private final AlbumRepository albumRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
|
||||
private Song song;
|
||||
private Media song;
|
||||
|
||||
public SongBottomSheetViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -32,11 +32,11 @@ public class SongBottomSheetViewModel extends AndroidViewModel {
|
|||
artistRepository = new ArtistRepository(application);
|
||||
}
|
||||
|
||||
public Song getSong() {
|
||||
public Media getSong() {
|
||||
return song;
|
||||
}
|
||||
|
||||
public void setSong(Song song) {
|
||||
public void setSong(Media song) {
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.app.Application;
|
|||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
|
@ -13,7 +12,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
|
@ -33,7 +32,7 @@ public class SongListPageViewModel extends AndroidViewModel {
|
|||
public Artist artist;
|
||||
public Album album;
|
||||
|
||||
private MutableLiveData<List<Song>> songList;
|
||||
private MutableLiveData<List<Media>> songList;
|
||||
|
||||
public ArrayList<String> filters = new ArrayList<>();
|
||||
public ArrayList<String> filterNames = new ArrayList<>();
|
||||
|
|
@ -48,29 +47,29 @@ public class SongListPageViewModel extends AndroidViewModel {
|
|||
downloadRepository = new DownloadRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getSongList(LifecycleOwner owner) {
|
||||
public LiveData<List<Media>> getSongList(LifecycleOwner owner) {
|
||||
songList = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
switch (title) {
|
||||
case Song.BY_GENRE:
|
||||
case Media.BY_GENRE:
|
||||
songList = songRepository.getSongsByGenre(genre.getId());
|
||||
break;
|
||||
case Song.BY_ARTIST:
|
||||
case Media.BY_ARTIST:
|
||||
songList = artistRepository.getTopSongs(artist.getName(), 50);
|
||||
break;
|
||||
case Song.BY_GENRES:
|
||||
case Media.BY_GENRES:
|
||||
songList = songRepository.getSongsByGenres(filters);
|
||||
break;
|
||||
case Song.BY_YEAR:
|
||||
case Media.BY_YEAR:
|
||||
songList = songRepository.getRandomSample(500, year, year + 10);
|
||||
break;
|
||||
case Song.STARRED:
|
||||
case Media.STARRED:
|
||||
songList = songRepository.getStarredSongs(false, -1);
|
||||
break;
|
||||
case Song.DOWNLOADED:
|
||||
case Media.DOWNLOADED:
|
||||
downloadRepository.getLiveDownload().observe(owner, downloads -> songList.setValue(MappingUtil.mapDownloadToSong(downloads)));
|
||||
break;
|
||||
case Song.FROM_ALBUM:
|
||||
case Media.FROM_ALBUM:
|
||||
downloadRepository.getLiveDownloadFromAlbum(album.getId()).observe(owner, downloads -> songList.setValue(MappingUtil.mapDownloadToSong(downloads)));
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,19 +8,15 @@ import androidx.lifecycle.LifecycleOwner;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StarredSyncViewModel extends AndroidViewModel {
|
||||
private final SongRepository songRepository;
|
||||
|
||||
private final MutableLiveData<List<Song>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Media>> starredTracks = new MutableLiveData<>(null);
|
||||
|
||||
public StarredSyncViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -28,7 +24,7 @@ public class StarredSyncViewModel extends AndroidViewModel {
|
|||
songRepository = new SongRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getStarredTracks(LifecycleOwner owner) {
|
||||
public LiveData<List<Media>> getStarredTracks(LifecycleOwner owner) {
|
||||
songRepository.getStarredSongs(false, -1).observe(owner, starredTracks::postValue);
|
||||
return starredTracks;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue