mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Fix initialization of mutableLiveData in repository
This commit is contained in:
parent
b8822fcda4
commit
8392d01fc5
7 changed files with 15 additions and 12 deletions
|
|
@ -31,7 +31,7 @@ public class ArtistRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getStarredArtists() {
|
||||
MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -54,7 +54,7 @@ public class ArtistRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getArtists(boolean random, int size) {
|
||||
MutableLiveData<List<Artist>> listLiveArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
MutableLiveData<List<Artist>> listLiveArtists = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -249,7 +249,7 @@ public class ArtistRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<ArrayList<Song>> getArtistRandomSong(FragmentActivity fragmentActivity, Artist artist, int count) {
|
||||
MutableLiveData<ArrayList<Song>> randomSongs = new MutableLiveData<>(new ArrayList());
|
||||
MutableLiveData<ArrayList<Song>> randomSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -266,6 +266,7 @@ public class ArtistRepository {
|
|||
for (int index = 0; index < albums.size(); index++) {
|
||||
albumRepository.getAlbumTracks(albums.get(index).getId()).observe(fragmentActivity, songs -> {
|
||||
ArrayList<Song> liveSongs = randomSongs.getValue();
|
||||
if(liveSongs == null) liveSongs = new ArrayList<>();
|
||||
Collections.shuffle(liveSongs);
|
||||
liveSongs.addAll(songs);
|
||||
randomSongs.setValue(liveSongs);
|
||||
|
|
@ -309,6 +310,7 @@ public class ArtistRepository {
|
|||
|
||||
private void addToMutableLiveData(MutableLiveData<List<Artist>> liveData, Artist artist) {
|
||||
List<Artist> liveArtists = liveData.getValue();
|
||||
if(liveArtists == null) liveArtists = new ArrayList<>();
|
||||
liveArtists.add(artist);
|
||||
liveData.setValue(liveArtists);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ public class DownloadRepository {
|
|||
private static final String TAG = "QueueRepository";
|
||||
|
||||
private DownloadDao downloadDao;
|
||||
private MutableLiveData<List<Download>> listLiveDownload = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
public DownloadRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class PlaylistRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Playlist>> getPlaylists(boolean random, int size) {
|
||||
MutableLiveData<List<Playlist>> listLivePlaylists = new MutableLiveData<>(new ArrayList<>());
|
||||
MutableLiveData<List<Playlist>> listLivePlaylists = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getPlaylistClient()
|
||||
|
|
@ -56,7 +56,7 @@ public class PlaylistRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getPlaylistSongs(String id) {
|
||||
MutableLiveData<List<Song>> listLivePlaylistSongs = new MutableLiveData<>(new ArrayList<>());
|
||||
MutableLiveData<List<Song>> listLivePlaylistSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getPlaylistClient()
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ public class SearchingRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<String>> getSuggestions(String query) {
|
||||
MutableLiveData<List<String>> suggestions = new MutableLiveData<>(new ArrayList());
|
||||
MutableLiveData<List<String>> suggestions = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getSearchingClient()
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getRandomSample(int number, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<Song>> randomSongsSample = new MutableLiveData<>(new ArrayList<>());
|
||||
MutableLiveData<List<Song>> randomSongsSample = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -180,7 +180,7 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getSongsByGenre(String id) {
|
||||
MutableLiveData<List<Song>> songsByGenre = new MutableLiveData<>(new ArrayList<>());
|
||||
MutableLiveData<List<Song>> songsByGenre = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -192,6 +192,7 @@ public class SongRepository {
|
|||
List<Song> newSongs = new ArrayList<>(MappingUtil.mapSong(response.body().getSongsByGenre().getSongs()));
|
||||
List<Song> songs = songsByGenre.getValue();
|
||||
|
||||
if(songs == null) songs = new ArrayList<>();
|
||||
songs.addAll(newSongs);
|
||||
Collections.shuffle(songs);
|
||||
|
||||
|
|
@ -212,10 +213,9 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getSongsByGenres(ArrayList<String> genresId) {
|
||||
MutableLiveData<List<Song>> songsByGenre = new MutableLiveData<>(new ArrayList<>());
|
||||
MutableLiveData<List<Song>> songsByGenre = new MutableLiveData<>();
|
||||
|
||||
for (String id : genresId)
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getSongsByGenre(id, 500, 0)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
|||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
List<Album> liveAlbum = albumList.getValue();
|
||||
if(liveAlbum == null) liveAlbum = new ArrayList<>();
|
||||
liveAlbum.addAll(MappingUtil.mapAlbum((List<AlbumID3>) media));
|
||||
albumList.setValue(liveAlbum);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue