From b4180afa3623d8a4f3d03496d6f2d62931f902ec Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Sat, 16 Mar 2024 17:44:18 +0100 Subject: [PATCH] refactor: refactored artist page layout for consistent vertical scrolling --- .../tempo/repository/AlbumRepository.java | 3 +- .../ui/adapter/AlbumCatalogueAdapter.java | 6 +- .../ui/fragment/AlbumCatalogueFragment.java | 2 +- .../tempo/ui/fragment/ArtistPageFragment.java | 78 +++++++------------ .../tempo/util/Preferences.kt | 12 --- .../main/res/layout/fragment_artist_page.xml | 41 ++-------- .../layout/item_library_catalogue_album.xml | 8 +- 7 files changed, 49 insertions(+), 101 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java b/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java index 2d82fe18..5149af9d 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java +++ b/app/src/main/java/com/cappielloantonio/tempo/repository/AlbumRepository.java @@ -132,9 +132,10 @@ public class AlbumRepository { .enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getArtist() != null) { + if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getArtist() != null && response.body().getSubsonicResponse().getArtist().getAlbums() != null) { List albums = response.body().getSubsonicResponse().getArtist().getAlbums(); albums.sort(Comparator.comparing(AlbumID3::getYear)); + Collections.reverse(albums); artistsAlbum.setValue(albums); } } diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java index 62ff0315..8027578f 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/AlbumCatalogueAdapter.java @@ -2,6 +2,7 @@ package com.cappielloantonio.tempo.ui.adapter; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; import android.widget.Filter; import android.widget.Filterable; @@ -24,6 +25,7 @@ import java.util.List; public class AlbumCatalogueAdapter extends RecyclerView.Adapter implements Filterable { private final ClickCallback click; private String currentFilter; + private boolean showArtist; private final Filter filtering = new Filter() { @Override @@ -59,11 +61,12 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter albums; private List albumsFull; - public AlbumCatalogueAdapter(ClickCallback click) { + public AlbumCatalogueAdapter(ClickCallback click, boolean showArtist) { this.click = click; this.albums = Collections.emptyList(); this.albumsFull = Collections.emptyList(); this.currentFilter = ""; + this.showArtist = showArtist; } @NonNull @@ -79,6 +82,7 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter albumAdapter.setItems(albums)); diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistPageFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistPageFragment.java index 58e18b28..88faa0e4 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistPageFragment.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistPageFragment.java @@ -27,9 +27,11 @@ import com.cappielloantonio.tempo.helper.recyclerview.GridItemDecoration; import com.cappielloantonio.tempo.interfaces.ClickCallback; import com.cappielloantonio.tempo.service.MediaManager; import com.cappielloantonio.tempo.service.MediaService; +import com.cappielloantonio.tempo.subsonic.models.ArtistID3; import com.cappielloantonio.tempo.ui.activity.MainActivity; import com.cappielloantonio.tempo.ui.adapter.AlbumArtistPageOrSimilarAdapter; import com.cappielloantonio.tempo.ui.adapter.AlbumCatalogueAdapter; +import com.cappielloantonio.tempo.ui.adapter.ArtistCatalogueAdapter; import com.cappielloantonio.tempo.ui.adapter.ArtistSimilarAdapter; import com.cappielloantonio.tempo.ui.adapter.SongHorizontalAdapter; import com.cappielloantonio.tempo.util.Constants; @@ -38,6 +40,10 @@ import com.cappielloantonio.tempo.util.Preferences; import com.cappielloantonio.tempo.viewmodel.ArtistPageViewModel; import com.google.common.util.concurrent.ListenableFuture; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + @UnstableApi public class ArtistPageFragment extends Fragment implements ClickCallback { private FragmentArtistPageBinding bind; @@ -45,9 +51,8 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { private ArtistPageViewModel artistPageViewModel; private SongHorizontalAdapter songHorizontalAdapter; - private AlbumArtistPageOrSimilarAdapter albumArtistPageOrSimilarAdapter; private AlbumCatalogueAdapter albumCatalogueAdapter; - private ArtistSimilarAdapter artistSimilarAdapter; + private ArtistCatalogueAdapter artistCatalogueAdapter; private ListenableFuture mediaBrowserListenableFuture; @@ -64,8 +69,7 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { initArtistInfo(); initPlayButtons(); initTopSongsView(); - initHorizontalAlbumsView(); - initVerticalAlbumsView(); + initAlbumsView(); initSimilarArtistsView(); return view; @@ -99,18 +103,6 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { bundle.putParcelable(Constants.ARTIST_OBJECT, artistPageViewModel.getArtist()); activity.navController.navigate(R.id.action_artistPageFragment_to_songListPageFragment, bundle); }); - - bind.artistPageAlbumsSwitchLayoutTextViewClickable.setOnClickListener(view -> { - boolean isHorizontalRecyclerViewVisible = bind.albumsHorizontalRecyclerView.getVisibility() == View.VISIBLE; - - bind.albumsHorizontalRecyclerView.setVisibility(isHorizontalRecyclerViewVisible ? View.GONE : View.VISIBLE); - bind.albumsVerticalRecyclerView.setVisibility(isHorizontalRecyclerViewVisible ? View.VISIBLE : View.GONE); - - Preferences.setArtistAlbumLayout(!isHorizontalRecyclerViewVisible); - }); - - bind.albumsHorizontalRecyclerView.setVisibility(Preferences.isArtistAlbumLayoutHorizontal() ? View.VISIBLE : View.GONE); - bind.albumsVerticalRecyclerView.setVisibility(Preferences.isArtistAlbumLayoutHorizontal() ? View.GONE : View.VISIBLE); } private void initAppBar() { @@ -203,36 +195,13 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { }); } - private void initHorizontalAlbumsView() { - bind.albumsHorizontalRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); + private void initAlbumsView() { + bind.albumsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2)); + bind.albumsRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false)); + bind.albumsRecyclerView.setHasFixedSize(true); - albumArtistPageOrSimilarAdapter = new AlbumArtistPageOrSimilarAdapter(this); - bind.albumsHorizontalRecyclerView.setAdapter(albumArtistPageOrSimilarAdapter); - artistPageViewModel.getAlbumList().observe(getViewLifecycleOwner(), albums -> { - if (albums == null) { - if (bind != null) - bind.artistPageAlbumPlaceholder.placeholder.setVisibility(View.VISIBLE); - if (bind != null) bind.artistPageAlbumsSector.setVisibility(View.GONE); - } else { - if (bind != null) - bind.artistPageAlbumPlaceholder.placeholder.setVisibility(View.GONE); - if (bind != null) - bind.artistPageAlbumsSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE); - albumArtistPageOrSimilarAdapter.setItems(albums); - } - }); - - CustomLinearSnapHelper albumSnapHelper = new CustomLinearSnapHelper(); - albumSnapHelper.attachToRecyclerView(bind.albumsHorizontalRecyclerView); - } - - private void initVerticalAlbumsView() { - bind.albumsVerticalRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2)); - bind.albumsVerticalRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false)); - bind.albumsVerticalRecyclerView.setHasFixedSize(true); - - albumCatalogueAdapter = new AlbumCatalogueAdapter(this); - bind.albumsVerticalRecyclerView.setAdapter(albumCatalogueAdapter); + albumCatalogueAdapter = new AlbumCatalogueAdapter(this, false); + bind.albumsRecyclerView.setAdapter(albumCatalogueAdapter); artistPageViewModel.getAlbumList().observe(getViewLifecycleOwner(), albums -> { if (albums == null) { @@ -250,11 +219,13 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { } private void initSimilarArtistsView() { - bind.similarArtistsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); + bind.similarArtistsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2)); + bind.similarArtistsRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false)); bind.similarArtistsRecyclerView.setHasFixedSize(true); - artistSimilarAdapter = new ArtistSimilarAdapter(this); - bind.similarArtistsRecyclerView.setAdapter(artistSimilarAdapter); + artistCatalogueAdapter = new ArtistCatalogueAdapter(this); + bind.similarArtistsRecyclerView.setAdapter(artistCatalogueAdapter); + artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(getViewLifecycleOwner(), artist -> { if (artist == null) { if (bind != null) @@ -263,9 +234,16 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { } else { if (bind != null) bind.artistPageSimilarArtistPlaceholder.placeholder.setVisibility(View.GONE); - if (bind != null) + if (bind != null && artist.getSimilarArtists() != null) bind.similarArtistSector.setVisibility(!artist.getSimilarArtists().isEmpty() ? View.VISIBLE : View.GONE); - artistSimilarAdapter.setItems(artist.getSimilarArtists()); + + List artists = new ArrayList<>(); + + if (artist.getSimilarArtists() != null) { + artists.addAll(artist.getSimilarArtists()); + } + + artistCatalogueAdapter.setItems(artists); } }); diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt index 5e622cf4..8aa240b7 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt @@ -52,7 +52,6 @@ object Preferences { private const val BUFFERING_STRATEGY = "buffering_strategy" private const val SKIP_MIN_STAR_RATING = "skip_min_star_rating" private const val MIN_STAR_RATING = "min_star_rating" - private const val ARTIST_ALBUM_LAYOUT = "artist_album_layout" private const val ALWAYS_ON_DISPLAY = "always_on_display" private const val AUDIO_QUALITY_PER_ITEM = "audio_quality_per_item" @@ -376,17 +375,6 @@ object Preferences { return App.getInstance().preferences.getInt(MIN_STAR_RATING, 0) } - @JvmStatic - fun isArtistAlbumLayoutHorizontal(): Boolean { - return App.getInstance().preferences.getBoolean(ARTIST_ALBUM_LAYOUT, true) - } - - @JvmStatic - fun setArtistAlbumLayout(isArtistAlbumLayoutHorizontal: Boolean) { - App.getInstance().preferences.edit().putBoolean(ARTIST_ALBUM_LAYOUT, isArtistAlbumLayoutHorizontal) - .apply() - } - @JvmStatic fun isDisplayAlwaysOn(): Boolean { return App.getInstance().preferences.getBoolean(ALWAYS_ON_DISPLAY, false) diff --git a/app/src/main/res/layout/fragment_artist_page.xml b/app/src/main/res/layout/fragment_artist_page.xml index a62fdfa6..f4d3d819 100644 --- a/app/src/main/res/layout/fragment_artist_page.xml +++ b/app/src/main/res/layout/fragment_artist_page.xml @@ -204,44 +204,16 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - - - - - - + android:text="@string/artist_page_title_album_section" /> + android:paddingBottom="8dp"/> diff --git a/app/src/main/res/layout/item_library_catalogue_album.xml b/app/src/main/res/layout/item_library_catalogue_album.xml index e554b925..e38a1d10 100644 --- a/app/src/main/res/layout/item_library_catalogue_album.xml +++ b/app/src/main/res/layout/item_library_catalogue_album.xml @@ -31,10 +31,16 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:ellipsize="marquee" - android:paddingBottom="16dp" android:singleLine="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/album_name_label" /> + + \ No newline at end of file