Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.cappielloantonio.tempo.subsonic.models.AlbumID3;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.TileSizeManager;

import java.util.Collections;
import java.util.List;
Expand All @@ -22,6 +23,8 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>

private List<AlbumID3> albums;

private int sizePx = 400;

public AlbumAdapter(ClickCallback click) {
this.click = click;
this.albums = Collections.emptyList();
Expand All @@ -31,11 +34,20 @@ public AlbumAdapter(ClickCallback click) {
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemLibraryAlbumBinding view = ItemLibraryAlbumBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

TileSizeManager.getInstance().calculateTileSize(parent.getContext());
sizePx = TileSizeManager.getInstance().getTileSizePx(parent.getContext());

return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ViewGroup.LayoutParams lp = holder.item.albumCoverImageView.getLayoutParams();
lp.width = sizePx;
lp.height = sizePx;
holder.item.albumCoverImageView.setLayoutParams(lp);

AlbumID3 album = albums.get(position);

holder.item.albumNameLabel.setText(album.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.TileSizeManager;

import java.util.Collections;
import java.util.List;
Expand All @@ -24,6 +25,7 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
private final boolean mix;
private final boolean bestOf;

private int sizePx = 400;
private List<ArtistID3> artists;

public ArtistAdapter(ClickCallback click, Boolean mix, Boolean bestOf) {
Expand All @@ -37,11 +39,20 @@ public ArtistAdapter(ClickCallback click, Boolean mix, Boolean bestOf) {
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemLibraryArtistBinding view = ItemLibraryArtistBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

TileSizeManager.getInstance().calculateTileSize(parent.getContext());
sizePx = TileSizeManager.getInstance().getTileSizePx(parent.getContext());

return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ViewGroup.LayoutParams lp = holder.item.artistCoverImageView.getLayoutParams();
lp.width = sizePx;
lp.height = sizePx;
holder.item.artistCoverImageView.setLayoutParams(lp);

ArtistID3 artist = artists.get(position);

holder.item.artistNameLabel.setText(artist.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.cappielloantonio.tempo.subsonic.models.SimilarArtistID3;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.TileSizeManager;

import java.util.Collections;
import java.util.List;
Expand All @@ -22,6 +23,8 @@ public class ArtistSimilarAdapter extends RecyclerView.Adapter<ArtistSimilarAdap

private List<SimilarArtistID3> artists;

private int sizePx = 400;

public ArtistSimilarAdapter(ClickCallback click) {
this.click = click;
this.artists = Collections.emptyList();
Expand All @@ -31,11 +34,20 @@ public ArtistSimilarAdapter(ClickCallback click) {
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemLibrarySimilarArtistBinding view = ItemLibrarySimilarArtistBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

TileSizeManager.getInstance().calculateTileSize(parent.getContext());
sizePx = TileSizeManager.getInstance().getTileSizePx(parent.getContext());

return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ViewGroup.LayoutParams lp = holder.item.similarArtistCoverImageView.getLayoutParams();
lp.width = sizePx;
lp.height = sizePx;
holder.item.similarArtistCoverImageView.setLayoutParams(lp);

SimilarArtistID3 artist = artists.get(position);

holder.item.artistNameLabel.setText(artist.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;

Expand All @@ -14,6 +15,7 @@
import com.cappielloantonio.tempo.subsonic.models.Child;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.TileSizeManager;

import java.util.Collections;
import java.util.List;
Expand All @@ -23,6 +25,9 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte

private List<Child> songs;

private int widthPx = 800;
private int heightPx = 400;

public DiscoverSongAdapter(ClickCallback click) {
this.click = click;
this.songs = Collections.emptyList();
Expand All @@ -32,11 +37,21 @@ public DiscoverSongAdapter(ClickCallback click) {
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemHomeDiscoverSongBinding view = ItemHomeDiscoverSongBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

TileSizeManager.getInstance().calculateDiscoverSize(parent.getContext());
widthPx = TileSizeManager.getInstance().getDiscoverWidthPx(parent.getContext());;
heightPx = TileSizeManager.getInstance().getDiscoverHeightPx(parent.getContext());;

return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ViewGroup.LayoutParams lp = holder.item.discoverSongCoverImageView.getLayoutParams();
lp.width = widthPx;
lp.height = heightPx;
holder.item.discoverSongCoverImageView.setLayoutParams(lp);

Child song = songs.get(position);

holder.item.titleDiscoverSongLabel.setText(song.getTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.cappielloantonio.tempo.ui.adapter.AlbumCatalogueAdapter;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.util.TileSizeManager;
import com.cappielloantonio.tempo.viewmodel.AlbumCatalogueViewModel;

import java.util.ArrayList;
Expand All @@ -48,9 +49,9 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
private FragmentAlbumCatalogueBinding bind;
private MainActivity activity;
private AlbumCatalogueViewModel albumCatalogueViewModel;

private AlbumCatalogueAdapter albumAdapter;
private int spanCount = 2;
private int tileSpacing = 20;
private AlbumCatalogueAdapter albumAdapter;
private String currentSortOrder;
private List<com.cappielloantonio.tempo.subsonic.models.AlbumID3> originalAlbums;

Expand Down Expand Up @@ -92,9 +93,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
bind = FragmentAlbumCatalogueBinding.inflate(inflater, container, false);
View view = bind.getRoot();

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
spanCount = Preferences.getLandscapeItemsPerRow();
}
TileSizeManager.getInstance().calculateTileSize( requireContext() );
spanCount = TileSizeManager.getInstance().getTileSpanCount( requireContext() );
tileSpacing = TileSizeManager.getInstance().getTileSpacing( requireContext() );

initAppBar();
initAlbumCatalogueView();
Expand Down Expand Up @@ -140,7 +141,7 @@ private void initAppBar() {
@SuppressLint("ClickableViewAccessibility")
private void initAlbumCatalogueView() {
bind.albumCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), spanCount));
bind.albumCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, 20, false));
bind.albumCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, tileSpacing, false));
bind.albumCatalogueRecyclerView.setHasFixedSize(true);

albumAdapter = new AlbumCatalogueAdapter(this, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.cappielloantonio.tempo.ui.adapter.ArtistCatalogueAdapter;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.util.TileSizeManager;
import com.cappielloantonio.tempo.viewmodel.ArtistCatalogueViewModel;
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;

Expand All @@ -51,7 +52,9 @@ public class ArtistCatalogueFragment extends Fragment implements ClickCallback {
private ArtistCatalogueViewModel artistCatalogueViewModel;

private ArtistCatalogueAdapter artistAdapter;

private int spanCount = 2;
private int tileSpacing = 20;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -68,9 +71,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
bind = FragmentArtistCatalogueBinding.inflate(inflater, container, false);
View view = bind.getRoot();

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
spanCount = Preferences.getLandscapeItemsPerRow();
}
TileSizeManager.getInstance().calculateTileSize( requireContext() );
spanCount = TileSizeManager.getInstance().getTileSpanCount( requireContext() );
tileSpacing = TileSizeManager.getInstance().getTileSpacing( requireContext() );

initAppBar();
initArtistCatalogueView();
Expand Down Expand Up @@ -115,7 +118,7 @@ private void initAppBar() {
@SuppressLint("ClickableViewAccessibility")
private void initArtistCatalogueView() {
bind.artistCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), spanCount));
bind.artistCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, 20, false));
bind.artistCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, tileSpacing, false));
bind.artistCatalogueRecyclerView.setHasFixedSize(true);

artistAdapter = new ArtistCatalogueAdapter(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.util.TileSizeManager;
import com.cappielloantonio.tempo.viewmodel.ArtistPageViewModel;
import com.cappielloantonio.tempo.viewmodel.PlaybackViewModel;
import com.google.common.util.concurrent.ListenableFuture;
Expand All @@ -65,6 +66,7 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;

private int spanCount = 2;
private int tileSpacing = 20;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand All @@ -75,9 +77,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
artistPageViewModel = new ViewModelProvider(requireActivity()).get(ArtistPageViewModel.class);
playbackViewModel = new ViewModelProvider(requireActivity()).get(PlaybackViewModel.class);

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
spanCount = Preferences.getLandscapeItemsPerRow();
}
TileSizeManager.getInstance().calculateTileSize( requireContext() );
spanCount = TileSizeManager.getInstance().getTileSpanCount( requireContext() );
tileSpacing = TileSizeManager.getInstance().getTileSpacing( requireContext() );

init(view);
initAppBar();
Expand Down Expand Up @@ -285,7 +287,7 @@ private void initTopSongsView() {

private void initAlbumsView() {
bind.albumsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), spanCount));
bind.albumsRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, 20, false));
bind.albumsRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, tileSpacing, false));
bind.albumsRecyclerView.setHasFixedSize(true);

albumCatalogueAdapter = new AlbumCatalogueAdapter(this, false);
Expand All @@ -304,7 +306,7 @@ private void initAlbumsView() {

private void initSimilarArtistsView() {
bind.similarArtistsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), spanCount));
bind.similarArtistsRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, 20, false));
bind.similarArtistsRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, tileSpacing, false));
bind.similarArtistsRecyclerView.setHasFixedSize(true);

artistCatalogueAdapter = new ArtistCatalogueAdapter(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.cappielloantonio.tempo.ui.adapter.GenreCatalogueAdapter;
import com.cappielloantonio.tempo.util.Constants;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.util.TileSizeManager;
import com.cappielloantonio.tempo.viewmodel.GenreCatalogueViewModel;

@OptIn(markerClass = UnstableApi.class)
Expand All @@ -43,7 +44,9 @@ public class GenreCatalogueFragment extends Fragment implements ClickCallback {
private GenreCatalogueViewModel genreCatalogueViewModel;

private GenreCatalogueAdapter genreCatalogueAdapter;

private int spanCount = 2;
private int tileSpacing = 20;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -59,9 +62,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
View view = bind.getRoot();
genreCatalogueViewModel = new ViewModelProvider(requireActivity()).get(GenreCatalogueViewModel.class);

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
spanCount = Preferences.getLandscapeItemsPerRow();
}
TileSizeManager.getInstance().calculateGenreSize( requireContext() );
spanCount = TileSizeManager.getInstance().getGenreSpanCount( requireContext() );
tileSpacing = TileSizeManager.getInstance().getGenreSpacing( requireContext() );

init();
initAppBar();
Expand Down Expand Up @@ -105,7 +108,7 @@ private void initAppBar() {
@SuppressLint("ClickableViewAccessibility")
private void initGenreCatalogueView() {
bind.genreCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), spanCount));
bind.genreCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, 16, false));
bind.genreCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(spanCount, tileSpacing, false));
bind.genreCatalogueRecyclerView.setHasFixedSize(true);

