mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
- Removed middle layer of abstraction for subsonic classes
- Used kotlin for classes
This commit is contained in:
parent
917c0839de
commit
ca15f51c85
168 changed files with 2026 additions and 6588 deletions
|
|
@ -8,10 +8,9 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.interfaces.DecadesCallback;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
|
@ -32,8 +31,8 @@ public class AlbumRepository {
|
|||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getAlbums(String type, int size, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<Album>> listLiveAlbums = new MutableLiveData<>();
|
||||
public MutableLiveData<List<AlbumID3>> getAlbums(String type, int size, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<AlbumID3>> listLiveAlbums = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -41,13 +40,9 @@ public class AlbumRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Album> albums = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getAlbumList2() != null) {
|
||||
albums.addAll(MappingUtil.mapAlbum(response.body().getAlbumList2().getAlbums()));
|
||||
listLiveAlbums.setValue(response.body().getAlbumList2().getAlbums());
|
||||
}
|
||||
|
||||
listLiveAlbums.setValue(albums);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -59,8 +54,8 @@ public class AlbumRepository {
|
|||
return listLiveAlbums;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getStarredAlbums(boolean random, int size) {
|
||||
MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>();
|
||||
public MutableLiveData<List<AlbumID3>> getStarredAlbums(boolean random, int size) {
|
||||
MutableLiveData<List<AlbumID3>> starredAlbums = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -69,13 +64,13 @@ public class AlbumRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getStarred2() != null) {
|
||||
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getStarred2().getAlbums()));
|
||||
List<AlbumID3> albums = response.body().getStarred2().getAlbums();
|
||||
|
||||
if (!random) {
|
||||
starredAlbums.setValue(albums);
|
||||
} else {
|
||||
if (random) {
|
||||
Collections.shuffle(albums);
|
||||
starredAlbums.setValue(albums.subList(0, Math.min(size, albums.size())));
|
||||
} else {
|
||||
starredAlbums.setValue(albums);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -140,8 +135,8 @@ public class AlbumRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getAlbumTracks(String id) {
|
||||
MutableLiveData<List<Media>> albumTracks = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getAlbumTracks(String id) {
|
||||
MutableLiveData<List<Child>> albumTracks = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -149,10 +144,10 @@ public class AlbumRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Media> tracks = new ArrayList<>();
|
||||
List<Child> tracks = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getAlbum() != null) {
|
||||
tracks.addAll(MappingUtil.mapSong(response.body().getAlbum().getSongs()));
|
||||
tracks.addAll(response.body().getAlbum().getSongs());
|
||||
}
|
||||
|
||||
albumTracks.setValue(tracks);
|
||||
|
|
@ -167,8 +162,8 @@ public class AlbumRepository {
|
|||
return albumTracks;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getArtistAlbums(String id) {
|
||||
MutableLiveData<List<Album>> artistsAlbum = new MutableLiveData<>();
|
||||
public MutableLiveData<List<AlbumID3>> getArtistAlbums(String id) {
|
||||
MutableLiveData<List<AlbumID3>> artistsAlbum = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -176,14 +171,11 @@ public class AlbumRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Album> albums = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getArtist() != null) {
|
||||
albums.addAll(MappingUtil.mapAlbum(response.body().getArtist().getAlbums()));
|
||||
albums.sort(Comparator.comparing(Album::getYear));
|
||||
List<AlbumID3> albums = response.body().getArtist().getAlbums();
|
||||
albums.sort(Comparator.comparing(AlbumID3::getYear));
|
||||
artistsAlbum.setValue(albums);
|
||||
}
|
||||
|
||||
artistsAlbum.setValue(albums);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -195,8 +187,8 @@ public class AlbumRepository {
|
|||
return artistsAlbum;
|
||||
}
|
||||
|
||||
public MutableLiveData<Album> getAlbum(String id) {
|
||||
MutableLiveData<Album> album = new MutableLiveData<>();
|
||||
public MutableLiveData<AlbumID3> getAlbum(String id) {
|
||||
MutableLiveData<AlbumID3> album = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -205,7 +197,7 @@ public class AlbumRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getAlbum() != null) {
|
||||
album.setValue(MappingUtil.mapAlbum(response.body().getAlbum()));
|
||||
album.setValue(response.body().getAlbum());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,17 +210,17 @@ public class AlbumRepository {
|
|||
return album;
|
||||
}
|
||||
|
||||
public void getInstantMix(Album album, int count, MediaCallback callback) {
|
||||
public void getInstantMix(AlbumID3 album, int count, MediaCallback callback) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getSimilarSongs2(album.getId(), count)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Media> songs = new ArrayList<>();
|
||||
List<Child> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSimilarSongs2() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
songs.addAll(response.body().getSimilarSongs2().getSongs());
|
||||
}
|
||||
|
||||
callback.onLoadMedia(songs);
|
||||
|
|
|
|||
|
|
@ -3,18 +3,16 @@ package com.cappielloantonio.play.repository;
|
|||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistInfo2;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
import com.cappielloantonio.play.subsonic.models.IndexID3;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -31,8 +29,8 @@ public class ArtistRepository {
|
|||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getStarredArtists(boolean random, int size) {
|
||||
MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>();
|
||||
public MutableLiveData<List<ArtistID3>> getStarredArtists(boolean random, int size) {
|
||||
MutableLiveData<List<ArtistID3>> starredArtists = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -41,7 +39,7 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getStarred2() != null) {
|
||||
List<Artist> artists = new ArrayList<>(MappingUtil.mapArtist(response.body().getStarred2().getArtists()));
|
||||
List<ArtistID3> artists = response.body().getStarred2().getArtists();
|
||||
|
||||
if (!random) {
|
||||
getArtistInfo(artists, starredArtists);
|
||||
|
|
@ -61,8 +59,8 @@ public class ArtistRepository {
|
|||
return starredArtists;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getArtists(boolean random, int size) {
|
||||
MutableLiveData<List<Artist>> listLiveArtists = new MutableLiveData<>();
|
||||
public MutableLiveData<List<ArtistID3>> getArtists(boolean random, int size) {
|
||||
MutableLiveData<List<ArtistID3>> listLiveArtists = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -71,10 +69,10 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
List<ArtistID3> artists = new ArrayList<>();
|
||||
|
||||
for (IndexID3 index : response.body().getArtists().getIndices()) {
|
||||
artists.addAll(MappingUtil.mapArtist(index.getArtists()));
|
||||
artists.addAll(index.getArtists());
|
||||
}
|
||||
|
||||
if (random) {
|
||||
|
|
@ -97,12 +95,12 @@ public class ArtistRepository {
|
|||
/*
|
||||
* Metodo che mi restituisce le informazioni essenzionali dell'artista (cover, numero di album...)
|
||||
*/
|
||||
public void getArtistInfo(List<Artist> artists, MutableLiveData<List<Artist>> list) {
|
||||
List<Artist> liveArtists = list.getValue();
|
||||
public void getArtistInfo(List<ArtistID3> artists, MutableLiveData<List<ArtistID3>> list) {
|
||||
List<ArtistID3> liveArtists = list.getValue();
|
||||
if (liveArtists == null) liveArtists = new ArrayList<>();
|
||||
list.setValue(liveArtists);
|
||||
|
||||
for (Artist artist : artists) {
|
||||
for (ArtistID3 artist : artists) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getArtist(artist.getId())
|
||||
|
|
@ -110,7 +108,7 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getArtist() != null) {
|
||||
addToMutableLiveData(list, MappingUtil.mapArtistWithAlbum(response.body().getArtist()));
|
||||
addToMutableLiveData(list, response.body().getArtist());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,8 +120,8 @@ public class ArtistRepository {
|
|||
}
|
||||
}
|
||||
|
||||
public MutableLiveData<Artist> getArtistInfo(String id) {
|
||||
MutableLiveData<Artist> artist = new MutableLiveData<>();
|
||||
public MutableLiveData<ArtistID3> getArtistInfo(String id) {
|
||||
MutableLiveData<ArtistID3> artist = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -132,7 +130,7 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getArtist() != null) {
|
||||
artist.setValue(MappingUtil.mapArtistWithAlbum(response.body().getArtist()));
|
||||
artist.setValue(response.body().getArtist());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -148,8 +146,8 @@ public class ArtistRepository {
|
|||
/*
|
||||
* Metodo che mi restituisce le informazioni complete dell'artista (bio, immagini prese da last.fm, artisti simili...)
|
||||
*/
|
||||
public MutableLiveData<Artist> getArtistFullInfo(String id) {
|
||||
MutableLiveData<Artist> artistFullInfo = new MutableLiveData<>();
|
||||
public MutableLiveData<ArtistInfo2> getArtistFullInfo(String id) {
|
||||
MutableLiveData<ArtistInfo2> artistFullInfo = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -158,7 +156,7 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getArtistInfo2() != null) {
|
||||
artistFullInfo.setValue(MappingUtil.mapArtist(response.body().getArtistInfo2()));
|
||||
artistFullInfo.setValue(response.body().getArtistInfo2());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -222,8 +220,8 @@ public class ArtistRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<Artist> getArtist(String id) {
|
||||
MutableLiveData<Artist> artist = new MutableLiveData<>();
|
||||
public MutableLiveData<ArtistID3> getArtist(String id) {
|
||||
MutableLiveData<ArtistID3> artist = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -232,7 +230,7 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getArtist() != null) {
|
||||
artist.setValue(MappingUtil.mapArtist(response.body().getArtist()));
|
||||
artist.setValue(response.body().getArtist());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -245,8 +243,8 @@ public class ArtistRepository {
|
|||
return artist;
|
||||
}
|
||||
|
||||
public MutableLiveData<ArrayList<Media>> getInstantMix(Artist artist, int count) {
|
||||
MutableLiveData<ArrayList<Media>> instantMix = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getInstantMix(ArtistID3 artist, int count) {
|
||||
MutableLiveData<List<Child>> instantMix = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -255,7 +253,7 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSimilarSongs2() != null) {
|
||||
instantMix.setValue(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
instantMix.setValue(response.body().getSimilarSongs2().getSongs());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -268,8 +266,8 @@ public class ArtistRepository {
|
|||
return instantMix;
|
||||
}
|
||||
|
||||
public MutableLiveData<ArrayList<Media>> getArtistRandomSong(LifecycleOwner owner, Artist artist, int count) {
|
||||
MutableLiveData<ArrayList<Media>> randomSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<ArrayList<Child>> getArtistRandomSong(LifecycleOwner owner, ArtistID3 artist, int count) {
|
||||
MutableLiveData<ArrayList<Child>> randomSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -278,14 +276,14 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getArtist() != null && response.body().getArtist().getAlbums() != null) {
|
||||
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getArtist().getAlbums()));
|
||||
List<AlbumID3> albums = response.body().getArtist().getAlbums();
|
||||
|
||||
if (albums.size() > 0) {
|
||||
AlbumRepository albumRepository = new AlbumRepository(App.getInstance());
|
||||
|
||||
for (int index = 0; index < albums.size(); index++) {
|
||||
albumRepository.getAlbumTracks(albums.get(index).getId()).observe(owner, songs -> {
|
||||
ArrayList<Media> liveSongs = randomSongs.getValue();
|
||||
ArrayList<Child> liveSongs = randomSongs.getValue();
|
||||
if (liveSongs == null) liveSongs = new ArrayList<>();
|
||||
Collections.shuffle(liveSongs);
|
||||
liveSongs.addAll(songs);
|
||||
|
|
@ -305,8 +303,8 @@ public class ArtistRepository {
|
|||
return randomSongs;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getTopSongs(String artistName, int count) {
|
||||
MutableLiveData<List<Media>> topSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getTopSongs(String artistName, int count) {
|
||||
MutableLiveData<List<Child>> topSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -315,7 +313,7 @@ public class ArtistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getTopSongs() != null) {
|
||||
topSongs.setValue(MappingUtil.mapSong(response.body().getTopSongs().getSongs()));
|
||||
topSongs.setValue(response.body().getTopSongs().getSongs());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,8 +326,8 @@ public class ArtistRepository {
|
|||
return topSongs;
|
||||
}
|
||||
|
||||
private void addToMutableLiveData(MutableLiveData<List<Artist>> liveData, Artist artist) {
|
||||
List<Artist> liveArtists = liveData.getValue();
|
||||
private void addToMutableLiveData(MutableLiveData<List<ArtistID3>> liveData, ArtistID3 artist) {
|
||||
List<ArtistID3> liveArtists = liveData.getValue();
|
||||
if (liveArtists != null) liveArtists.add(artist);
|
||||
liveData.setValue(liveArtists);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,14 @@ import android.app.Application;
|
|||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.DownloadDao;
|
||||
import com.cappielloantonio.play.model.Download;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
import com.cappielloantonio.play.util.Preferences;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadRepository {
|
||||
private static final String TAG = "QueueRepository";
|
||||
|
||||
private final DownloadDao downloadDao;
|
||||
|
||||
public DownloadRepository(Application application) {
|
||||
|
|
@ -23,31 +20,31 @@ public class DownloadRepository {
|
|||
}
|
||||
|
||||
public LiveData<List<Download>> getLiveDownload() {
|
||||
return downloadDao.getAll(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
return downloadDao.getAll(Preferences.getServerId());
|
||||
}
|
||||
|
||||
public LiveData<List<Download>> getLiveDownloadSample(int size, boolean isArtist, boolean isAlbum, boolean isTrack, boolean isPlaylist) {
|
||||
if (isArtist) return downloadDao.getSampleArtist(size, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
else if (isAlbum) return downloadDao.getSampleAlbum(size, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
else if (isTrack) return downloadDao.getSample(size, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
else if (isPlaylist) return downloadDao.getSamplePlaylist(size, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
else return downloadDao.getSample(size, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
if (isArtist) return downloadDao.getSampleArtist(size, Preferences.getServerId());
|
||||
else if (isAlbum) return downloadDao.getSampleAlbum(size, Preferences.getServerId());
|
||||
else if (isTrack) return downloadDao.getSample(size, Preferences.getServerId());
|
||||
else if (isPlaylist) return downloadDao.getSamplePlaylist(size, Preferences.getServerId());
|
||||
else return downloadDao.getSample(size, Preferences.getServerId());
|
||||
}
|
||||
|
||||
public LiveData<List<Download>> getLiveDownloadFromArtist(String artistId) {
|
||||
return downloadDao.getAllFromArtist(PreferenceUtil.getInstance(App.getInstance()).getServerId(), artistId);
|
||||
return downloadDao.getAllFromArtist(Preferences.getServerId(), artistId);
|
||||
}
|
||||
|
||||
public LiveData<List<Download>> getLiveDownloadFromAlbum(String albumId) {
|
||||
return downloadDao.getAllFromAlbum(PreferenceUtil.getInstance(App.getInstance()).getServerId(), albumId);
|
||||
return downloadDao.getAllFromAlbum(Preferences.getServerId(), albumId);
|
||||
}
|
||||
|
||||
public LiveData<List<Download>> getLiveDownloadFromPlaylist(String playlistId) {
|
||||
return downloadDao.getAllFromPlaylist(PreferenceUtil.getInstance(App.getInstance()).getServerId(), playlistId);
|
||||
return downloadDao.getAllFromPlaylist(Preferences.getServerId(), playlistId);
|
||||
}
|
||||
|
||||
public LiveData<List<Download>> getLivePlaylist() {
|
||||
return downloadDao.getAllPlaylists(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
return downloadDao.getAllPlaylists(Preferences.getServerId());
|
||||
}
|
||||
|
||||
public void insert(Download download) {
|
||||
|
|
@ -107,7 +104,7 @@ public class DownloadRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
downloadDao.deleteAll(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
downloadDao.deleteAll(Preferences.getServerId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@ import androidx.annotation.NonNull;
|
|||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.subsonic.models.Genre;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -37,7 +35,7 @@ public class GenreRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getGenres() != null) {
|
||||
List<Genre> genreList = new ArrayList<>(MappingUtil.mapGenre(response.body().getGenres().getGenres()));
|
||||
List<Genre> genreList = response.body().getGenres().getGenres();
|
||||
|
||||
if (random) {
|
||||
Collections.shuffle(genreList);
|
||||
|
|
|
|||
|
|
@ -10,10 +10,9 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.PlaylistDao;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
import com.cappielloantonio.play.subsonic.models.Playlist;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -44,7 +43,8 @@ public class PlaylistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getPlaylists() != null) {
|
||||
List<Playlist> playlists = new ArrayList<>(MappingUtil.mapPlaylist(response.body().getPlaylists().getPlaylists()));
|
||||
List<Playlist> playlists = response.body().getPlaylists().getPlaylists();
|
||||
|
||||
if (random) {
|
||||
Collections.shuffle(playlists);
|
||||
listLivePlaylists.setValue(playlists.subList(0, Math.min(playlists.size(), size)));
|
||||
|
|
@ -62,8 +62,8 @@ public class PlaylistRepository {
|
|||
return listLivePlaylists;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getPlaylistSongs(String id) {
|
||||
MutableLiveData<List<Media>> listLivePlaylistSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getPlaylistSongs(String id) {
|
||||
MutableLiveData<List<Child>> listLivePlaylistSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getPlaylistClient()
|
||||
|
|
@ -72,7 +72,7 @@ public class PlaylistRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getPlaylist() != null) {
|
||||
List<Media> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getPlaylist().getEntries()));
|
||||
List<Child> songs = response.body().getPlaylist().getEntries();
|
||||
listLivePlaylistSongs.setValue(songs);
|
||||
}
|
||||
}
|
||||
|
|
@ -154,7 +154,8 @@ public class PlaylistRepository {
|
|||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPinnedPlaylists(String serverId) {
|
||||
return playlistDao.getAll(serverId);
|
||||
// return playlistDao.getAll(serverId);
|
||||
return playlistDao.getAll();
|
||||
}
|
||||
|
||||
public void insert(Playlist playlist) {
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@ import androidx.annotation.NonNull;
|
|||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.model.PodcastChannel;
|
||||
import com.cappielloantonio.play.subsonic.models.PodcastChannel;
|
||||
import com.cappielloantonio.play.subsonic.models.PodcastEpisode;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ public class PodcastRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getPodcasts() != null) {
|
||||
livePodcastChannel.setValue(MappingUtil.mapPodcastChannel(response.body().getPodcasts().getChannels()));
|
||||
livePodcastChannel.setValue(response.body().getPodcasts().getChannels());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,8 +49,8 @@ public class PodcastRepository {
|
|||
return livePodcastChannel;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getNewestPodcastEpisodes(int count) {
|
||||
MutableLiveData<List<Media>> liveNewestPodcastEpisodes = new MutableLiveData<>();
|
||||
public MutableLiveData<List<PodcastEpisode>> getNewestPodcastEpisodes(int count) {
|
||||
MutableLiveData<List<PodcastEpisode>> liveNewestPodcastEpisodes = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getPodcastClient()
|
||||
|
|
@ -60,7 +59,7 @@ public class PodcastRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getNewestPodcasts() != null) {
|
||||
liveNewestPodcastEpisodes.setValue(MappingUtil.mapPodcastEpisode(response.body().getNewestPodcasts().getEpisodes()));
|
||||
liveNewestPodcastEpisodes.setValue(response.body().getNewestPodcasts().getEpisodes());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.media3.common.MediaItem;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.QueueDao;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class QueueRepository {
|
||||
private static final String TAG = "QueueRepository";
|
||||
|
|
@ -30,8 +29,8 @@ public class QueueRepository {
|
|||
return queueDao.getAll();
|
||||
}
|
||||
|
||||
public List<Media> getMedia() {
|
||||
List<Media> media = new ArrayList<>();
|
||||
public List<Child> getMedia() {
|
||||
List<Child> media = new ArrayList<>();
|
||||
|
||||
GetMediaThreadSafe getMedia = new GetMediaThreadSafe(queueDao);
|
||||
Thread thread = new Thread(getMedia);
|
||||
|
|
@ -39,7 +38,10 @@ public class QueueRepository {
|
|||
|
||||
try {
|
||||
thread.join();
|
||||
media = getMedia.getMedia();
|
||||
media = getMedia.getMedia().stream()
|
||||
.map(Child.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -47,9 +49,9 @@ public class QueueRepository {
|
|||
return media;
|
||||
}
|
||||
|
||||
public void insert(Media media, boolean reset, int afterIndex) {
|
||||
public void insert(Child media, boolean reset, int afterIndex) {
|
||||
try {
|
||||
List<Media> mediaList = new ArrayList<>();
|
||||
List<Queue> mediaList = new ArrayList<>();
|
||||
|
||||
if (!reset) {
|
||||
GetMediaThreadSafe getMediaThreadSafe = new GetMediaThreadSafe(queueDao);
|
||||
|
|
@ -60,7 +62,7 @@ public class QueueRepository {
|
|||
mediaList = getMediaThreadSafe.getMedia();
|
||||
}
|
||||
|
||||
mediaList.add(afterIndex, media);
|
||||
mediaList.add(afterIndex, (Queue) media);
|
||||
|
||||
Thread delete = new Thread(new DeleteAllThreadSafe(queueDao));
|
||||
delete.start();
|
||||
|
|
@ -74,9 +76,9 @@ public class QueueRepository {
|
|||
}
|
||||
}
|
||||
|
||||
public void insertAll(List<Media> toAdd, boolean reset, int afterIndex) {
|
||||
public void insertAll(List<Child> toAdd, boolean reset, int afterIndex) {
|
||||
try {
|
||||
List<Media> media = new ArrayList<>();
|
||||
List<Queue> media = new ArrayList<>();
|
||||
|
||||
if (!reset) {
|
||||
GetMediaThreadSafe getMediaThreadSafe = new GetMediaThreadSafe(queueDao);
|
||||
|
|
@ -87,7 +89,9 @@ public class QueueRepository {
|
|||
media = getMediaThreadSafe.getMedia();
|
||||
}
|
||||
|
||||
media.addAll(afterIndex, toAdd);
|
||||
for (int i = 0; i < toAdd.size(); i++) {
|
||||
media.add(afterIndex + i, (Queue) toAdd.get(i));
|
||||
}
|
||||
|
||||
Thread delete = new Thread(new DeleteAllThreadSafe(queueDao));
|
||||
delete.start();
|
||||
|
|
@ -206,7 +210,7 @@ public class QueueRepository {
|
|||
|
||||
private static class GetMediaThreadSafe implements Runnable {
|
||||
private final QueueDao queueDao;
|
||||
private List<Media> media;
|
||||
private List<Queue> media;
|
||||
|
||||
public GetMediaThreadSafe(QueueDao queueDao) {
|
||||
this.queueDao = queueDao;
|
||||
|
|
@ -214,26 +218,26 @@ public class QueueRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
media = MappingUtil.mapQueue(queueDao.getAllSimple());
|
||||
media = queueDao.getAllSimple();
|
||||
}
|
||||
|
||||
public List<Media> getMedia() {
|
||||
public List<Queue> getMedia() {
|
||||
return media;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private final QueueDao queueDao;
|
||||
private final List<Media> media;
|
||||
private final List<Queue> media;
|
||||
|
||||
public InsertAllThreadSafe(QueueDao queueDao, List<Media> media) {
|
||||
public InsertAllThreadSafe(QueueDao queueDao, List<Queue> media) {
|
||||
this.queueDao = queueDao;
|
||||
this.media = media;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
queueDao.insertAll(MappingUtil.mapMediaToQueue(media));
|
||||
queueDao.insertAll(media);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,15 +8,12 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.RecentSearchDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.RecentSearch;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
import com.cappielloantonio.play.subsonic.models.SearchResult3;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
|
|
@ -37,8 +34,8 @@ public class SearchingRepository {
|
|||
recentSearchDao = database.recentSearchDao();
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getSearchedSongs(String query) {
|
||||
MutableLiveData<List<Media>> searchedSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<SearchResult3> search(String query) {
|
||||
MutableLiveData<SearchResult3> result = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getSearchingClient()
|
||||
|
|
@ -46,13 +43,7 @@ public class SearchingRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSearchResult3() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getSearchResult3().getSongs()));
|
||||
}
|
||||
|
||||
searchedSongs.setValue(songs);
|
||||
result.setValue(response.body().getSearchResult3());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -61,61 +52,7 @@ public class SearchingRepository {
|
|||
}
|
||||
});
|
||||
|
||||
return searchedSongs;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getSearchedAlbums(String query) {
|
||||
MutableLiveData<List<Album>> searchedAlbums = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getSearchingClient()
|
||||
.search3(query, 0, 20, 0)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Album> albums = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSearchResult3() != null) {
|
||||
albums.addAll(MappingUtil.mapAlbum(response.body().getSearchResult3().getAlbums()));
|
||||
}
|
||||
|
||||
searchedAlbums.setValue(albums);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return searchedAlbums;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getSearchedArtists(String query) {
|
||||
MutableLiveData<List<Artist>> searchedArtists = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getSearchingClient()
|
||||
.search3(query, 0, 0, 20)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSearchResult3() != null) {
|
||||
artists.addAll(MappingUtil.mapArtist(response.body().getSearchResult3().getArtists()));
|
||||
}
|
||||
|
||||
searchedArtists.setValue(artists);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return searchedArtists;
|
||||
return result;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<String>> getSuggestions(String query) {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,8 @@ import androidx.annotation.NonNull;
|
|||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -29,8 +27,8 @@ public class SongRepository {
|
|||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getStarredSongs(boolean random, int size) {
|
||||
MutableLiveData<List<Media>> starredSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getStarredSongs(boolean random, int size) {
|
||||
MutableLiveData<List<Child>> starredSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -39,7 +37,7 @@ public class SongRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getStarred2() != null) {
|
||||
List<Media> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getStarred2().getSongs()));
|
||||
List<Child> songs = response.body().getStarred2().getSongs();
|
||||
|
||||
if (!random) {
|
||||
starredSongs.setValue(songs);
|
||||
|
|
@ -59,8 +57,8 @@ public class SongRepository {
|
|||
return starredSongs;
|
||||
}
|
||||
|
||||
public MutableLiveData<ArrayList<Media>> getInstantMix(Media song, int count) {
|
||||
MutableLiveData<ArrayList<Media>> instantMix = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getInstantMix(Child song, int count) {
|
||||
MutableLiveData<List<Child>> instantMix = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -69,7 +67,7 @@ public class SongRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSimilarSongs2() != null) {
|
||||
instantMix.setValue(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
instantMix.setValue(response.body().getSimilarSongs2().getSongs());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,8 +80,8 @@ public class SongRepository {
|
|||
return instantMix;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getRandomSample(int number, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<Media>> randomSongsSample = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getRandomSample(int number, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<Child>> randomSongsSample = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -91,10 +89,10 @@ public class SongRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Media> songs = new ArrayList<>();
|
||||
List<Child> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getRandomSongs() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getRandomSongs().getSongs()));
|
||||
songs.addAll(response.body().getRandomSongs().getSongs());
|
||||
}
|
||||
|
||||
randomSongsSample.setValue(songs);
|
||||
|
|
@ -177,8 +175,8 @@ public class SongRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getSongsByGenre(String id) {
|
||||
MutableLiveData<List<Media>> songsByGenre = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getSongsByGenre(String id) {
|
||||
MutableLiveData<List<Child>> songsByGenre = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -187,15 +185,15 @@ public class SongRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSongsByGenre() != null) {
|
||||
List<Media> newSongs = new ArrayList<>(MappingUtil.mapSong(response.body().getSongsByGenre().getSongs()));
|
||||
List<Media> songs = songsByGenre.getValue();
|
||||
List<Child> newSongs = response.body().getSongsByGenre().getSongs();
|
||||
List<Child> songs = songsByGenre.getValue();
|
||||
|
||||
if (songs == null) songs = new ArrayList<>();
|
||||
songs.addAll(newSongs);
|
||||
Collections.shuffle(songs);
|
||||
|
||||
LinkedHashSet<Media> hashSet = new LinkedHashSet<>(songs);
|
||||
ArrayList<Media> songsWithoutDuplicates = new ArrayList<>(hashSet);
|
||||
LinkedHashSet<Child> hashSet = new LinkedHashSet<>(songs);
|
||||
ArrayList<Child> songsWithoutDuplicates = new ArrayList<>(hashSet);
|
||||
|
||||
songsByGenre.setValue(songsWithoutDuplicates);
|
||||
}
|
||||
|
|
@ -210,8 +208,8 @@ public class SongRepository {
|
|||
return songsByGenre;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Media>> getSongsByGenres(ArrayList<String> genresId) {
|
||||
MutableLiveData<List<Media>> songsByGenre = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Child>> getSongsByGenres(ArrayList<String> genresId) {
|
||||
MutableLiveData<List<Child>> songsByGenre = new MutableLiveData<>();
|
||||
|
||||
for (String id : genresId)
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
|
|
@ -220,10 +218,10 @@ public class SongRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Media> songs = new ArrayList<>();
|
||||
List<Child> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSongsByGenre() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getSongsByGenre().getSongs()));
|
||||
songs.addAll(response.body().getSongsByGenre().getSongs());
|
||||
}
|
||||
|
||||
songsByGenre.setValue(songs);
|
||||
|
|
@ -238,8 +236,8 @@ public class SongRepository {
|
|||
return songsByGenre;
|
||||
}
|
||||
|
||||
public MutableLiveData<Media> getSong(String id) {
|
||||
MutableLiveData<Media> song = new MutableLiveData<>();
|
||||
public MutableLiveData<Child> getSong(String id) {
|
||||
MutableLiveData<Child> song = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -248,7 +246,7 @@ public class SongRepository {
|
|||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
song.setValue(MappingUtil.mapSong(response.body().getSong()));
|
||||
song.setValue(response.body().getSong());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -261,12 +259,12 @@ public class SongRepository {
|
|||
return song;
|
||||
}
|
||||
|
||||
public MutableLiveData<String> getSongLyrics(Media song) {
|
||||
public MutableLiveData<String> getSongLyrics(Child song) {
|
||||
MutableLiveData<String> lyrics = new MutableLiveData<>(null);
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getMediaRetrievalClient()
|
||||
.getLyrics(song.getArtistName(), song.getTitle())
|
||||
.getLyrics(song.getArtist(), song.getTitle())
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue