mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Adapters refactoring
This commit is contained in:
parent
18fae806a6
commit
ae23d268cd
34 changed files with 341 additions and 100 deletions
|
|
@ -24,6 +24,7 @@ public class SongRepository {
|
|||
private LiveData<List<Song>> listLiveAlbumSongs;
|
||||
private LiveData<List<Song>> listLiveSongByGenre;
|
||||
private LiveData<List<Song>> listLiveFilteredSongs;
|
||||
private LiveData<List<Song>> listLiveSongByYear;
|
||||
|
||||
|
||||
public SongRepository(Application application) {
|
||||
|
|
@ -115,6 +116,28 @@ public class SongRepository {
|
|||
return catalogue;
|
||||
}
|
||||
|
||||
public List<Integer> getYearList() {
|
||||
List<Integer> years = new ArrayList<>();
|
||||
|
||||
GetYearListThreadSafe getYearListThreadSafe = new GetYearListThreadSafe(songDao);
|
||||
Thread thread = new Thread(getYearListThreadSafe);
|
||||
thread.start();
|
||||
|
||||
try {
|
||||
thread.join();
|
||||
years = getYearListThreadSafe.getYearList();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return years;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getSongByYearListLive(int year) {
|
||||
listLiveSongByYear = songDao.getSongsByYear(year);
|
||||
return listLiveSongByYear;
|
||||
}
|
||||
|
||||
public boolean exist(Song song) {
|
||||
boolean exist = false;
|
||||
|
||||
|
|
@ -383,4 +406,33 @@ public class SongRepository {
|
|||
songGenreCrossDao.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetYearListThreadSafe implements Runnable {
|
||||
private SongDao songDao;
|
||||
private List<Integer> years = new ArrayList<>();
|
||||
private List<Integer> decades = new ArrayList<>();
|
||||
|
||||
public GetYearListThreadSafe(SongDao songDao) {
|
||||
this.songDao = songDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
years = songDao.getYearList();
|
||||
|
||||
for(int year : years) {
|
||||
if(!decades.contains(year - year % 10)) {
|
||||
decades.add(year);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getYearList() {
|
||||
return years;
|
||||
}
|
||||
|
||||
public List<Integer> getDecadeList() {
|
||||
return decades;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue