Centralization in CustomGlideRequest of the corner rounding setting for images

This commit is contained in:
antonio 2023-03-16 19:47:39 +01:00
parent afa5375675
commit 1ac6ab3e3c
32 changed files with 99 additions and 106 deletions

View file

@ -9,6 +9,9 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.signature.ObjectKey;
import com.cappielloantonio.play.App;
@ -20,7 +23,8 @@ import java.util.Map;
public class CustomGlideRequest {
private static final String TAG = "CustomGlideRequest";
public static final int CORNER_RADIUS = 12;
public static final int CORNER_RADIUS = Preferences.isCornerRoundingEnabled() ? Preferences.getRoundedCornerSize() : 1;
//public static final int CORNER_RADIUS = 12;
public static final DiskCacheStrategy DEFAULT_DISK_CACHE_STRATEGY = DiskCacheStrategy.ALL;
@ -31,7 +35,7 @@ public class CustomGlideRequest {
.error(new ColorDrawable(SurfaceColors.SURFACE_5.getColor(context)))
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
.signature(new ObjectKey(item != null ? item : 0))
.centerCrop();
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS));
}
public static String createUrl(String item, int size) {
@ -83,7 +87,9 @@ public class CustomGlideRequest {
}
public RequestBuilder<Drawable> build() {
return requestManager.load(item);
return requestManager
.load(item)
.transition(DrawableTransitionOptions.withCrossFade());
}
}
}

View file

@ -47,8 +47,6 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), album.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.albumCoverImageView);
}

View file

@ -47,8 +47,6 @@ public class AlbumArtistPageOrSimilarAdapter extends RecyclerView.Adapter<AlbumA
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), album.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.artistPageAlbumCoverImageView);
}

View file

@ -82,8 +82,6 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), album.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.albumCatalogueCoverImageView);
}

View file

@ -49,8 +49,6 @@ public class AlbumHorizontalAdapter extends RecyclerView.Adapter<AlbumHorizontal
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), album.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.albumCoverImageView);
}

View file

@ -52,8 +52,6 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), artist.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.artistCoverImageView);
}

View file

@ -82,8 +82,6 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), artist.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.artistCatalogueCoverImageView);
}

View file

@ -53,8 +53,6 @@ public class ArtistHorizontalAdapter extends RecyclerView.Adapter<ArtistHorizont
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), artist.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.artistCoverImageView);
}

View file

@ -46,8 +46,6 @@ public class ArtistSimilarAdapter extends RecyclerView.Adapter<ArtistSimilarAdap
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), artist.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.similarArtistCoverImageView);
}

View file

@ -8,6 +8,8 @@ import android.view.animation.AccelerateDecelerateInterpolator;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.cappielloantonio.play.databinding.ItemHomeDiscoverSongBinding;
import com.cappielloantonio.play.glide.CustomGlideRequest;
@ -46,7 +48,6 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), song.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.into(holder.item.discoverSongCoverImageView);
}

View file

@ -44,8 +44,6 @@ public class GridTrackAdapter extends RecyclerView.Adapter<GridTrackAdapter.View
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), item.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.trackCoverImageView);
}

View file

@ -53,8 +53,6 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), song.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.queueSongCoverImageView);
MediaManager.getCurrentIndex(mediaBrowserListenableFuture, index -> {

View file

@ -42,8 +42,6 @@ public class PlaylistDialogSongHorizontalAdapter extends RecyclerView.Adapter<Pl
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), song.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.playlistDialogSongCoverImageView);
}

View file

@ -84,8 +84,6 @@ public class PlaylistHorizontalAdapter extends RecyclerView.Adapter<PlaylistHori
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), playlist.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.playlistCoverImageView);
}

View file

@ -52,8 +52,6 @@ public class PodcastEpisodeAdapter extends RecyclerView.Adapter<PodcastEpisodeAd
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), podcastEpisode.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.podcastCoverImageView);
}

View file

@ -46,8 +46,6 @@ public class SimilarTrackAdapter extends RecyclerView.Adapter<SimilarTrackAdapte
CustomGlideRequest.Builder
.from(holder.itemView.getContext(), song.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.trackCoverImageView);
}

View file

@ -63,8 +63,6 @@ public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAd
if (isCoverVisible) CustomGlideRequest.Builder
.from(holder.itemView.getContext(), song.getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(holder.item.songCoverImageView);
if (isCoverVisible) holder.item.trackNumberTextView.setVisibility(View.INVISIBLE);

View file

@ -177,8 +177,6 @@ public class AlbumPageFragment extends Fragment implements ClickCallback {
CustomGlideRequest.Builder
.from(requireContext(), albumPageViewModel.getAlbum().getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(bind.albumCoverImageView);
}

View file

@ -122,7 +122,6 @@ public class ArtistPageFragment extends Fragment implements ClickCallback {
if (getContext() != null && bind != null) CustomGlideRequest.Builder
.from(requireContext(), artistPageViewModel.getArtist().getId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.into(bind.artistBackdropImageView);
if (bind != null) bind.bioTextView.setText(normalizedBio);

View file

@ -160,8 +160,6 @@ public class PlayerBottomSheetFragment extends Fragment {
CustomGlideRequest.Builder
.from(requireContext(), mediaMetadata.extras.getString("coverArtId"))
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(bind.playerHeaderLayout.playerHeaderMediaCoverImage);
}
}

View file

@ -171,7 +171,6 @@ public class PlayerCoverFragment extends Fragment {
CustomGlideRequest.Builder
.from(requireContext(), mediaMetadata.extras != null ? mediaMetadata.extras.getString("coverArtId") : null)
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.into(bind.nowPlayingSongCoverImageView);
}
}

View file

@ -166,7 +166,6 @@ public class PlaylistPageFragment extends Fragment implements ClickCallback {
CustomGlideRequest.Builder
.from(requireContext(), playlistPageViewModel.getPlaylist().getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.into(bind.playlistCoverImageView);
}

View file

@ -84,8 +84,6 @@ public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements
CustomGlideRequest.Builder
.from(requireContext(), albumBottomSheetViewModel.getAlbum().getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(coverAlbum);
TextView titleAlbum = view.findViewById(R.id.album_title_text_view);

View file

@ -75,8 +75,6 @@ public class ArtistBottomSheetDialog extends BottomSheetDialogFragment implement
CustomGlideRequest.Builder
.from(requireContext(), artistBottomSheetViewModel.getArtist().getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(coverArtist);
TextView nameArtist = view.findViewById(R.id.song_title_text_view);

View file

@ -70,8 +70,6 @@ public class PodcastBottomSheetDialog extends BottomSheetDialogFragment implemen
CustomGlideRequest.Builder
.from(requireContext(), podcastBottomSheetViewModel.getPodcast().getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(coverPodcast);
TextView titlePodcast = view.findViewById(R.id.podcast_title_text_view);

View file

@ -79,8 +79,6 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements
CustomGlideRequest.Builder
.from(requireContext(), songBottomSheetViewModel.getSong().getCoverArtId())
.build()
.transition(DrawableTransitionOptions.withCrossFade())
.transform(new CenterCrop(), new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
.into(coverSong);
TextView titleSong = view.findViewById(R.id.song_title_text_view);

View file

@ -25,6 +25,8 @@ object Preferences {
private const val SYNC_STARRED_TRACKS_FOR_OFFLINE_USE = "sync_starred_tracks_for_offline_use"
private const val QUEUE_SYNCING = "queue_syncing"
private const val QUEUE_SYNCING_COUNTDOWN = "queue_syncing_countdown"
private const val ROUNDED_CORNER = "rounded_corner"
private const val ROUNDED_CORNER_SIZE = "rounded_corner_size"
@JvmStatic
fun getServer(): String? {
@ -195,4 +197,14 @@ object Preferences {
fun getSyncCountdownTimer(): Int {
return App.getInstance().preferences.getString(QUEUE_SYNCING_COUNTDOWN, "5")!!.toInt()
}
@JvmStatic
fun isCornerRoundingEnabled(): Boolean {
return App.getInstance().preferences.getBoolean(ROUNDED_CORNER, false)
}
@JvmStatic
fun getRoundedCornerSize(): Int {
return App.getInstance().preferences.getString(ROUNDED_CORNER_SIZE, "12")!!.toInt()
}
}

View file

@ -155,7 +155,8 @@
android:layout_width="match_parent"
android:layout_height="212dp"
android:clipToPadding="false"
android:paddingBottom="8dp" />
android:paddingTop="8dp"
android:paddingBottom="16dp" />
</LinearLayout>
<include

View file

@ -1,56 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="4dp">
android:paddingHorizontal="16dp">
<ImageView
android:id="@+id/discover_song_cover_image_view"
android:layout_width="match_parent"
android:layout_height="196dp" />
<View
android:layout_width="match_parent"
android:layout_height="196dp"
android:background="@drawable/gradient_discover_background_image" />
android:foreground="@drawable/gradient_discover_background_image" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="196dp">
<TextView
android:id="@+id/title_discover_song_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="18dp"
android:layout_marginRight="16dp"
android:ellipsize="end"
android:fontFamily="@font/inter"
android:maxLines="2"
android:textColor="@color/gradientTitleColor"
android:textFontWeight="400"
android:textSize="20sp" />
<TextView
android:id="@+id/title_discover_song_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="18dp"
android:layout_marginRight="16dp"
android:ellipsize="end"
android:fontFamily="@font/inter"
android:maxLines="2"
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_height="wrap_content"
android:layout_below="@id/title_discover_song_label"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:drawablePadding="10dp"
android:ellipsize="end"
android:fontFamily="@font/inter"
android:maxLines="1"
android:textColor="@color/gradientSubtitleColor"
android:textFontWeight="400"
android:textSize="14sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/album_discover_song_label"
android:layout_width="wrap_content"
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:ellipsize="end"
android:fontFamily="@font/inter"
android:maxLines="1"
android:textColor="@color/gradientSubtitleColor"
android:textFontWeight="400"
android:textSize="14sp" />
</RelativeLayout>

View file

@ -130,4 +130,15 @@
<item>5</item>
<item>2</item>
</string-array>
<string-array name="rounded_corner_size_titles">
<item>High</item>
<item>Medium</item>
<item>Low</item>
</string-array>
<string-array name="rounded_corner_size_values">
<item>18</item>
<item>12</item>
<item>6</item>
</string-array>
</resources>

View file

@ -159,6 +159,10 @@
<string name="settings_queue_syncing_title">Sync play queue for this user</string>
<string name="settings_queue_syncing_countdown">Sync timer</string>
<string name="settings_queue_syncing_summary">If enabled, the user will have the ability to save their play queue and will have the ability to load state when opening the application.</string>
<string name="settings_rounded_corner">Rounded corners</string>
<string name="settings_rounded_corner_summary">If enabled, sets a curvature angle for all rendered covers. The changes will take effect on restart.</string>
<string name="settings_rounded_corner_size">Corners size</string>
<string name="settings_rounded_corner_size_summary">Sets the magnitude of the curvature angle.</string>
<string name="settings_scan_title">Scan library</string>
<string name="settings_summary_syncing">Returns the state of the play queue for this user. This includes the tracks in the play queue, the currently playing track, and the position within this track. The server must support this feature.</string>
<string name="settings_summary_transcoding">Priority given to the transcoding mode. If set to \"Direct play\" the bitrate of the file will not be changed.</string>
@ -169,10 +173,11 @@
<string name="settings_title_general">General</string>
<string name="settings_title_syncing">Syncing</string>
<string name="settings_title_transcoding">Transcoding</string>
<string name="settings_title_ui">UI</string>
<string name="settings_version_summary">3.1.0</string>
<string name="settings_version_title">Version</string>
<string name="settings_wifi_only_title">Stream via Wi-Fi only alert</string>
<string name="settings_wifi_only_summary">Ask for user confirmation before streaming over mobile network</string>
<string name="settings_wifi_only_summary">Ask for user confirmation before streaming over mobile network.</string>
<string name="song_bottom_sheet_add_to_playlist">Add to playlist</string>
<string name="song_bottom_sheet_add_to_queue">Add to queue</string>
<string name="song_bottom_sheet_download">Download</string>

View file

@ -1,15 +1,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/settings_title_general">
<ListPreference
app:defaultValue="default"
app:dialogTitle="@string/settings_theme"
app:entries="@array/theme_list_titles"
app:entryValues="@array/theme_list_values"
app:key="theme"
app:title="@string/settings_theme"
app:useSimpleSummaryProvider="true" />
<Preference
android:key="equalizer"
android:title="@string/settings_equalizer_title"
@ -24,6 +15,32 @@
android:title="@string/settings_logout_title"/>
</PreferenceCategory>
<PreferenceCategory app:title="@string/settings_title_ui">
<ListPreference
app:defaultValue="default"
app:dialogTitle="@string/settings_theme"
app:entries="@array/theme_list_titles"
app:entryValues="@array/theme_list_values"
app:key="theme"
app:title="@string/settings_theme"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
android:title="@string/settings_rounded_corner"
android:defaultValue="true"
android:summary="@string/settings_rounded_corner_summary"
android:key="rounded_corner" />
<ListPreference
app:defaultValue="6"
app:dialogTitle="@string/settings_rounded_corner_size"
app:entries="@array/rounded_corner_size_titles"
app:entryValues="@array/rounded_corner_size_values"
app:key="rounded_corner_size"
app:title="@string/settings_rounded_corner_size"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/settings_title_data">
<ListPreference
app:defaultValue="500"