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 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) {
|
public AlbumRepository(Application application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Album>> getAlbums(String type, int size) {
|
public MutableLiveData<List<Album>> getAlbums(String type, int size) {
|
||||||
|
MutableLiveData<List<Album>> listLiveAlbums = new MutableLiveData<>();
|
||||||
|
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
.getAlbumSongListClient()
|
.getAlbumSongListClient()
|
||||||
.getAlbumList2(type, size, 0, null, null)
|
.getAlbumList2(type, size, 0, null, null)
|
||||||
|
|
@ -46,21 +43,7 @@ public class AlbumRepository {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getAlbumList2().getAlbums()));
|
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;
|
|
||||||
case "random":
|
|
||||||
listLiveRandomAlbums.setValue(albums);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -69,18 +52,7 @@ public class AlbumRepository {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (type) {
|
return listLiveAlbums;
|
||||||
case "newest":
|
|
||||||
return listLiveRecentlyAddedAlbums;
|
|
||||||
case "frequent":
|
|
||||||
return listLiveMostPlayedAlbums;
|
|
||||||
case "recent":
|
|
||||||
return listLiveRecentlyPlayedAlbums;
|
|
||||||
case "random":
|
|
||||||
return listLiveRandomAlbums;
|
|
||||||
default:
|
|
||||||
return new MutableLiveData<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Album>> getStarredAlbums() {
|
public MutableLiveData<List<Album>> getStarredAlbums() {
|
||||||
|
|
|
||||||
|
|
@ -26,15 +26,13 @@ import retrofit2.Response;
|
||||||
public class ArtistRepository {
|
public class ArtistRepository {
|
||||||
private Application application;
|
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) {
|
public ArtistRepository(Application application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Artist>> getStarredArtists() {
|
public MutableLiveData<List<Artist>> getStarredArtists() {
|
||||||
|
MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
.getAlbumSongListClient()
|
.getAlbumSongListClient()
|
||||||
.getStarred2()
|
.getStarred2()
|
||||||
|
|
@ -56,6 +54,8 @@ public class ArtistRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Artist>> getArtists(boolean random, int size) {
|
public MutableLiveData<List<Artist>> getArtists(boolean random, int size) {
|
||||||
|
MutableLiveData<List<Artist>> listLiveArtists = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
.getBrowsingClient()
|
.getBrowsingClient()
|
||||||
.getArtists()
|
.getArtists()
|
||||||
|
|
@ -69,9 +69,13 @@ public class ArtistRepository {
|
||||||
artists.addAll(MappingUtil.mapArtist(index.getArtists()));
|
artists.addAll(MappingUtil.mapArtist(index.getArtists()));
|
||||||
}
|
}
|
||||||
|
|
||||||
listLiveArtists.setValue(artists);
|
if(random) {
|
||||||
Collections.shuffle(artists);
|
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,11 +84,7 @@ public class ArtistRepository {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (random) {
|
return listLiveArtists;
|
||||||
return listLiveRandomArtists;
|
|
||||||
} else {
|
|
||||||
return listLiveArtists;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@ public class GenreRepository {
|
||||||
|
|
||||||
private Application application;
|
private Application application;
|
||||||
|
|
||||||
private MutableLiveData<List<Genre>> genres = new MutableLiveData<>();
|
|
||||||
|
|
||||||
public GenreRepository(Application application) {
|
public GenreRepository(Application application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Genre>> getGenres(boolean random, int size) {
|
public MutableLiveData<List<Genre>> getGenres(boolean random, int size) {
|
||||||
|
MutableLiveData<List<Genre>> genres = new MutableLiveData<>();
|
||||||
|
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
.getBrowsingClient()
|
.getBrowsingClient()
|
||||||
.getGenres()
|
.getGenres()
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,13 @@ import retrofit2.Response;
|
||||||
public class PlaylistRepository {
|
public class PlaylistRepository {
|
||||||
private Application application;
|
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) {
|
public PlaylistRepository(Application application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Playlist>> getPlaylists(boolean random, int size) {
|
public MutableLiveData<List<Playlist>> getPlaylists(boolean random, int size) {
|
||||||
|
MutableLiveData<List<Playlist>> listLivePlaylists = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
.getPlaylistClient()
|
.getPlaylistClient()
|
||||||
.getPlaylists()
|
.getPlaylists()
|
||||||
|
|
@ -39,9 +37,13 @@ public class PlaylistRepository {
|
||||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||||
List<Playlist> playlists = new ArrayList<>(MappingUtil.mapPlaylist(response.body().getPlaylists().getPlaylists()));
|
List<Playlist> playlists = new ArrayList<>(MappingUtil.mapPlaylist(response.body().getPlaylists().getPlaylists()));
|
||||||
listLivePlaylists.setValue(playlists);
|
if(random) {
|
||||||
Collections.shuffle(playlists);
|
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) {
|
public MutableLiveData<List<Song>> getPlaylistSongs(String id) {
|
||||||
|
MutableLiveData<List<Song>> listLivePlaylistSongs = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
.getPlaylistClient()
|
.getPlaylistClient()
|
||||||
.getPlaylist(id)
|
.getPlaylist(id)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class PlaylistCatalogueFragment extends Fragment {
|
||||||
View view = bind.getRoot();
|
View view = bind.getRoot();
|
||||||
|
|
||||||
initAppBar();
|
initAppBar();
|
||||||
initArtistCatalogueView();
|
initPlaylistCatalogueView();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +71,6 @@ public class PlaylistCatalogueFragment extends Fragment {
|
||||||
|
|
||||||
private void initData() {
|
private void initData() {
|
||||||
playlistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(PlaylistCatalogueViewModel.class);
|
playlistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(PlaylistCatalogueViewModel.class);
|
||||||
playlistCatalogueViewModel.loadPlaylists(requireContext());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAppBar() {
|
private void initAppBar() {
|
||||||
|
|
@ -98,7 +97,7 @@ public class PlaylistCatalogueFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private void initArtistCatalogueView() {
|
private void initPlaylistCatalogueView() {
|
||||||
bind.playlistCatalogueRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
bind.playlistCatalogueRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||||
bind.playlistCatalogueRecyclerView.setHasFixedSize(true);
|
bind.playlistCatalogueRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
||||||
private MutableLiveData<List<Playlist>> playlists = new MutableLiveData<>(new ArrayList<>());
|
private MutableLiveData<List<Playlist>> playlists;
|
||||||
|
|
||||||
private PlaylistRepository playlistRepository;
|
private PlaylistRepository playlistRepository;
|
||||||
private String query = "";
|
private String query = "";
|
||||||
|
|
@ -31,28 +31,12 @@ public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
||||||
playlistRepository = new PlaylistRepository(application);
|
playlistRepository = new PlaylistRepository(application);
|
||||||
|
|
||||||
|
playlists = playlistRepository.getPlaylists(false, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Playlist>> getPlaylistList() {
|
public LiveData<List<Playlist>> getPlaylistList() {
|
||||||
return playlists;
|
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