mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Add artist page
This commit is contained in:
parent
8b7e383dc2
commit
c2be2711b9
44 changed files with 1028 additions and 191 deletions
|
|
@ -7,6 +7,8 @@ import androidx.lifecycle.LiveData;
|
|||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -14,7 +16,10 @@ import java.util.List;
|
|||
public class AlbumRepository {
|
||||
private AlbumDao albumDao;
|
||||
private LiveData<List<Album>> listLiveAlbums;
|
||||
private LiveData<List<Album>> artistListLiveAlbums;
|
||||
private LiveData<List<Album>> listLiveSampleAlbum;
|
||||
private LiveData<List<Album>> searchListLiveAlbum;
|
||||
|
||||
|
||||
public AlbumRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
|
|
@ -26,11 +31,21 @@ public class AlbumRepository {
|
|||
return listLiveAlbums;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getArtistListLiveAlbums(String artistId) {
|
||||
artistListLiveAlbums = albumDao.getArtistAlbums(artistId);
|
||||
return artistListLiveAlbums;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getListLiveSampleAlbum() {
|
||||
listLiveSampleAlbum = albumDao.getSample(10);
|
||||
return listLiveSampleAlbum;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> searchListLiveAlbum(String name) {
|
||||
searchListLiveAlbum = albumDao.searchAlbum(name);
|
||||
return searchListLiveAlbum;
|
||||
}
|
||||
|
||||
public boolean exist(Album album) {
|
||||
boolean exist = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.cappielloantonio.play.database.AppDatabase;
|
|||
import com.cappielloantonio.play.database.dao.ArtistDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -16,6 +17,8 @@ public class ArtistRepository {
|
|||
private ArtistDao artistDao;
|
||||
private LiveData<List<Artist>> listLiveArtists;
|
||||
private LiveData<List<Artist>> listLiveSampleArtist;
|
||||
private LiveData<List<Artist>> searchListLiveArtist;
|
||||
|
||||
|
||||
public ArtistRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
|
|
@ -32,6 +35,11 @@ public class ArtistRepository {
|
|||
return listLiveSampleArtist;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> searchListLiveArtist(String name) {
|
||||
searchListLiveArtist = artistDao.searchArtist(name);
|
||||
return searchListLiveArtist;
|
||||
}
|
||||
|
||||
public boolean exist(Artist artist) {
|
||||
boolean exist = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,11 @@ import java.util.List;
|
|||
|
||||
public class SongRepository {
|
||||
private SongDao songDao;
|
||||
private LiveData<List<Song>> listLiveSongs;
|
||||
private LiveData<List<Song>> searchListLiveSongs;
|
||||
private LiveData<List<Song>> listLiveSampleDiscoverSongs;
|
||||
private LiveData<List<Song>> listLiveSampleRecentlyAddedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleRecentlyPlayedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleMostPlayedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleArtistTopSongs;
|
||||
|
||||
|
||||
public SongRepository(Application application) {
|
||||
|
|
@ -32,11 +31,6 @@ public class SongRepository {
|
|||
return searchListLiveSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveDiscoverSampleSong() {
|
||||
listLiveSampleDiscoverSongs = songDao.getDiscoverSample(5);
|
||||
return listLiveSampleDiscoverSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getListLiveRecentlyAddedSampleSong() {
|
||||
listLiveSampleRecentlyAddedSongs = songDao.getRecentlyAddedSample(20);
|
||||
return listLiveSampleRecentlyAddedSongs;
|
||||
|
|
@ -52,6 +46,11 @@ public class SongRepository {
|
|||
return listLiveSampleMostPlayedSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getArtistListLiveTopSong(String artistID) {
|
||||
listLiveSampleArtistTopSongs = songDao.getArtistTopSongsSample(artistID, 5);
|
||||
return listLiveSampleArtistTopSongs;
|
||||
}
|
||||
|
||||
public boolean exist(Song song) {
|
||||
boolean exist = false;
|
||||
|
||||
|
|
@ -87,6 +86,31 @@ public class SongRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public void update(Song song) {
|
||||
song.nowPlaying();
|
||||
|
||||
UpdateThreadSafe update = new UpdateThreadSafe(songDao, song);
|
||||
Thread thread = new Thread(update);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public List<Song> getRandomSample(int number) {
|
||||
List<Song> sample = new ArrayList<>();
|
||||
|
||||
PickRandomThreadSafe randomThread = new PickRandomThreadSafe(songDao, number);
|
||||
Thread thread = new Thread(randomThread);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
sample = randomThread.getSample();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
private static class ExistThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private Song song;
|
||||
|
|
@ -151,4 +175,39 @@ public class SongRepository {
|
|||
songDao.delete(song);
|
||||
}
|
||||
}
|
||||
|
||||
private static class UpdateThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private Song song;
|
||||
|
||||
public UpdateThreadSafe(SongDao songDao, Song song) {
|
||||
this.songDao = songDao;
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
songDao.update(song);
|
||||
}
|
||||
}
|
||||
|
||||
private static class PickRandomThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private int elementNumber;
|
||||
private List<Song> sample;
|
||||
|
||||
public PickRandomThreadSafe(SongDao songDao, int number) {
|
||||
this.songDao = songDao;
|
||||
this.elementNumber = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sample = songDao.random(elementNumber);
|
||||
}
|
||||
|
||||
public List<Song> getSample() {
|
||||
return sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue