mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
build: change of package name
This commit is contained in:
parent
49afdbe4eb
commit
b76a38cb30
274 changed files with 1981 additions and 2161 deletions
|
|
@ -0,0 +1,240 @@
|
|||
package com.cappielloantonio.tempo.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.tempo.model.Chronology;
|
||||
import com.cappielloantonio.tempo.repository.AlbumRepository;
|
||||
import com.cappielloantonio.tempo.repository.ArtistRepository;
|
||||
import com.cappielloantonio.tempo.repository.ChronologyRepository;
|
||||
import com.cappielloantonio.tempo.repository.PodcastRepository;
|
||||
import com.cappielloantonio.tempo.repository.SongRepository;
|
||||
import com.cappielloantonio.tempo.subsonic.models.AlbumID3;
|
||||
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
|
||||
import com.cappielloantonio.tempo.subsonic.models.Child;
|
||||
import com.cappielloantonio.tempo.util.Preferences;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class HomeViewModel extends AndroidViewModel {
|
||||
private static final String TAG = "HomeViewModel";
|
||||
|
||||
private final SongRepository songRepository;
|
||||
private final AlbumRepository albumRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
private final PodcastRepository podcastRepository;
|
||||
private final ChronologyRepository chronologyRepository;
|
||||
|
||||
private final MutableLiveData<List<Child>> dicoverSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<AlbumID3>> newReleasedAlbum = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Child>> starredTracksSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<ArtistID3>> starredArtistsSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<ArtistID3>> bestOfArtists = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Child>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<AlbumID3>> starredAlbums = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<ArtistID3>> starredArtists = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<AlbumID3>> mostPlayedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<AlbumID3>> recentlyPlayedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Integer>> years = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<AlbumID3>> recentlyAddedAlbumSample = new MutableLiveData<>(null);
|
||||
|
||||
private final MutableLiveData<List<Chronology>> thisGridTopSong = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Child>> mediaInstantMix = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Child>> artistInstantMix = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Child>> artistBestOf = new MutableLiveData<>(null);
|
||||
|
||||
public HomeViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
songRepository = new SongRepository();
|
||||
albumRepository = new AlbumRepository();
|
||||
artistRepository = new ArtistRepository();
|
||||
podcastRepository = new PodcastRepository();
|
||||
chronologyRepository = new ChronologyRepository();
|
||||
}
|
||||
|
||||
public LiveData<List<Child>> getDiscoverSongSample(LifecycleOwner owner) {
|
||||
if (dicoverSongSample.getValue() == null) {
|
||||
songRepository.getRandomSample(10, null, null).observe(owner, dicoverSongSample::postValue);
|
||||
}
|
||||
|
||||
return dicoverSongSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Chronology>> getGridSongSample(LifecycleOwner owner) {
|
||||
String server = Preferences.getServerId();
|
||||
chronologyRepository.getLastWeek(server).observe(owner, thisGridTopSong::postValue);
|
||||
return thisGridTopSong;
|
||||
}
|
||||
|
||||
public LiveData<List<AlbumID3>> getRecentlyReleasedAlbums(LifecycleOwner owner) {
|
||||
if (newReleasedAlbum.getValue() == null) {
|
||||
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
|
||||
|
||||
albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> {
|
||||
if (albums != null) {
|
||||
albums.sort(Comparator.comparing(AlbumID3::getCreated).reversed());
|
||||
newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return newReleasedAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Child>> getStarredTracksSample(LifecycleOwner owner) {
|
||||
if (starredTracksSample.getValue() == null) {
|
||||
songRepository.getStarredSongs(true, 10).observe(owner, starredTracksSample::postValue);
|
||||
}
|
||||
|
||||
return starredTracksSample;
|
||||
}
|
||||
|
||||
public LiveData<List<ArtistID3>> getStarredArtistsSample(LifecycleOwner owner) {
|
||||
if (starredArtistsSample.getValue() == null) {
|
||||
artistRepository.getStarredArtists(true, 10).observe(owner, starredArtistsSample::postValue);
|
||||
}
|
||||
|
||||
return starredArtistsSample;
|
||||
}
|
||||
|
||||
public LiveData<List<ArtistID3>> getBestOfArtists(LifecycleOwner owner) {
|
||||
if (bestOfArtists.getValue() == null) {
|
||||
artistRepository.getStarredArtists(true, 20).observe(owner, bestOfArtists::postValue);
|
||||
}
|
||||
|
||||
return bestOfArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Child>> getStarredTracks(LifecycleOwner owner) {
|
||||
if (starredTracks.getValue() == null) {
|
||||
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||||
}
|
||||
|
||||
return starredTracks;
|
||||
}
|
||||
|
||||
public LiveData<List<AlbumID3>> getStarredAlbums(LifecycleOwner owner) {
|
||||
if (starredAlbums.getValue() == null) {
|
||||
albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue);
|
||||
}
|
||||
|
||||
return starredAlbums;
|
||||
}
|
||||
|
||||
public LiveData<List<ArtistID3>> getStarredArtists(LifecycleOwner owner) {
|
||||
if (starredArtists.getValue() == null) {
|
||||
artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue);
|
||||
}
|
||||
|
||||
return starredArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Integer>> getYearList(LifecycleOwner owner) {
|
||||
if (years.getValue() == null) {
|
||||
albumRepository.getDecades().observe(owner, years::postValue);
|
||||
}
|
||||
|
||||
return years;
|
||||
}
|
||||
|
||||
public LiveData<List<AlbumID3>> getMostPlayedAlbums(LifecycleOwner owner) {
|
||||
if (mostPlayedAlbumSample.getValue() == null) {
|
||||
albumRepository.getAlbums("frequent", 20, null, null).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
}
|
||||
|
||||
return mostPlayedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<AlbumID3>> getMostRecentlyAddedAlbums(LifecycleOwner owner) {
|
||||
if (recentlyAddedAlbumSample.getValue() == null) {
|
||||
albumRepository.getAlbums("newest", 20, null, null).observe(owner, recentlyAddedAlbumSample::postValue);
|
||||
}
|
||||
|
||||
return recentlyAddedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<AlbumID3>> getRecentlyPlayedAlbumList(LifecycleOwner owner) {
|
||||
if (recentlyPlayedAlbumSample.getValue() == null) {
|
||||
albumRepository.getAlbums("recent", 20, null, null).observe(owner, recentlyPlayedAlbumSample::postValue);
|
||||
}
|
||||
|
||||
return recentlyPlayedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Child>> getMediaInstantMix(LifecycleOwner owner, Child media) {
|
||||
mediaInstantMix.setValue(Collections.emptyList());
|
||||
|
||||
songRepository.getInstantMix(media, 20).observe(owner, mediaInstantMix::postValue);
|
||||
|
||||
return mediaInstantMix;
|
||||
}
|
||||
|
||||
public LiveData<List<Child>> getArtistInstantMix(LifecycleOwner owner, ArtistID3 artist) {
|
||||
artistInstantMix.setValue(Collections.emptyList());
|
||||
|
||||
artistRepository.getTopSongs(artist.getName(), 10).observe(owner, artistInstantMix::postValue);
|
||||
|
||||
return artistInstantMix;
|
||||
}
|
||||
|
||||
public LiveData<List<Child>> getArtistBestOf(LifecycleOwner owner, ArtistID3 artist) {
|
||||
artistBestOf.setValue(Collections.emptyList());
|
||||
|
||||
artistRepository.getTopSongs(artist.getName(), 10).observe(owner, artistBestOf::postValue);
|
||||
|
||||
return artistBestOf;
|
||||
}
|
||||
|
||||
public LiveData<List<Child>> getAllStarredTracks() {
|
||||
return songRepository.getStarredSongs(false, -1);
|
||||
}
|
||||
|
||||
public void refreshDiscoverySongSample(LifecycleOwner owner) {
|
||||
songRepository.getRandomSample(10, null, null).observe(owner, dicoverSongSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshSimilarSongSample(LifecycleOwner owner) {
|
||||
songRepository.getStarredSongs(true, 10).observe(owner, starredTracksSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshRadioArtistSample(LifecycleOwner owner) {
|
||||
artistRepository.getStarredArtists(true, 10).observe(owner, starredArtistsSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshBestOfArtist(LifecycleOwner owner) {
|
||||
artistRepository.getStarredArtists(true, 20).observe(owner, bestOfArtists::postValue);
|
||||
}
|
||||
|
||||
public void refreshStarredTracks(LifecycleOwner owner) {
|
||||
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||||
}
|
||||
|
||||
public void refreshStarredAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue);
|
||||
}
|
||||
|
||||
public void refreshStarredArtists(LifecycleOwner owner) {
|
||||
artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue);
|
||||
}
|
||||
|
||||
public void refreshMostPlayedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("frequent", 20, null, null).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshMostRecentlyAddedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("newest", 20, null, null).observe(owner, recentlyAddedAlbumSample::postValue);
|
||||
}
|
||||
|
||||
public void refreshRecentlyPlayedAlbumList(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("recent", 20, null, null).observe(owner, recentlyPlayedAlbumSample::postValue);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue