mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-02-01 07:03:35 +00:00
Add favorite view
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.cappielloantonio.play.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
|
||||
public class AlbumBottomSheetViewModel extends AndroidViewModel {
|
||||
private SongRepository songRepository;
|
||||
private Song song;
|
||||
|
||||
public AlbumBottomSheetViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
songRepository = new SongRepository(application);
|
||||
}
|
||||
|
||||
public void setSong(Song song) {
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
public Song getSong() {
|
||||
return song;
|
||||
}
|
||||
|
||||
public void setFavorite() {
|
||||
if(song.isFavorite()) {
|
||||
song.setFavorite(false);
|
||||
}
|
||||
else {
|
||||
song.setFavorite(true);
|
||||
}
|
||||
|
||||
songRepository.setFavoriteStatus(song);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -20,6 +19,7 @@ public class HomeViewModel extends AndroidViewModel {
|
||||
private LiveData<List<Song>> recentlyPlayedSongSample;
|
||||
private LiveData<List<Song>> recentlyAddedSongSample;
|
||||
private LiveData<List<Song>> mostPlayedSongSample;
|
||||
private LiveData<List<Song>> favoritesSongSample;
|
||||
private List<Integer> years;
|
||||
|
||||
public HomeViewModel(@NonNull Application application) {
|
||||
@@ -31,6 +31,7 @@ public class HomeViewModel extends AndroidViewModel {
|
||||
recentlyPlayedSongSample = songRepository.getListLiveRecentlyPlayedSampleSong(20);
|
||||
recentlyAddedSongSample = songRepository.getListLiveRecentlyAddedSampleSong(20);
|
||||
mostPlayedSongSample = songRepository.getListLiveMostPlayedSampleSong(20);
|
||||
favoritesSongSample = songRepository.getListLiveFavoritesSampleSong(20);
|
||||
years = songRepository.getYearList();
|
||||
}
|
||||
|
||||
@@ -56,7 +57,10 @@ public class HomeViewModel extends AndroidViewModel {
|
||||
}
|
||||
|
||||
public List<Integer> getYearList() {
|
||||
Log.d(TAG, "getYearList: " + years.toString());
|
||||
return years;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getFavorites() {
|
||||
return favoritesSongSample;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ public class SongListPageViewModel extends AndroidViewModel {
|
||||
case Song.BY_YEAR:
|
||||
songList = songRepository.getSongByYearListLive(year);
|
||||
break;
|
||||
case Song.IS_FAVORITE:
|
||||
songList = songRepository.getListLiveFavoritesSong();
|
||||
break;
|
||||
}
|
||||
|
||||
return songList;
|
||||
|
||||
Reference in New Issue
Block a user