genreCatalogueAdapter = new GenreCatalogueAdapter(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.cappielloantonio.tempo.util.MappingUtil;
import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.util.TileSizeManager;
import com.cappielloantonio.tempo.util.UIUtil;
import com.cappielloantonio.tempo.viewmodel.HomeViewModel;
import com.cappielloantonio.tempo.viewmodel.PlaybackViewModel;
Expand Down Expand Up @@ -682,11 +683,12 @@ public void onChanged(List<Child> allSongs) {
private void initDiscoverSongSlideView() {
if (homeViewModel.checkHomeSectorVisibility(Constants.HOME_SECTOR_DISCOVERY)) return;

bind.discoverSongViewPager.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
bind.discoverSongRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.discoverSongRecyclerView.setHasFixedSize(true);

discoverSongAdapter = new DiscoverSongAdapter(this);
bind.discoverSongViewPager.setAdapter(discoverSongAdapter);
bind.discoverSongViewPager.setOffscreenPageLimit(1);
bind.discoverSongRecyclerView.setAdapter(discoverSongAdapter);

homeViewModel.getDiscoverSongSample(getViewLifecycleOwner()).observe(getViewLifecycleOwner(), songs -> {
MusicUtil.ratingFilter(songs);

Expand All @@ -699,8 +701,6 @@ private void initDiscoverSongSlideView() {
discoverSongAdapter.setItems(songs);
}
});

setSlideViewOffset(bind.discoverSongViewPager, 20, 16);
}

private void initSimilarSongView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ object Preferences {
private const val ARTIST_DISPLAY_BIOGRAPHY= "artist_display_biography"
private const val NETWORK_PING_TIMEOUT = "network_ping_timeout_base"

private const val TILE_SIZE = "tile_size"
private const val AA_ALBUM_VIEW = "androidauto_album_view"
private const val AA_HOME_VIEW = "androidauto_home_view"
private const val AA_PLAYLIST_VIEW = "androidauto_playlist_view"
Expand Down Expand Up @@ -769,6 +770,10 @@ object Preferences {
}

@JvmStatic
fun getTileSize(): Int {
val parsed = App.getInstance().preferences.getString(TILE_SIZE, "2")?.toIntOrNull()
return parsed?.takeIf { it in 2..6 } ?: 2
}
fun isAndroidAutoAlbumViewEnabled(): Boolean {
return App.getInstance().preferences.getBoolean(AA_ALBUM_VIEW, true)
}
Expand Down
Loading