mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
Moved newReleases view from library to home
This commit is contained in:
parent
994ee1e2f7
commit
e5229dd48b
7 changed files with 85 additions and 88 deletions
|
|
@ -19,7 +19,9 @@ import com.cappielloantonio.play.repository.PlaylistRepository;
|
|||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class HomeViewModel extends AndroidViewModel {
|
||||
|
|
@ -31,8 +33,8 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final PlaylistRepository playlistRepository;
|
||||
|
||||
private final MutableLiveData<List<Song>> 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<Album>> mostPlayedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> recentlyPlayedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Integer>> years = new MutableLiveData<>(null);
|
||||
|
|
@ -58,6 +60,17 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return dicoverSongSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getRecentlyReleasedAlbums(LifecycleOwner owner) {
|
||||
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
|
||||
|
||||
albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> {
|
||||
albums.sort(Comparator.comparing(Album::getCreated).reversed());
|
||||
newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size())));
|
||||
});
|
||||
|
||||
return newReleasedAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getStarredTracksSample() {
|
||||
return starredTracksSample;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
|
||||
private final MutableLiveData<List<Playlist>> playlistSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> sampleAlbum = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> newReleasedAlbum = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> sampleArtist = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Genre>> sampleGenres = new MutableLiveData<>(null);
|
||||
|
||||
|
|
@ -51,17 +50,6 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
playlistRepository.getPlaylists(true, 10).observeForever(playlistSample::postValue);
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getRecentlyReleasedAlbums(LifecycleOwner owner) {
|
||||
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
|
||||
|
||||
albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> {
|
||||
albums.sort(Comparator.comparing(Album::getCreated).reversed());
|
||||
newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size())));
|
||||
});
|
||||
|
||||
return newReleasedAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getAlbumSample() {
|
||||
return sampleAlbum;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue