mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Refactor Song to Media
This commit is contained in:
parent
62f2723014
commit
d1d341ff9b
43 changed files with 242 additions and 274 deletions
|
|
@ -9,7 +9,7 @@ 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.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
|
|
@ -140,8 +140,8 @@ public class AlbumRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getAlbumTracks(String id) {
|
||||
MutableLiveData<List<Song>> albumTracks = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getAlbumTracks(String id) {
|
||||
MutableLiveData<List<Media>> albumTracks = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -149,7 +149,7 @@ public class AlbumRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Song> tracks = new ArrayList<>();
|
||||
List<Media> tracks = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getAlbum() != null) {
|
||||
tracks.addAll(MappingUtil.mapSong(response.body().getAlbum().getSongs()));
|
||||
|
|
@ -248,7 +248,7 @@ public class AlbumRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSimilarSongs2() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ 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.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.IndexID3;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
|
@ -251,7 +251,7 @@ public class ArtistRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSimilarSongs2() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
|
|
@ -267,8 +267,8 @@ public class ArtistRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<ArrayList<Song>> getArtistRandomSong(FragmentActivity fragmentActivity, Artist artist, int count) {
|
||||
MutableLiveData<ArrayList<Song>> randomSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<ArrayList<Media>> getArtistRandomSong(FragmentActivity fragmentActivity, Artist artist, int count) {
|
||||
MutableLiveData<ArrayList<Media>> randomSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -284,7 +284,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();
|
||||
ArrayList<Media> liveSongs = randomSongs.getValue();
|
||||
if (liveSongs == null) liveSongs = new ArrayList<>();
|
||||
Collections.shuffle(liveSongs);
|
||||
liveSongs.addAll(songs);
|
||||
|
|
@ -304,8 +304,8 @@ public class ArtistRepository {
|
|||
return randomSongs;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getTopSongs(String artistName, int count) {
|
||||
MutableLiveData<List<Song>> topSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getTopSongs(String artistName, int count) {
|
||||
MutableLiveData<List<Media>> topSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
|
|||
|
|
@ -9,10 +9,8 @@ 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.database.dao.ServerDao;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Server;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
|
|
@ -63,8 +61,8 @@ public class PlaylistRepository {
|
|||
return listLivePlaylists;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getPlaylistSongs(String id) {
|
||||
MutableLiveData<List<Song>> listLivePlaylistSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getPlaylistSongs(String id) {
|
||||
MutableLiveData<List<Media>> listLivePlaylistSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getPlaylistClient()
|
||||
|
|
@ -73,7 +71,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<Song> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getPlaylist().getEntries()));
|
||||
List<Media> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getPlaylist().getEntries()));
|
||||
listLivePlaylistSongs.setValue(songs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import androidx.lifecycle.LiveData;
|
|||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.QueueDao;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.time.Instant;
|
||||
|
|
@ -28,8 +28,8 @@ public class QueueRepository {
|
|||
return queueDao.getAll();
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
public List<Media> getSongs() {
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
GetSongsThreadSafe getSongs = new GetSongsThreadSafe(queueDao);
|
||||
Thread thread = new Thread(getSongs);
|
||||
|
|
@ -45,9 +45,9 @@ public class QueueRepository {
|
|||
return songs;
|
||||
}
|
||||
|
||||
public void insert(Song song, boolean reset, int afterIndex) {
|
||||
public void insert(Media song, boolean reset, int afterIndex) {
|
||||
try {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (!reset) {
|
||||
GetSongsThreadSafe getSongsThreadSafe = new GetSongsThreadSafe(queueDao);
|
||||
|
|
@ -72,9 +72,9 @@ public class QueueRepository {
|
|||
}
|
||||
}
|
||||
|
||||
public void insertAll(List<Song> toAdd, boolean reset, int afterIndex) {
|
||||
public void insertAll(List<Media> toAdd, boolean reset, int afterIndex) {
|
||||
try {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (!reset) {
|
||||
GetSongsThreadSafe getSongsThreadSafe = new GetSongsThreadSafe(queueDao);
|
||||
|
|
@ -176,7 +176,7 @@ public class QueueRepository {
|
|||
|
||||
private static class GetSongsThreadSafe implements Runnable {
|
||||
private final QueueDao queueDao;
|
||||
private List<Song> songs;
|
||||
private List<Media> songs;
|
||||
|
||||
public GetSongsThreadSafe(QueueDao queueDao) {
|
||||
this.queueDao = queueDao;
|
||||
|
|
@ -187,16 +187,16 @@ public class QueueRepository {
|
|||
songs = MappingUtil.mapQueue(queueDao.getAllSimple());
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
public List<Media> getSongs() {
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InsertAllThreadSafe implements Runnable {
|
||||
private final QueueDao queueDao;
|
||||
private final List<Song> songs;
|
||||
private final List<Media> songs;
|
||||
|
||||
public InsertAllThreadSafe(QueueDao queueDao, List<Song> songs) {
|
||||
public InsertAllThreadSafe(QueueDao queueDao, List<Media> songs) {
|
||||
this.queueDao = queueDao;
|
||||
this.songs = songs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ 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.Song;
|
||||
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;
|
||||
|
|
@ -37,8 +37,8 @@ public class SearchingRepository {
|
|||
recentSearchDao = database.recentSearchDao();
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getSearchedSongs(String query) {
|
||||
MutableLiveData<List<Song>> searchedSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getSearchedSongs(String query) {
|
||||
MutableLiveData<List<Media>> searchedSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getSearchingClient()
|
||||
|
|
@ -46,7 +46,7 @@ public class SearchingRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSearchResult3() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getSearchResult3().getSongs()));
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
|
|
@ -29,8 +29,8 @@ public class SongRepository {
|
|||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getStarredSongs(boolean random, int size) {
|
||||
MutableLiveData<List<Song>> starredSongs = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getStarredSongs(boolean random, int size) {
|
||||
MutableLiveData<List<Media>> starredSongs = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -39,7 +39,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<Song> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getStarred2().getSongs()));
|
||||
List<Media> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getStarred2().getSongs()));
|
||||
|
||||
if (!random) {
|
||||
starredSongs.setValue(songs);
|
||||
|
|
@ -59,7 +59,7 @@ public class SongRepository {
|
|||
return starredSongs;
|
||||
}
|
||||
|
||||
public void getInstantMix(Song song, int count, MediaCallback callback) {
|
||||
public void getInstantMix(Media song, int count, MediaCallback callback) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getSimilarSongs2(song.getId(), count)
|
||||
|
|
@ -67,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) {
|
||||
List<Song> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
List<Media> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
|
||||
|
||||
if (songs.size() <= 1) {
|
||||
songs.add(song);
|
||||
|
|
@ -79,15 +79,15 @@ public class SongRepository {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
songs.add(song);
|
||||
callback.onLoadMedia(songs);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getRandomSample(int number, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<Song>> randomSongsSample = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getRandomSample(int number, Integer fromYear, Integer toYear) {
|
||||
MutableLiveData<List<Media>> randomSongsSample = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -95,7 +95,7 @@ public class SongRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getRandomSongs() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getRandomSongs().getSongs()));
|
||||
|
|
@ -181,8 +181,8 @@ public class SongRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getSongsByGenre(String id) {
|
||||
MutableLiveData<List<Song>> songsByGenre = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getSongsByGenre(String id) {
|
||||
MutableLiveData<List<Media>> songsByGenre = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
|
|
@ -191,15 +191,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<Song> newSongs = new ArrayList<>(MappingUtil.mapSong(response.body().getSongsByGenre().getSongs()));
|
||||
List<Song> songs = songsByGenre.getValue();
|
||||
List<Media> newSongs = new ArrayList<>(MappingUtil.mapSong(response.body().getSongsByGenre().getSongs()));
|
||||
List<Media> songs = songsByGenre.getValue();
|
||||
|
||||
if (songs == null) songs = new ArrayList<>();
|
||||
songs.addAll(newSongs);
|
||||
Collections.shuffle(songs);
|
||||
|
||||
LinkedHashSet<Song> hashSet = new LinkedHashSet<>(songs);
|
||||
ArrayList<Song> songsWithoutDuplicates = new ArrayList<>(hashSet);
|
||||
LinkedHashSet<Media> hashSet = new LinkedHashSet<>(songs);
|
||||
ArrayList<Media> songsWithoutDuplicates = new ArrayList<>(hashSet);
|
||||
|
||||
songsByGenre.setValue(songsWithoutDuplicates);
|
||||
}
|
||||
|
|
@ -214,8 +214,8 @@ public class SongRepository {
|
|||
return songsByGenre;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getSongsByGenres(ArrayList<String> genresId) {
|
||||
MutableLiveData<List<Song>> songsByGenre = new MutableLiveData<>();
|
||||
public MutableLiveData<List<Media>> getSongsByGenres(ArrayList<String> genresId) {
|
||||
MutableLiveData<List<Media>> songsByGenre = new MutableLiveData<>();
|
||||
|
||||
for (String id : genresId)
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
|
|
@ -224,7 +224,7 @@ public class SongRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
List<Media> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSongsByGenre() != null) {
|
||||
songs.addAll(MappingUtil.mapSong(response.body().getSongsByGenre().getSongs()));
|
||||
|
|
@ -242,8 +242,8 @@ public class SongRepository {
|
|||
return songsByGenre;
|
||||
}
|
||||
|
||||
public MutableLiveData<Song> getSong(String id) {
|
||||
MutableLiveData<Song> song = new MutableLiveData<>();
|
||||
public MutableLiveData<Media> getSong(String id) {
|
||||
MutableLiveData<Media> song = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
|
|
@ -265,7 +265,7 @@ public class SongRepository {
|
|||
return song;
|
||||
}
|
||||
|
||||
public MutableLiveData<String> getSongLyrics(Song song) {
|
||||
public MutableLiveData<String> getSongLyrics(Media song) {
|
||||
MutableLiveData<String> lyrics = new MutableLiveData<>(null);
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue