Added the ability to refresh samples on the home page

This commit is contained in:
CappielloAntonio 2021-08-10 15:42:39 +02:00
parent 0b57cd3176
commit bd9dc276f1
8 changed files with 127 additions and 16 deletions

1
.idea/misc.xml generated
View file

@ -22,6 +22,7 @@
<entry key="app/src/main/res/layout/fragment_artist_page.xml" value="0.1" />
<entry key="app/src/main/res/layout/fragment_home.xml" value="0.2212962962962963" />
<entry key="app/src/main/res/layout/fragment_login.xml" value="0.3166496424923391" />
<entry key="app/src/main/res/layout/item_home_discover_song.xml" value="0.3166496424923391" />
<entry key="app/src/main/res/layout/item_horizontal_album.xml" value="0.3166496424923391" />
<entry key="app/src/main/res/layout/item_horizontal_track.xml" value="0.1" />
<entry key="app/src/main/res/layout/item_login_server.xml" value="0.25" />

View file

@ -38,7 +38,7 @@ public class AlbumRepository {
this.application = application;
}
public LiveData<List<Album>> getAlbums(String type, int size) {
public MutableLiveData<List<Album>> getAlbums(String type, int size) {
App.getSubsonicClientInstance(application, false)
.getAlbumSongListClient()
.getAlbumList2(type, size, 0, null, null)

View file

@ -138,6 +138,41 @@ public class HomeFragment extends Fragment {
});
bind.homeSettingsImageView.setOnClickListener(v -> activity.navController.navigate(R.id.action_homeFragment_to_settingsFragment));
bind.musicDiscoveryTextViewRefreshable.setOnLongClickListener(v -> {
homeViewModel.refreshDiscoverySongSample(requireActivity());
return true;
});
bind.recentlyPlayedAlbumsTextViewRefreshable.setOnLongClickListener(v -> {
homeViewModel.refreshRecentlyPlayedAlbumList(requireActivity());
return true;
});
bind.mostPlayedAlbumsTextViewRefreshable.setOnLongClickListener(v -> {
homeViewModel.refreshMostPlayedAlbums(requireActivity());
return true;
});
bind.recentlyAddedAlbumsTextViewRefreshable.setOnLongClickListener(v -> {
homeViewModel.refreshMostRecentlyAddedAlbums(requireActivity());
return true;
});
bind.starredTracksTextViewRefreshable.setOnLongClickListener(v -> {
homeViewModel.refreshStarredTracks(requireActivity());
return true;
});
bind.starredAlbumsTextViewRefreshable.setOnLongClickListener(v -> {
homeViewModel.refreshStarredAlbums(requireActivity());
return true;
});
bind.starredArtistsTextViewRefreshable.setOnLongClickListener(v -> {
homeViewModel.refreshStarredArtists(requireActivity());
return true;
});
}
private void initDiscoverSongSlideView() {

View file

@ -78,6 +78,23 @@ public class LibraryFragment extends Fragment {
bind.artistCatalogueTextViewClickable.setOnClickListener(v -> activity.navController.navigate(R.id.action_libraryFragment_to_artistCatalogueFragment));
bind.genreCatalogueTextViewClickable.setOnClickListener(v -> activity.navController.navigate(R.id.action_libraryFragment_to_genreCatalogueFragment));
bind.playlistCatalogueTextViewClickable.setOnClickListener(v -> activity.navController.navigate(R.id.action_libraryFragment_to_playlistCatalogueFragment));
bind.albumCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshAlbumSample(requireActivity());
return true;
});
bind.artistCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshArtistSample(requireActivity());
return true;
});
bind.genreCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshGenreSample(requireActivity());
return true;
});
bind.playlistCatalogueSampleTextViewRefreshable.setOnLongClickListener(view -> {
libraryViewModel.refreshPlaylistSample(requireActivity());
return true;
});
}
private void initAlbumView() {

View file

@ -4,6 +4,7 @@ import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
@ -28,16 +29,16 @@ public class HomeViewModel extends AndroidViewModel {
private ArtistRepository artistRepository;
private DownloadRepository downloadRepository;
private LiveData<List<Song>> dicoverSongSample;
private LiveData<List<Album>> mostPlayedAlbumSample;
private LiveData<List<Album>> recentlyAddedAlbumSample;
private LiveData<List<Album>> recentlyPlayedAlbumSample;
private MutableLiveData<List<Song>> dicoverSongSample;
private MutableLiveData<List<Album>> mostPlayedAlbumSample;
private MutableLiveData<List<Album>> recentlyAddedAlbumSample;
private MutableLiveData<List<Album>> recentlyPlayedAlbumSample;
private LiveData<List<Download>> downloadedSongSample;
private LiveData<List<Integer>> years;
private LiveData<List<Song>> starredTracks;
private LiveData<List<Album>> starredAlbums;
private LiveData<List<Artist>> starredArtists;
private MutableLiveData<List<Song>> starredTracks;
private MutableLiveData<List<Album>> starredAlbums;
private MutableLiveData<List<Artist>> starredArtists;
public HomeViewModel(@NonNull Application application) {
super(application);
@ -98,4 +99,32 @@ public class HomeViewModel extends AndroidViewModel {
public LiveData<List<Album>> getRecentlyPlayedAlbumList() {
return recentlyPlayedAlbumSample;
}
public void refreshDiscoverySongSample(LifecycleOwner owner) {
songRepository.getRandomSample(10, null, null).observe(owner, songs -> dicoverSongSample.postValue(songs));
}
public void refreshStarredTracks(LifecycleOwner owner) {
songRepository.getStarredSongs().observe(owner, songs -> starredTracks.postValue(songs));
}
public void refreshStarredAlbums(LifecycleOwner owner) {
albumRepository.getStarredAlbums().observe(owner, albums -> starredAlbums.postValue(albums));
}
public void refreshStarredArtists(LifecycleOwner owner) {
artistRepository.getStarredArtists().observe(owner, artists -> starredArtists.postValue(artists));
}
public void refreshMostPlayedAlbums(LifecycleOwner owner) {
albumRepository.getAlbums("frequent", 20).observe(owner, albums -> mostPlayedAlbumSample.postValue(albums));
}
public void refreshMostRecentlyAddedAlbums(LifecycleOwner owner) {
albumRepository.getAlbums("newest", 20).observe(owner, albums -> recentlyAddedAlbumSample.postValue(albums));
}
public void refreshRecentlyPlayedAlbumList(LifecycleOwner owner) {
albumRepository.getAlbums("recent", 20).observe(owner, albums -> recentlyPlayedAlbumSample.postValue(albums));
}
}

View file

@ -4,7 +4,9 @@ import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.cappielloantonio.play.model.Album;
import com.cappielloantonio.play.model.Artist;
@ -23,10 +25,10 @@ public class LibraryViewModel extends AndroidViewModel {
private GenreRepository genreRepository;
private PlaylistRepository playlistRepository;
private LiveData<List<Playlist>> playlistSample;
private LiveData<List<Album>> sampleAlbum;
private LiveData<List<Artist>> sampleArtist;
private LiveData<List<Genre>> sampleGenres;
private MutableLiveData<List<Playlist>> playlistSample;
private MutableLiveData<List<Album>> sampleAlbum;
private MutableLiveData<List<Artist>> sampleArtist;
private MutableLiveData<List<Genre>> sampleGenres;
public LibraryViewModel(@NonNull Application application) {
super(application);
@ -44,10 +46,6 @@ public class LibraryViewModel extends AndroidViewModel {
playlistSample = playlistRepository.getPlaylists(true, 10);
}
public LiveData<List<Playlist>> getPlaylistSample() {
return playlistSample;
}
public LiveData<List<Album>> getAlbumSample() {
return sampleAlbum;
}
@ -59,4 +57,24 @@ public class LibraryViewModel extends AndroidViewModel {
public LiveData<List<Genre>> getGenreSample() {
return sampleGenres;
}
public LiveData<List<Playlist>> getPlaylistSample() {
return playlistSample;
}
public void refreshAlbumSample(LifecycleOwner owner) {
albumRepository.getAlbums("random", 20).observe(owner, albums -> sampleAlbum.postValue(albums));
}
public void refreshArtistSample(LifecycleOwner owner) {
artistRepository.getArtists(true, 20).observe(owner, artists -> sampleArtist.postValue(artists));
}
public void refreshGenreSample(LifecycleOwner owner) {
genreRepository.getGenres(true, 15).observe(owner, genres -> sampleGenres.postValue(genres));
}
public void refreshPlaylistSample(LifecycleOwner owner) {
playlistRepository.getPlaylists(true, 10).observe(owner, playlists -> playlistSample.postValue(playlists));
}
}

View file

@ -30,6 +30,7 @@
android:clipChildren="false">
<TextView
android:id="@+id/music_discovery_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -82,6 +83,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/most_played_albums_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -134,6 +136,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/recently_played_albums_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -216,6 +219,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/starred_tracks_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -265,6 +269,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/starred_albums_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -314,6 +319,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/starred_artists_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -416,6 +422,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/recently_added_albums_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"

View file

@ -29,6 +29,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/album_catalogue_sample_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -82,6 +83,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/artist_catalogue_sample_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -135,6 +137,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/genre_catalogue_sample_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -186,6 +189,7 @@
android:paddingEnd="8dp">
<TextView
android:id="@+id/playlist_catalogue_sample_text_view_refreshable"
style="@style/HeadlineTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"