Fixed bottom sheets functionality

This commit is contained in:
CappielloAntonio 2021-07-31 16:37:41 +02:00
parent 320e3b8678
commit 2e1c21e73c
15 changed files with 348 additions and 222 deletions

View file

@ -6,7 +6,9 @@ import androidx.lifecycle.LiveData;
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.Song;
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
@ -198,4 +200,47 @@ public class AlbumRepository {
return artistsAlbum;
}
public MutableLiveData<Album> getAlbum(String id) {
MutableLiveData<Album> album = new MutableLiveData<>();
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getAlbum(id)
.enqueue(new Callback<SubsonicResponse>() {
@Override
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
album.setValue(MappingUtil.mapAlbum(response.body().getAlbum()));
}
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
}
});
return album;
}
public void getInstantMix(Album album, int count, MediaCallback callback) {
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getSimilarSongs2(album.getId(), count)
.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().getSimilarSongs2().getSongs()));
callback.onLoadMedia(songs);
}
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
callback.onLoadMedia(new ArrayList<>());
}
});
}
}

View file

@ -2,12 +2,14 @@ package com.cappielloantonio.play.repository;
import android.app.Application;
import androidx.fragment.app.FragmentActivity;
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.subsonic.models.ArtistWithAlbumsID3;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.subsonic.models.IndexID3;
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
@ -203,6 +205,85 @@ public class ArtistRepository {
});
}
public MutableLiveData<Artist> getArtist(String id) {
MutableLiveData<Artist> artist = new MutableLiveData<>();
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getArtist(id)
.enqueue(new Callback<SubsonicResponse>() {
@Override
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
artist.setValue(MappingUtil.mapArtist(response.body().getArtist()));
}
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
}
});
return artist;
}
public void getInstantMix(Artist artist, int count, MediaCallback callback) {
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getSimilarSongs2(artist.getId(), count)
.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().getSimilarSongs2().getSongs()));
callback.onLoadMedia(songs);
}
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
callback.onLoadMedia(new ArrayList<>());
}
});
}
public MutableLiveData<ArrayList<Song>> getArtistRandomSong(FragmentActivity fragmentActivity, Artist artist, int count) {
MutableLiveData<ArrayList<Song>> randomSongs = new MutableLiveData<>(new ArrayList());
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getArtist(artist.getId())
.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().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(fragmentActivity, songs -> {
ArrayList<Song> liveSongs = randomSongs.getValue();
Collections.shuffle(liveSongs);
liveSongs.addAll(songs);
randomSongs.setValue(liveSongs);
});
}
}
}
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
}
});
return randomSongs;
}
private void addToMutableLiveData(MutableLiveData<List<Artist>> liveData, Artist artist) {
List<Artist> liveArtists = liveData.getValue();
liveArtists.add(artist);

View file

@ -47,32 +47,6 @@ public class QueueRepository {
return songs;
}
public void insertAll(List<Song> songs) {
InsertAllThreadSafe insertAll = new InsertAllThreadSafe(queueDao, songs);
Thread thread = new Thread(insertAll);
thread.start();
}
public List<Song> insertMix(ArrayList<Song> media) {
List<String> IDs = QueueUtil.getIDsFromSongs(media);
List<Song> mix = new ArrayList<>();
/*GetSongsByIDThreadSafe getSongsByIDThreadSafe = new GetSongsByIDThreadSafe(songDao, IDs);
Thread thread = new Thread(getSongsByIDThreadSafe);
thread.start();
try {
thread.join();
mix = QueueUtil.orderSongByIdList(IDs, getSongsByIDThreadSafe.getSongs());
insertAllAndStartNew(mix);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
return mix;
}
public void insertAllAndStartNew(List<Song> songs) {
try {
final Thread delete = new Thread(new DeleteAllThreadSafe(queueDao));

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<>(new ArrayList());
App.getSubsonicClientInstance(application, false)
.getSearchingClient()
@ -122,15 +122,15 @@ public class SearchingRepository {
List<String> newSuggestions = new ArrayList();
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
for(ArtistID3 artistID3 : response.body().getSearchResult3().getArtists()) {
for (ArtistID3 artistID3 : response.body().getSearchResult3().getArtists()) {
newSuggestions.add(artistID3.getName());
}
for(AlbumID3 albumID3 : response.body().getSearchResult3().getAlbums()) {
for (AlbumID3 albumID3 : response.body().getSearchResult3().getAlbums()) {
newSuggestions.add(albumID3.getName());
}
for(Child song : response.body().getSearchResult3().getSongs()) {
for (Child song : response.body().getSearchResult3().getSongs()) {
newSuggestions.add(song.getTitle());
}