feat: tile size manager (#440)
* Add TileSizeManager and improve dynamic tile sizing * Improve scale labels * Add protection against invalid tile size preferences * Fix DiscoverSongAdapter & move TileSizeManager
This commit is contained in:
@@ -13,6 +13,7 @@ import com.cappielloantonio.tempo.interfaces.ClickCallback;
|
||||
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;
|
||||
@@ -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();
|
||||
@@ -31,11 +34,20 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
||||
@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());
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.cappielloantonio.tempo.interfaces.ClickCallback;
|
||||
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;
|
||||
@@ -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) {
|
||||
@@ -37,11 +39,20 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
||||
@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());
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.cappielloantonio.tempo.interfaces.ClickCallback;
|
||||
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;
|
||||
@@ -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();
|
||||
@@ -31,11 +34,20 @@ public class ArtistSimilarAdapter extends RecyclerView.Adapter<ArtistSimilarAdap
|
||||
@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());
|
||||
|
||||
@@ -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.view.animation.AccelerateDecelerateInterpolator;
|
||||
|
||||
@@ -14,6 +15,7 @@ import com.cappielloantonio.tempo.interfaces.ClickCallback;
|
||||
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;
|
||||
@@ -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();
|
||||
@@ -32,11 +37,21 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte
|
||||
@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());
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.cappielloantonio.tempo.ui.activity.MainActivity;
|
||||
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;
|
||||
@@ -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;
|
||||
|
||||
@@ -92,9 +93,9 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
|
||||
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();
|
||||
@@ -140,7 +141,7 @@ public class AlbumCatalogueFragment extends Fragment implements ClickCallback {
|
||||
@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);
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.cappielloantonio.tempo.ui.activity.MainActivity;
|
||||
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;
|
||||
|
||||
@@ -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) {
|
||||
@@ -68,9 +71,9 @@ public class ArtistCatalogueFragment extends Fragment implements ClickCallback {
|
||||
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();
|
||||
@@ -115,7 +118,7 @@ public class ArtistCatalogueFragment extends Fragment implements ClickCallback {
|
||||
@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);
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.cappielloantonio.tempo.ui.adapter.SongHorizontalAdapter;
|
||||
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;
|
||||
@@ -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) {
|
||||
@@ -75,9 +77,9 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
|
||||
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();
|
||||
@@ -285,7 +287,7 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
|
||||
|
||||
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);
|
||||
@@ -304,7 +306,7 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
|
||||
|
||||
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);
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.cappielloantonio.tempo.ui.activity.MainActivity;
|
||||
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)
|
||||
@@ -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) {
|
||||
@@ -59,9 +62,9 @@ public class GenreCatalogueFragment extends Fragment implements ClickCallback {
|
||||
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();
|
||||
@@ -105,7 +108,7 @@ public class GenreCatalogueFragment extends Fragment implements ClickCallback {
|
||||
@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);
|
||||
|
||||
@@ -64,6 +64,7 @@ import com.cappielloantonio.tempo.util.ExternalAudioWriter;
|
||||
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;
|
||||
@@ -682,11 +683,12 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
||||
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);
|
||||
|
||||
@@ -699,8 +701,6 @@ public class HomeTabMusicFragment extends Fragment implements ClickCallback {
|
||||
discoverSongAdapter.setItems(songs);
|
||||
}
|
||||
});
|
||||
|
||||
setSlideViewOffset(bind.discoverSongViewPager, 20, 16);
|
||||
}
|
||||
|
||||
private void initSimilarSongView() {
|
||||
|
||||
@@ -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"
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.cappielloantonio.tempo.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
public class TileSizeManager {
|
||||
|
||||
private static TileSizeManager instance;
|
||||
|
||||
private int tileSizePx;
|
||||
private int tileSpanCount;
|
||||
private int tileSpacing;
|
||||
private int genreSizePx;
|
||||
private int genreSpanCount;
|
||||
private int genreSpacing;
|
||||
private int GenreSpacing;
|
||||
private int discoverWidthPx;
|
||||
private int discoverHeightPx;
|
||||
private boolean tileIsInitialized;
|
||||
private boolean genreIsInitialized;
|
||||
private boolean discoverIsInitialized;
|
||||
|
||||
private TileSizeManager() {
|
||||
}
|
||||
|
||||
public static TileSizeManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new TileSizeManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public int getTileSizePx(Context context) {
|
||||
if( !tileIsInitialized )
|
||||
calculateTileSize(context);
|
||||
return tileSizePx;
|
||||
}
|
||||
public int getTileSpanCount(Context context) {
|
||||
if( !tileIsInitialized )
|
||||
calculateTileSize(context);
|
||||
return tileSpanCount;
|
||||
}
|
||||
public int getTileSpacing(Context context) {
|
||||
if( !tileIsInitialized )
|
||||
calculateTileSize(context);
|
||||
return tileSpacing;
|
||||
}
|
||||
public int getGenreSizePx(Context context) {
|
||||
if( !genreIsInitialized )
|
||||
calculateGenreSize(context);
|
||||
return genreSizePx;
|
||||
}
|
||||
public int getGenreSpanCount(Context context) {
|
||||
if( !genreIsInitialized )
|
||||
calculateGenreSize(context);
|
||||
return genreSpanCount;
|
||||
}
|
||||
public int getGenreSpacing(Context context) {
|
||||
if( !genreIsInitialized )
|
||||
calculateGenreSize(context);
|
||||
return genreSpacing;
|
||||
}
|
||||
public int getDiscoverWidthPx(Context context) {
|
||||
if( !discoverIsInitialized )
|
||||
calculateTileSize(context);
|
||||
return discoverWidthPx;
|
||||
}
|
||||
public int getDiscoverHeightPx(Context context) {
|
||||
if( !discoverIsInitialized )
|
||||
calculateTileSize(context);
|
||||
return discoverHeightPx;
|
||||
}
|
||||
|
||||
public void calculateTileSize(Context context) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
float screenWidth = metrics.widthPixels;
|
||||
float screenHeight = metrics.heightPixels;
|
||||
|
||||
// retrieve the divisor in the preferences
|
||||
int userTileSize = Math.max(2, Math.min(6, Preferences.getTileSize()));
|
||||
float divisor = (float)userTileSize;
|
||||
|
||||
// little pading = 10
|
||||
tileSizePx = Math.round(Math.min(screenWidth, screenHeight) / divisor) - 10;
|
||||
tileSpanCount = Math.max(2, Math.round(screenWidth / (float)tileSizePx) );
|
||||
|
||||
switch (userTileSize) {
|
||||
default:
|
||||
case 2: // XL
|
||||
tileSpacing = 20;
|
||||
break;
|
||||
case 3: // L
|
||||
tileSpacing = 15;
|
||||
break;
|
||||
case 4: // M
|
||||
tileSpacing = 10;
|
||||
break;
|
||||
case 5: // S
|
||||
tileSpacing = 6;
|
||||
break;
|
||||
case 6: // SX
|
||||
tileSpacing = 2;
|
||||
break;
|
||||
}
|
||||
tileIsInitialized = true;
|
||||
}
|
||||
|
||||
public void calculateGenreSize(Context context) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
float screenWidth = metrics.widthPixels;
|
||||
float screenHeight = metrics.heightPixels;
|
||||
|
||||
// retrieve the divisor in the preferences
|
||||
int userTileSize = Math.max(2, Math.min(3, Preferences.getTileSize()));
|
||||
float divisor = (float)userTileSize;
|
||||
|
||||
// little pading = 10
|
||||
genreSizePx = Math.round(Math.min(screenWidth, screenHeight) / divisor) - 10;
|
||||
genreSpanCount = Math.max(2, Math.round(screenWidth / (float)genreSizePx) );
|
||||
|
||||
switch (userTileSize) {
|
||||
default:
|
||||
case 2: // XL
|
||||
genreSpacing = 20;
|
||||
break;
|
||||
case 3: // L
|
||||
genreSpacing = 15;
|
||||
break;
|
||||
case 4: // M
|
||||
genreSpacing = 10;
|
||||
break;
|
||||
case 5: // S
|
||||
genreSpacing = 6;
|
||||
break;
|
||||
case 6: // XS
|
||||
genreSpacing = 2;
|
||||
break;
|
||||
}
|
||||
genreIsInitialized = true;
|
||||
}
|
||||
|
||||
public void calculateDiscoverSize(Context context) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
float screenWidth = metrics.widthPixels;
|
||||
float screenHeight = metrics.heightPixels;
|
||||
float discoverDivisor;
|
||||
|
||||
// retrieve the divisor in the preferences
|
||||
int userTileSize = Math.max(2, Math.min(6, Preferences.getTileSize()));
|
||||
|
||||
switch (userTileSize) {
|
||||
default:
|
||||
case 2: // XL
|
||||
discoverDivisor = 1.0f;
|
||||
break;
|
||||
case 3: // L
|
||||
discoverDivisor = 1.25f;
|
||||
break;
|
||||
case 4: // M
|
||||
discoverDivisor = 1.5f;
|
||||
break;
|
||||
case 5: // S
|
||||
discoverDivisor = 1.75f;
|
||||
break;
|
||||
case 6: // XS
|
||||
discoverDivisor = 2.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
discoverWidthPx = Math.round(Math.min(screenWidth, screenHeight) / discoverDivisor) - 50;
|
||||
discoverHeightPx = Math.round((float)discoverWidthPx * 0.6f);
|
||||
discoverIsInitialized = true;
|
||||
}
|
||||
}
|
||||
@@ -330,13 +330,13 @@
|
||||
</LinearLayout>
|
||||
|
||||
<!-- slideview -->
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/discover_song_view_pager"
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/discover_song_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="212dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="16dp" />
|
||||
android:paddingBottom="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Similar tracks -->
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="8dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingHorizontal="16dp">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/discover_song_cover_image_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="344dp"
|
||||
android:layout_height="172dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
@@ -16,30 +17,34 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_discover_song_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="18dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="@font/inter"
|
||||
android:maxLines="2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/discover_song_cover_image_view"
|
||||
android:textColor="@color/gradientTitleColor"
|
||||
android:textFontWeight="400"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/album_discover_song_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/title_discover_song_label"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:drawablePadding="10dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="@font/inter"
|
||||
android:maxLines="1"
|
||||
android:maxLines="2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/title_discover_song_label"
|
||||
android:textColor="@color/gradientSubtitleColor"
|
||||
android:textFontWeight="400"
|
||||
android:textSize="14sp" />
|
||||
</RelativeLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -4,13 +4,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingBottom="8dp">
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingBottom="4dp">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/card_view"
|
||||
android:layout_width="172dp"
|
||||
android:layout_height="72dp"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="54dp"
|
||||
android:layout_gravity="center"
|
||||
card_view:cardCornerRadius="4dp"
|
||||
card_view:cardElevation="2dp"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/card_view"
|
||||
android:layout_width="196dp"
|
||||
android:layout_width="172dp"
|
||||
android:layout_height="54dp"
|
||||
android:layout_gravity="center"
|
||||
card_view:cardCornerRadius="4dp"
|
||||
|
||||
@@ -255,6 +255,20 @@
|
||||
<item>4</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="tile_size_titles">
|
||||
<item>Minuscule</item>
|
||||
<item>Petite</item>
|
||||
<item>Moyenne</item>
|
||||
<item>Large</item>
|
||||
<item>Défaut</item>
|
||||
</string-array>
|
||||
<string-array name="tile_size_divisor">
|
||||
<item>6</item>
|
||||
<item>5</item>
|
||||
<item>4</item>
|
||||
<item>3</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
<!-- Add by MFO -->
|
||||
<string-array name="aa_tab_titles">
|
||||
<item>Ne pas afficher</item>
|
||||
|
||||
@@ -432,6 +432,8 @@
|
||||
<string name="settings_sync_starred_tracks_for_offline_use_summary">Si activé, les pistes favorites seront téléchargées pour l\'écoute hors-ligne.</string>
|
||||
<string name="settings_sync_starred_tracks_for_offline_use_title">Synchronisation des pistes favorites pour écoute hors-ligne</string>
|
||||
<string name="settings_theme">Thème</string>
|
||||
<string name="settings_tile_size">Taille des vignettes</string>
|
||||
<string name="settings_title_data">Données</string>
|
||||
<string name="settings_title_data">Données</string>
|
||||
<string name="settings_title_general">Géneral</string>
|
||||
<string name="settings_title_playlist">Playlist</string>
|
||||
|
||||
@@ -279,6 +279,20 @@
|
||||
<item>7</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="tile_size_titles">
|
||||
<item>Tiny</item>
|
||||
<item>Small</item>
|
||||
<item>Medium</item>
|
||||
<item>Large</item>
|
||||
<item>Default</item>
|
||||
</string-array>
|
||||
<string-array name="tile_size_divisor">
|
||||
<item>6</item>
|
||||
<item>5</item>
|
||||
<item>4</item>
|
||||
<item>3</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
<!-- Add by MFO -->
|
||||
<string-array name="aa_tab_titles">
|
||||
<item>Do not display</item>
|
||||
|
||||
@@ -450,6 +450,7 @@
|
||||
<string name="settings_sync_starred_tracks_for_offline_use_summary">If enabled, starred tracks will be downloaded for offline use.</string>
|
||||
<string name="settings_sync_starred_tracks_for_offline_use_title">Sync starred tracks for offline use</string>
|
||||
<string name="settings_theme">Theme</string>
|
||||
<string name="settings_tile_size">Tiles size</string>
|
||||
<string name="settings_title_data">Data</string>
|
||||
<string name="settings_title_general">General</string>
|
||||
<string name="settings_title_playlist">Playlist</string>
|
||||
|
||||
@@ -54,6 +54,15 @@
|
||||
android:defaultValue="false"
|
||||
android:key="always_on_display" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="2"
|
||||
app:dialogTitle="@string/settings_tile_size"
|
||||
app:entries="@array/tile_size_titles"
|
||||
app:entryValues="@array/tile_size_divisor"
|
||||
app:key="tile_size"
|
||||
app:title="@string/settings_tile_size"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<SwitchPreference
|
||||
android:title="@string/settings_enable_drawer_on_landscape"
|
||||
android:key="enable_drawer_on_portrait"
|
||||
@@ -146,16 +155,7 @@
|
||||
android:defaultValue="false"
|
||||
android:summary="@string/search_sort_summary"
|
||||
android:key="sort_search_chronologically" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="4"
|
||||
app:dialogTitle="@string/settings_title_ui_landscape_items_per_row_dialog"
|
||||
app:entries="@array/landscape_items_per_row"
|
||||
app:entryValues="@array/landscape_items_per_row_values"
|
||||
app:key="landscape_items_per_row"
|
||||
android:summary="@string/settings_summary_landscape_items_per_row"
|
||||
app:title="@string/settings_title_ui_landscape_items_per_row" />
|
||||
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/settings_title_playlist">
|
||||
|
||||
Reference in New Issue
Block a user