Added starred tracks, starred albums and starred artists view

This commit is contained in:
CappielloAntonio 2021-07-27 16:58:38 +02:00
parent 9495fbd83d
commit 7742cbdd08
23 changed files with 752 additions and 171 deletions

View file

@ -8,9 +8,11 @@ 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.interfaces.MediaCallback;
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.ResponseStatus;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import com.cappielloantonio.play.util.MappingUtil;
@ -27,11 +29,13 @@ public class AlbumRepository {
private AlbumSongListClient albumSongListClient;
private AlbumDao albumDao;
private LiveData<List<Album>> listLiveAlbums;
private LiveData<List<Album>> artistListLiveAlbums;
private LiveData<List<Album>> listLiveSampleAlbum;
private LiveData<List<Album>> searchListLiveAlbum;
private MutableLiveData<List<Album>> listLiveRecentlyAddedAlbums = new MutableLiveData<>();
private MutableLiveData<List<Album>> listLiveMostPlayedAlbums = new MutableLiveData<>();
private MutableLiveData<List<Album>> listLiveRecentlyPlayedAlbums = new MutableLiveData<>();
public AlbumRepository(Application application) {
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
@ -41,15 +45,24 @@ public class AlbumRepository {
}
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);
switch (type) {
case "newest":
listLiveRecentlyAddedAlbums.setValue(albums);
break;
case "frequent":
listLiveMostPlayedAlbums.setValue(albums);
break;
case "recent":
listLiveRecentlyPlayedAlbums.setValue(albums);
break;
}
}
@Override
@ -58,7 +71,38 @@ public class AlbumRepository {
}
});
return listLiveAlbums;
switch (type) {
case "newest":
return listLiveRecentlyAddedAlbums;
case "frequent":
return listLiveMostPlayedAlbums;
case "recent":
return listLiveRecentlyPlayedAlbums;
default:
return new MutableLiveData<>();
}
}
public MutableLiveData<List<Album>> getStarredAlbums() {
MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>();
albumSongListClient
.getStarred2()
.enqueue(new Callback<SubsonicResponse>() {
@Override
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getStarred2().getAlbums()));
starredAlbums.setValue(albums);
}
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
}
});
return starredAlbums;
}
public LiveData<List<Album>> getArtistListLiveAlbums(String artistId) {

View file

@ -3,26 +3,62 @@ 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.ArtistDao;
import com.cappielloantonio.play.model.Album;
import com.cappielloantonio.play.model.Artist;
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.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class ArtistRepository {
private AlbumSongListClient albumSongListClient;
private ArtistDao artistDao;
private LiveData<List<Artist>> listLiveArtists;
private LiveData<List<Artist>> listLiveSampleArtist;
private LiveData<List<Artist>> searchListLiveArtist;
private MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>();
public ArtistRepository(Application application) {
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
AppDatabase database = AppDatabase.getInstance(application);
artistDao = database.artistDao();
}
public MutableLiveData<List<Artist>> getStarredArtists() {
albumSongListClient
.getStarred2()
.enqueue(new Callback<SubsonicResponse>() {
@Override
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
List<Artist> artists = new ArrayList<>(MappingUtil.mapArtist(response.body().getStarred2().getArtists()));
starredArtists.setValue(artists);
}
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
}
});
return starredArtists;
}
public LiveData<List<Artist>> getListLiveArtists() {
listLiveArtists = artistDao.getAll();
return listLiveArtists;

View file

@ -50,6 +50,8 @@ public class SongRepository {
private LiveData<List<Song>> listLiveSampleDownloadedSong;
private LiveData<List<Song>> listLiveDownloadedSong;
private MutableLiveData<List<Song>> starredSongs = new MutableLiveData<>();
public SongRepository(Application application) {
albumSongListClient = App.getSubsonicClientInstance(application, false).getAlbumSongListClient();
browsingClient = App.getSubsonicClientInstance(application, false).getBrowsingClient();
@ -59,17 +61,15 @@ public class SongRepository {
songGenreCrossDao = database.songGenreCrossDao();
}
public MutableLiveData<List<Song>> getSongs() {
MutableLiveData<List<Song>> liveSongs = new MutableLiveData<>();
public MutableLiveData<List<Song>> getStarredSongs() {
albumSongListClient
.getRandomSongs(10)
.getStarred2()
.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);
List<Song> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getStarred2().getSongs()));
starredSongs.setValue(songs);
}
}
@ -79,7 +79,7 @@ public class SongRepository {
}
});
return liveSongs;
return starredSongs;
}
public void getInstantMix(Song song, int count, MediaCallback callback) {
@ -344,23 +344,6 @@ public class SongRepository {
thread.start();
}
/*public List<Song> getRandomSample(int number) {
List<Song> sample = new ArrayList<>();
PickRandomThreadSafe randomThread = new PickRandomThreadSafe(songDao, number);
Thread thread = new Thread(randomThread);
thread.start();
try {
thread.join();
sample = randomThread.getSample();
} catch (InterruptedException e) {
e.printStackTrace();
}
return sample;
}*/
public void getRandomSample(int number, MediaCallback callback) {
albumSongListClient
.getRandomSongs(number)