coil: add option to round album covers
Add an option to round album covers for people who might want more visual cohesion with apps that have completely drunken the "Round Everything!" kool-aid. Covers will still be hard-edged by default.
This commit is contained in:
@@ -21,6 +21,7 @@ package org.oxycblt.auxio.coil
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.databinding.BindingAdapter
|
||||
import coil.dispose
|
||||
@@ -28,11 +29,14 @@ import coil.imageLoader
|
||||
import coil.load
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.OriginalSize
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
|
||||
// --- BINDING ADAPTERS ---
|
||||
|
||||
@@ -40,47 +44,40 @@ import org.oxycblt.auxio.music.Song
|
||||
* Bind the album art for a [song].
|
||||
*/
|
||||
@BindingAdapter("albumArt")
|
||||
fun ImageView.bindAlbumArt(song: Song?) {
|
||||
dispose()
|
||||
|
||||
load(song) {
|
||||
error(R.drawable.ic_album)
|
||||
}
|
||||
}
|
||||
fun ImageView.bindAlbumArt(song: Song?) = load(song, R.drawable.ic_album)
|
||||
|
||||
/**
|
||||
* Bind the album art for an [album].
|
||||
*/
|
||||
@BindingAdapter("albumArt")
|
||||
fun ImageView.bindAlbumArt(album: Album?) {
|
||||
dispose()
|
||||
|
||||
load(album) {
|
||||
error(R.drawable.ic_album)
|
||||
}
|
||||
}
|
||||
fun ImageView.bindAlbumArt(album: Album?) = load(album, R.drawable.ic_album)
|
||||
|
||||
/**
|
||||
* Bind the image for an [artist]
|
||||
*/
|
||||
@BindingAdapter("artistImage")
|
||||
fun ImageView.bindArtistImage(artist: Artist?) {
|
||||
dispose()
|
||||
|
||||
load(artist) {
|
||||
error(R.drawable.ic_artist)
|
||||
}
|
||||
}
|
||||
fun ImageView.bindArtistImage(artist: Artist?) = load(artist, R.drawable.ic_artist)
|
||||
|
||||
/**
|
||||
* Bind the image for a [genre]
|
||||
*/
|
||||
@BindingAdapter("genreImage")
|
||||
fun ImageView.bindGenreImage(genre: Genre?) {
|
||||
fun ImageView.bindGenreImage(genre: Genre?) = load(genre, R.drawable.ic_genre)
|
||||
|
||||
fun <T : Music> ImageView.load(music: T?, @DrawableRes error: Int) {
|
||||
dispose()
|
||||
|
||||
load(genre) {
|
||||
error(R.drawable.ic_genre)
|
||||
load(music) {
|
||||
// Round out the corners if it's enabled
|
||||
// We don't do this by default because it's ugly and desecrates album artwork.
|
||||
val settingsManager = SettingsManager.getInstance()
|
||||
|
||||
if (settingsManager.roundCovers) {
|
||||
val radius = resources.getDimension(R.dimen.spacing_small)
|
||||
transformations(RoundedCornersTransformation(radius))
|
||||
}
|
||||
|
||||
error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||
private val minTouchTargetSize: Int = resources.getDimensionPixelSize(R.dimen.size_btn_small)
|
||||
private val touchSlop: Int = ViewConfiguration.get(context).scaledTouchSlop
|
||||
|
||||
// Views for the track, thumb, and popup. Note that the track view is mostly vestigal
|
||||
// Views for the track, thumb, and popup. Note that the track view is mostly vestigial
|
||||
// and is only for bounds checking.
|
||||
private val trackView: View
|
||||
private val thumbView: View
|
||||
@@ -134,21 +134,23 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
|
||||
minimumWidth = resources.getDimensionPixelSize(
|
||||
R.dimen.popup_min_width
|
||||
)
|
||||
|
||||
minimumHeight = resources.getDimensionPixelSize(
|
||||
R.dimen.size_btn_large
|
||||
)
|
||||
|
||||
val layoutParams = layoutParams as FrameLayout.LayoutParams
|
||||
layoutParams.gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP
|
||||
layoutParams.marginEnd = resources.getDimensionPixelOffset(
|
||||
R.dimen.spacing_small
|
||||
)
|
||||
(layoutParams as FrameLayout.LayoutParams).apply {
|
||||
gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP
|
||||
marginEnd = resources.getDimensionPixelOffset(
|
||||
R.dimen.spacing_small
|
||||
)
|
||||
}
|
||||
|
||||
setLayoutParams(layoutParams)
|
||||
TextViewCompat.setTextAppearance(this, R.style.TextAppearance_Auxio_HeadlineLarge)
|
||||
setTextColor(R.attr.colorOnSecondary.resolveAttr(context))
|
||||
|
||||
background = FastScrollPopupDrawable(context)
|
||||
elevation = resources.getDimensionPixelOffset(R.dimen.elevation_normal).toFloat()
|
||||
@@ -156,9 +158,6 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||
gravity = Gravity.CENTER
|
||||
includeFontPadding = false
|
||||
isSingleLine = true
|
||||
|
||||
TextViewCompat.setTextAppearance(this, R.style.TextAppearance_Auxio_HeadlineLarge)
|
||||
setTextColor(R.attr.colorOnSecondary.resolveAttr(context))
|
||||
}
|
||||
|
||||
thumbWidth = thumbDrawable.intrinsicWidth
|
||||
|
||||
@@ -145,7 +145,8 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
||||
}
|
||||
}
|
||||
|
||||
SettingsManager.KEY_SHOW_COVERS, SettingsManager.KEY_QUALITY_COVERS -> {
|
||||
SettingsManager.KEY_SHOW_COVERS, SettingsManager.KEY_QUALITY_COVERS,
|
||||
SettingsManager.KEY_ROUND_COVERS -> {
|
||||
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
|
||||
Coil.imageLoader(requireContext()).apply {
|
||||
this.memoryCache?.clear()
|
||||
|
||||
@@ -90,6 +90,10 @@ class SettingsManager private constructor(context: Context) :
|
||||
val useQualityCovers: Boolean
|
||||
get() = sharedPrefs.getBoolean(KEY_QUALITY_COVERS, false)
|
||||
|
||||
/** Whether to round album covers */
|
||||
val roundCovers: Boolean
|
||||
get() = sharedPrefs.getBoolean(KEY_ROUND_COVERS, false)
|
||||
|
||||
/** Whether to do Audio focus. */
|
||||
val doAudioFocus: Boolean
|
||||
get() = sharedPrefs.getBoolean(KEY_AUDIO_FOCUS, true)
|
||||
@@ -258,6 +262,7 @@ class SettingsManager private constructor(context: Context) :
|
||||
const val KEY_LIB_TABS = "auxio_lib_tabs"
|
||||
const val KEY_SHOW_COVERS = "KEY_SHOW_COVERS"
|
||||
const val KEY_QUALITY_COVERS = "KEY_QUALITY_COVERS"
|
||||
const val KEY_ROUND_COVERS = "auxio_round_covers"
|
||||
const val KEY_USE_ALT_NOTIFICATION_ACTION = "KEY_ALT_NOTIF_ACTION"
|
||||
|
||||
const val KEY_AUDIO_FOCUS = "KEY_AUDIO_FOCUS"
|
||||
|
||||
Reference in New Issue
Block a user