mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Fix long click to refresh
This commit is contained in:
parent
560c7e0035
commit
d3f1ce1fe4
6 changed files with 34 additions and 75 deletions
|
|
@ -29,16 +29,13 @@ public class AlbumRepository {
|
|||
|
||||
private Application application;
|
||||
|
||||
private MutableLiveData<List<Album>> listLiveRecentlyAddedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveMostPlayedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveRecentlyPlayedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveRandomAlbums = new MutableLiveData<>();
|
||||
|
||||
public AlbumRepository(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getAlbums(String type, int size) {
|
||||
MutableLiveData<List<Album>> listLiveAlbums = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getAlbumList2(type, size, 0, null, null)
|
||||
|
|
@ -46,21 +43,7 @@ public class AlbumRepository {
|
|||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getAlbumList2().getAlbums()));
|
||||
|
||||
switch (type) {
|
||||
case "newest":
|
||||
listLiveRecentlyAddedAlbums.setValue(albums);
|
||||
break;
|
||||
case "frequent":
|
||||
listLiveMostPlayedAlbums.setValue(albums);
|
||||
break;
|
||||
case "recent":
|
||||
listLiveRecentlyPlayedAlbums.setValue(albums);
|
||||
break;
|
||||
case "random":
|
||||
listLiveRandomAlbums.setValue(albums);
|
||||
break;
|
||||
}
|
||||
listLiveAlbums.setValue(albums);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -69,18 +52,7 @@ public class AlbumRepository {
|
|||
}
|
||||
});
|
||||
|
||||
switch (type) {
|
||||
case "newest":
|
||||
return listLiveRecentlyAddedAlbums;
|
||||
case "frequent":
|
||||
return listLiveMostPlayedAlbums;
|
||||
case "recent":
|
||||
return listLiveRecentlyPlayedAlbums;
|
||||
case "random":
|
||||
return listLiveRandomAlbums;
|
||||
default:
|
||||
return new MutableLiveData<>();
|
||||
}
|
||||
return listLiveAlbums;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getStarredAlbums() {
|
||||
|
|
|
|||
|
|
@ -26,15 +26,13 @@ import retrofit2.Response;
|
|||
public class ArtistRepository {
|
||||
private Application application;
|
||||
|
||||
private MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
private MutableLiveData<List<Artist>> listLiveRandomArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
private MutableLiveData<List<Artist>> listLiveArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
public ArtistRepository(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getStarredArtists() {
|
||||
MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getStarred2()
|
||||
|
|
@ -56,6 +54,8 @@ public class ArtistRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getArtists(boolean random, int size) {
|
||||
MutableLiveData<List<Artist>> listLiveArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getArtists()
|
||||
|
|
@ -69,9 +69,13 @@ public class ArtistRepository {
|
|||
artists.addAll(MappingUtil.mapArtist(index.getArtists()));
|
||||
}
|
||||
|
||||
listLiveArtists.setValue(artists);
|
||||
if(random) {
|
||||
Collections.shuffle(artists);
|
||||
getArtistInfo(artists.subList(0, artists.size() / size > 0 ? size : artists.size()), listLiveRandomArtists);
|
||||
getArtistInfo(artists.subList(0, artists.size() / size > 0 ? size : artists.size()), listLiveArtists);
|
||||
}
|
||||
else {
|
||||
listLiveArtists.setValue(artists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,12 +84,8 @@ public class ArtistRepository {
|
|||
}
|
||||
});
|
||||
|
||||
if (random) {
|
||||
return listLiveRandomArtists;
|
||||
} else {
|
||||
return listLiveArtists;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Metodo che mi restituisce le informazioni essenzionali dell'artista (cover, numero di album...)
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@ public class GenreRepository {
|
|||
|
||||
private Application application;
|
||||
|
||||
private MutableLiveData<List<Genre>> genres = new MutableLiveData<>();
|
||||
|
||||
public GenreRepository(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Genre>> getGenres(boolean random, int size) {
|
||||
MutableLiveData<List<Genre>> genres = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getGenres()
|
||||
|
|
|
|||
|
|
@ -22,15 +22,13 @@ import retrofit2.Response;
|
|||
public class PlaylistRepository {
|
||||
private Application application;
|
||||
|
||||
private MutableLiveData<List<Playlist>> listLivePlaylists = new MutableLiveData<>(new ArrayList<>());
|
||||
private MutableLiveData<List<Playlist>> listLiveRandomPlaylist = new MutableLiveData<>(new ArrayList<>());
|
||||
private MutableLiveData<List<Song>> listLivePlaylistSongs = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
public PlaylistRepository(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Playlist>> getPlaylists(boolean random, int size) {
|
||||
MutableLiveData<List<Playlist>> listLivePlaylists = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getPlaylistClient()
|
||||
.getPlaylists()
|
||||
|
|
@ -39,9 +37,13 @@ public class PlaylistRepository {
|
|||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
List<Playlist> playlists = new ArrayList<>(MappingUtil.mapPlaylist(response.body().getPlaylists().getPlaylists()));
|
||||
listLivePlaylists.setValue(playlists);
|
||||
if(random) {
|
||||
Collections.shuffle(playlists);
|
||||
listLiveRandomPlaylist.setValue(playlists);
|
||||
listLivePlaylists.setValue(playlists.subList(0, size));
|
||||
}
|
||||
else {
|
||||
listLivePlaylists.setValue(playlists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +56,8 @@ public class PlaylistRepository {
|
|||
}
|
||||
|
||||
public MutableLiveData<List<Song>> getPlaylistSongs(String id) {
|
||||
MutableLiveData<List<Song>> listLivePlaylistSongs = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getPlaylistClient()
|
||||
.getPlaylist(id)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class PlaylistCatalogueFragment extends Fragment {
|
|||
View view = bind.getRoot();
|
||||
|
||||
initAppBar();
|
||||
initArtistCatalogueView();
|
||||
initPlaylistCatalogueView();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
@ -71,7 +71,6 @@ public class PlaylistCatalogueFragment extends Fragment {
|
|||
|
||||
private void initData() {
|
||||
playlistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(PlaylistCatalogueViewModel.class);
|
||||
playlistCatalogueViewModel.loadPlaylists(requireContext());
|
||||
}
|
||||
|
||||
private void initAppBar() {
|
||||
|
|
@ -98,7 +97,7 @@ public class PlaylistCatalogueFragment extends Fragment {
|
|||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void initArtistCatalogueView() {
|
||||
private void initPlaylistCatalogueView() {
|
||||
bind.playlistCatalogueRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
bind.playlistCatalogueRecyclerView.setHasFixedSize(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import retrofit2.Call;
|
|||
import retrofit2.Callback;
|
||||
|
||||
public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
||||
private MutableLiveData<List<Playlist>> playlists = new MutableLiveData<>(new ArrayList<>());
|
||||
private MutableLiveData<List<Playlist>> playlists;
|
||||
|
||||
private PlaylistRepository playlistRepository;
|
||||
private String query = "";
|
||||
|
|
@ -31,28 +31,12 @@ public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
|||
super(application);
|
||||
|
||||
playlistRepository = new PlaylistRepository(application);
|
||||
|
||||
playlists = playlistRepository.getPlaylists(false, -1);
|
||||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPlaylistList() {
|
||||
return playlists;
|
||||
}
|
||||
|
||||
public void loadPlaylists(Context context) {
|
||||
App.getSubsonicClientInstance(context, false)
|
||||
.getPlaylistClient()
|
||||
.getPlaylists()
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, retrofit2.Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
playlists.setValue(MappingUtil.mapPlaylist(response.body().getPlaylists().getPlaylists()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue