Fix initialization of mutableLiveData in repository

This commit is contained in:
CappielloAntonio 2021-08-19 12:25:04 +02:00
parent b8822fcda4
commit 8392d01fc5
7 changed files with 15 additions and 12 deletions

3
.idea/misc.xml generated
View file

@ -8,6 +8,7 @@
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.2814814814814815" />
<entry key="app/src/main/res/drawable-v24/ic_shuffle.xml" value="0.28055555555555556" />
<entry key="app/src/main/res/drawable/dialog_shape.xml" value="0.27685185185185185" />
<entry key="app/src/main/res/drawable/ic_arrow_back.xml" value="0.28055555555555556" />
<entry key="app/src/main/res/drawable/ic_close.xml" value="0.27685185185185185" />
<entry key="app/src/main/res/drawable/ic_done.xml" value="0.28055555555555556" />
<entry key="app/src/main/res/drawable/ic_download_for_offline.xml" value="0.27685185185185185" />
@ -40,7 +41,7 @@
<entry key="app/src/main/res/layout/item_home_discovery_placeholder.xml" value="0.3229166666666667" />
<entry key="app/src/main/res/layout/item_home_horizontal_placeholder.xml" value="0.3229166666666667" />
<entry key="app/src/main/res/layout/item_home_placeholder.xml" value="0.47191011235955055" />
<entry key="app/src/main/res/layout/item_home_similar_track.xml" value="0.3229166666666667" />
<entry key="app/src/main/res/layout/item_home_similar_track.xml" value="0.7617554858934169" />
<entry key="app/src/main/res/layout/item_home_track.xml" value="0.3229166666666667" />
<entry key="app/src/main/res/layout/item_home_year.xml" value="0.3229166666666667" />
<entry key="app/src/main/res/layout/item_home_year_placeholder.xml" value="0.3229166666666667" />

View file

@ -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);
}

View file

@ -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);

View file

@ -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()

View file

@ -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()

View file

@ -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)

View file

@ -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);