mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-03 19:01:39 +00:00
Added discover/recentryAddedAlbum/recentlyPlayedAlbum/mostPlayedAlbum data retrieval
This commit is contained in:
parent
304a5f078a
commit
532fcd1ee6
45 changed files with 351 additions and 1205 deletions
|
|
@ -3,17 +3,29 @@ package com.cappielloantonio.play.repository;
|
|||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.AlbumDao;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class AlbumRepository {
|
||||
private static final String TAG = "AlbumRepository";
|
||||
|
||||
private AlbumSongListClient albumSongListClient;
|
||||
|
||||
private AlbumDao albumDao;
|
||||
private LiveData<List<Album>> listLiveAlbums;
|
||||
private LiveData<List<Album>> artistListLiveAlbums;
|
||||
|
|
@ -22,12 +34,30 @@ public class AlbumRepository {
|
|||
|
||||
|
||||
public AlbumRepository(Application application) {
|
||||
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
|
||||
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
albumDao = database.albumDao();
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getListLiveAlbums() {
|
||||
listLiveAlbums = albumDao.getAll();
|
||||
public LiveData<List<Album>> getListLiveAlbums(String type, int size) {
|
||||
MutableLiveData<List<Album>> listLiveAlbums = new MutableLiveData<>();
|
||||
|
||||
albumSongListClient
|
||||
.getAlbumList2(type, size, 0)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getAlbumList2().getAlbums()));
|
||||
listLiveAlbums.setValue(albums);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return listLiveAlbums;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ package com.cappielloantonio.play.repository;
|
|||
import android.app.Application;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.SongArtistCrossDao;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.model.SongArtistCross;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
|||
|
|
@ -3,20 +3,33 @@ package com.cappielloantonio.play.repository;
|
|||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.SongDao;
|
||||
import com.cappielloantonio.play.database.dao.SongGenreCrossDao;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient;
|
||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||
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;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SongRepository {
|
||||
private static final String TAG = "SongRepository";
|
||||
|
||||
private AlbumSongListClient albumSongListClient;
|
||||
|
||||
private SongDao songDao;
|
||||
private SongGenreCrossDao songGenreCrossDao;
|
||||
private LiveData<List<Song>> searchListLiveSongs;
|
||||
|
|
@ -36,11 +49,36 @@ public class SongRepository {
|
|||
private LiveData<List<Song>> listLiveDownloadedSong;
|
||||
|
||||
public SongRepository(Application application) {
|
||||
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
|
||||
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
songDao = database.songDao();
|
||||
songGenreCrossDao = database.songGenreCrossDao();
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getSongs() {
|
||||
MutableLiveData<List<Song>> liveSongs = new MutableLiveData<>();
|
||||
|
||||
albumSongListClient
|
||||
.getRandomSongs(10)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
List<Song> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getRandomSongs().getSongs()));
|
||||
liveSongs.setValue(songs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return liveSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> searchListLiveSong(String title, int limit) {
|
||||
searchListLiveSongs = songDao.searchSong(title, limit);
|
||||
return searchListLiveSongs;
|
||||
|
|
@ -276,7 +314,7 @@ public class SongRepository {
|
|||
thread.start();
|
||||
}
|
||||
|
||||
public List<Song> getRandomSample(int number) {
|
||||
/*public List<Song> getRandomSample(int number) {
|
||||
List<Song> sample = new ArrayList<>();
|
||||
|
||||
PickRandomThreadSafe randomThread = new PickRandomThreadSafe(songDao, number);
|
||||
|
|
@ -291,6 +329,28 @@ public class SongRepository {
|
|||
}
|
||||
|
||||
return sample;
|
||||
}*/
|
||||
|
||||
public void getRandomSample(int number, MediaCallback callback) {
|
||||
albumSongListClient
|
||||
.getRandomSongs(number)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
songs = new ArrayList<>(MappingUtil.mapSong(response.body().getRandomSongs().getSongs()));
|
||||
}
|
||||
|
||||
callback.onLoadMedia(songs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
callback.onError(new Exception(t.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<Song> getPlaylistSong(String playlistID) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue