Add option to not load cover art
Add an option to not load cover art whatsoever.
This commit is contained in:
parent
d7087fe0b1
commit
39ba1c38ec
7 changed files with 117 additions and 9 deletions
|
@ -17,16 +17,29 @@ import org.oxycblt.auxio.music.Genre
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.settings.SettingsManager
|
import org.oxycblt.auxio.settings.SettingsManager
|
||||||
|
|
||||||
|
// TODO: Stop disk caching
|
||||||
|
|
||||||
|
// SettingsManager is lazy-initted to prevent it from being used before its initialized.
|
||||||
|
val settingsManager: SettingsManager by lazy {
|
||||||
|
SettingsManager.getInstance()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a bitmap for a song. onDone will be called when the bitmap is loaded.
|
* Get a bitmap for a song. onDone will be called when the bitmap is loaded.
|
||||||
* **Do not use this on the UI elements, instead use the Binding Adapters.**
|
* **Do not use this on the UI elements, instead use the Binding Adapters.**
|
||||||
* @param context [Context] required
|
* @param context [Context] required
|
||||||
* @param song Song to load the cover for
|
* @param song Song to load the cover for
|
||||||
* @param onDone What to do with the bitmap when the loading is finished. Bitmap will be null if loading failed.
|
* @param onDone What to do with the bitmap when the loading is finished. Bitmap will be null if loading failed/shouldnt occur.
|
||||||
*/
|
*/
|
||||||
fun getBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
|
fun getBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
|
||||||
|
if (!settingsManager.showCovers) {
|
||||||
|
onDone(null)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val request = ImageRequest.Builder(context)
|
val request = ImageRequest.Builder(context)
|
||||||
.data(song.album.coverUri)
|
.doCoverSetup(context, song)
|
||||||
.target(onError = { onDone(null) }, onSuccess = { onDone(it.toBitmap()) })
|
.target(onError = { onDone(null) }, onSuccess = { onDone(it.toBitmap()) })
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
@ -40,9 +53,14 @@ fun getBitmap(context: Context, song: Song, onDone: (Bitmap?) -> Unit) {
|
||||||
*/
|
*/
|
||||||
@BindingAdapter("coverArt")
|
@BindingAdapter("coverArt")
|
||||||
fun ImageView.bindCoverArt(song: Song) {
|
fun ImageView.bindCoverArt(song: Song) {
|
||||||
|
if (!settingsManager.showCovers) {
|
||||||
|
setImageResource(R.drawable.ic_song)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val request = getDefaultRequest()
|
val request = getDefaultRequest()
|
||||||
.error(R.drawable.ic_song)
|
|
||||||
.doCoverSetup(context, song)
|
.doCoverSetup(context, song)
|
||||||
|
.error(R.drawable.ic_song)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
Coil.imageLoader(context).enqueue(request)
|
Coil.imageLoader(context).enqueue(request)
|
||||||
|
@ -53,9 +71,14 @@ fun ImageView.bindCoverArt(song: Song) {
|
||||||
*/
|
*/
|
||||||
@BindingAdapter("coverArt")
|
@BindingAdapter("coverArt")
|
||||||
fun ImageView.bindCoverArt(album: Album) {
|
fun ImageView.bindCoverArt(album: Album) {
|
||||||
|
if (!settingsManager.showCovers) {
|
||||||
|
setImageResource(R.drawable.ic_album)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val request = getDefaultRequest()
|
val request = getDefaultRequest()
|
||||||
.error(R.drawable.ic_album)
|
|
||||||
.doCoverSetup(context, album)
|
.doCoverSetup(context, album)
|
||||||
|
.error(R.drawable.ic_album)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
Coil.imageLoader(context).enqueue(request)
|
Coil.imageLoader(context).enqueue(request)
|
||||||
|
@ -66,6 +89,10 @@ fun ImageView.bindCoverArt(album: Album) {
|
||||||
*/
|
*/
|
||||||
@BindingAdapter("artistImage")
|
@BindingAdapter("artistImage")
|
||||||
fun ImageView.bindArtistImage(artist: Artist) {
|
fun ImageView.bindArtistImage(artist: Artist) {
|
||||||
|
if (!settingsManager.showCovers) {
|
||||||
|
setImageResource(R.drawable.ic_artist)
|
||||||
|
return
|
||||||
|
}
|
||||||
val request: ImageRequest
|
val request: ImageRequest
|
||||||
|
|
||||||
// If there is more than one album, then create a mosaic of them.
|
// If there is more than one album, then create a mosaic of them.
|
||||||
|
@ -106,6 +133,11 @@ fun ImageView.bindArtistImage(artist: Artist) {
|
||||||
*/
|
*/
|
||||||
@BindingAdapter("genreImage")
|
@BindingAdapter("genreImage")
|
||||||
fun ImageView.bindGenreImage(genre: Genre) {
|
fun ImageView.bindGenreImage(genre: Genre) {
|
||||||
|
if (!settingsManager.showCovers) {
|
||||||
|
setImageResource(R.drawable.ic_genre)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val request: ImageRequest
|
val request: ImageRequest
|
||||||
val genreCovers = mutableListOf<Uri>()
|
val genreCovers = mutableListOf<Uri>()
|
||||||
|
|
||||||
|
@ -144,7 +176,7 @@ fun ImageRequest.Builder.doCoverSetup(context: Context, data: BaseModel): ImageR
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SettingsManager.getInstance().qualityCovers) {
|
if (settingsManager.useQualityCovers) {
|
||||||
fetcher(QualityCoverFetcher(context))
|
fetcher(QualityCoverFetcher(context))
|
||||||
|
|
||||||
if (data is Song) {
|
if (data is Song) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.oxycblt.auxio.playback
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.drawable.AnimatedVectorDrawable
|
import android.graphics.drawable.AnimatedVectorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.TypedValue
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -17,9 +18,11 @@ import org.oxycblt.auxio.databinding.FragmentPlaybackBinding
|
||||||
import org.oxycblt.auxio.detail.DetailViewModel
|
import org.oxycblt.auxio.detail.DetailViewModel
|
||||||
import org.oxycblt.auxio.logD
|
import org.oxycblt.auxio.logD
|
||||||
import org.oxycblt.auxio.playback.state.LoopMode
|
import org.oxycblt.auxio.playback.state.LoopMode
|
||||||
|
import org.oxycblt.auxio.settings.SettingsManager
|
||||||
import org.oxycblt.auxio.ui.accent
|
import org.oxycblt.auxio.ui.accent
|
||||||
import org.oxycblt.auxio.ui.memberBinding
|
import org.oxycblt.auxio.ui.memberBinding
|
||||||
import org.oxycblt.auxio.ui.toColor
|
import org.oxycblt.auxio.ui.toColor
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [Fragment] that displays more information about the song, along with more media controls.
|
* A [Fragment] that displays more information about the song, along with more media controls.
|
||||||
|
@ -38,6 +41,7 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||||
private val accentColor: ColorStateList by lazy {
|
private val accentColor: ColorStateList by lazy {
|
||||||
ColorStateList.valueOf(accent.first.toColor(requireContext()))
|
ColorStateList.valueOf(accent.first.toColor(requireContext()))
|
||||||
}
|
}
|
||||||
|
|
||||||
private val controlColor: ColorStateList by lazy {
|
private val controlColor: ColorStateList by lazy {
|
||||||
ColorStateList.valueOf(R.color.control_color.toColor(requireContext()))
|
ColorStateList.valueOf(R.color.control_color.toColor(requireContext()))
|
||||||
}
|
}
|
||||||
|
@ -61,6 +65,12 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||||
)
|
)
|
||||||
|
|
||||||
val queueMenuItem: MenuItem
|
val queueMenuItem: MenuItem
|
||||||
|
val showCoverArt = SettingsManager.getInstance().showCovers
|
||||||
|
|
||||||
|
val paddingPixels = TypedValue.applyDimension(
|
||||||
|
TypedValue.COMPLEX_UNIT_DIP, 64F,
|
||||||
|
requireContext().resources.displayMetrics
|
||||||
|
).roundToInt()
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
|
@ -97,6 +107,10 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||||
|
|
||||||
binding.song = it
|
binding.song = it
|
||||||
binding.playbackSeekBar.max = it.seconds.toInt()
|
binding.playbackSeekBar.max = it.seconds.toInt()
|
||||||
|
|
||||||
|
if (!showCoverArt) {
|
||||||
|
binding.playbackCover.setImageResource(R.drawable.ic_album)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logD("No song is being played, leaving.")
|
logD("No song is being played, leaving.")
|
||||||
|
|
||||||
|
|
|
@ -319,6 +319,22 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
startForegroundOrNotify("Notif action update")
|
startForegroundOrNotify("Notif action update")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onShowCoverUpdate(showCovers: Boolean) {
|
||||||
|
playbackManager.song?.let {
|
||||||
|
notification.setMetadata(this, it, settingsManager.colorizeNotif) {
|
||||||
|
startForegroundOrNotify("Cover update")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onQualityCoverUpdate(doQualityCovers: Boolean) {
|
||||||
|
playbackManager.song?.let { song ->
|
||||||
|
notification.setMetadata(this, song, settingsManager.colorizeNotif) {
|
||||||
|
startForegroundOrNotify("Quality cover update")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- OTHER FUNCTIONS ---
|
// --- OTHER FUNCTIONS ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -105,10 +105,26 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsManager.Keys.KEY_SHOW_COVERS -> {
|
||||||
|
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
|
||||||
|
Coil.imageLoader(requireContext()).apply {
|
||||||
|
bitmapPool.clear()
|
||||||
|
memoryCache.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
requireActivity().recreate()
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SettingsManager.Keys.KEY_QUALITY_COVERS -> {
|
SettingsManager.Keys.KEY_QUALITY_COVERS -> {
|
||||||
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
|
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
|
||||||
// Clear out any cached images, before recreating the activity
|
// Clear out any cached images, before recreating the activity
|
||||||
Coil.imageLoader(requireContext()).bitmapPool.clear()
|
Coil.imageLoader(requireContext()).apply {
|
||||||
|
bitmapPool.clear()
|
||||||
|
memoryCache.clear()
|
||||||
|
}
|
||||||
|
|
||||||
requireActivity().recreate()
|
requireActivity().recreate()
|
||||||
|
|
||||||
|
|
|
@ -73,10 +73,17 @@ class SettingsManager private constructor(context: Context) :
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to even loading embedded covers
|
||||||
|
* TODO: Make the UI result of this better
|
||||||
|
*/
|
||||||
|
val showCovers: Boolean
|
||||||
|
get() = sharedPrefs.getBoolean(Keys.KEY_SHOW_COVERS, true)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to ignore MediaStore covers
|
* Whether to ignore MediaStore covers
|
||||||
*/
|
*/
|
||||||
val qualityCovers: Boolean
|
val useQualityCovers: Boolean
|
||||||
get() = sharedPrefs.getBoolean(Keys.KEY_QUALITY_COVERS, false)
|
get() = sharedPrefs.getBoolean(Keys.KEY_QUALITY_COVERS, false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,6 +178,14 @@ class SettingsManager private constructor(context: Context) :
|
||||||
Keys.KEY_LIBRARY_DISPLAY_MODE -> callbacks.forEach {
|
Keys.KEY_LIBRARY_DISPLAY_MODE -> callbacks.forEach {
|
||||||
it.onLibDisplayModeUpdate(libraryDisplayMode)
|
it.onLibDisplayModeUpdate(libraryDisplayMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Keys.KEY_SHOW_COVERS -> callbacks.forEach {
|
||||||
|
it.onShowCoverUpdate(showCovers)
|
||||||
|
}
|
||||||
|
|
||||||
|
Keys.KEY_QUALITY_COVERS -> callbacks.forEach {
|
||||||
|
it.onQualityCoverUpdate(useQualityCovers)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,10 +225,11 @@ class SettingsManager private constructor(context: Context) :
|
||||||
const val KEY_THEME = "KEY_THEME"
|
const val KEY_THEME = "KEY_THEME"
|
||||||
const val KEY_ACCENT = "KEY_ACCENT"
|
const val KEY_ACCENT = "KEY_ACCENT"
|
||||||
const val KEY_EDGE_TO_EDGE = "KEY_EDGE"
|
const val KEY_EDGE_TO_EDGE = "KEY_EDGE"
|
||||||
|
const val KEY_LIBRARY_DISPLAY_MODE = "KEY_LIBRARY_DISPLAY_MODE"
|
||||||
|
const val KEY_SHOW_COVERS = "KEY_SHOW_COVERS"
|
||||||
|
const val KEY_QUALITY_COVERS = "KEY_QUALITY_COVERS"
|
||||||
const val KEY_COLORIZE_NOTIFICATION = "KEY_COLOR_NOTIF"
|
const val KEY_COLORIZE_NOTIFICATION = "KEY_COLOR_NOTIF"
|
||||||
const val KEY_USE_ALT_NOTIFICATION_ACTION = "KEY_ALT_NOTIF_ACTION"
|
const val KEY_USE_ALT_NOTIFICATION_ACTION = "KEY_ALT_NOTIF_ACTION"
|
||||||
const val KEY_LIBRARY_DISPLAY_MODE = "KEY_LIBRARY_DISPLAY_MODE"
|
|
||||||
const val KEY_QUALITY_COVERS = "KEY_QUALITY_COVERS"
|
|
||||||
const val KEY_AUDIO_FOCUS = "KEY_AUDIO_FOCUS"
|
const val KEY_AUDIO_FOCUS = "KEY_AUDIO_FOCUS"
|
||||||
const val KEY_PLUG_MANAGEMENT = "KEY_PLUG_MGT"
|
const val KEY_PLUG_MANAGEMENT = "KEY_PLUG_MGT"
|
||||||
const val KEY_SONG_PLAYBACK_MODE = "KEY_SONG_PLAY_MODE"
|
const val KEY_SONG_PLAYBACK_MODE = "KEY_SONG_PLAY_MODE"
|
||||||
|
@ -259,5 +275,7 @@ class SettingsManager private constructor(context: Context) :
|
||||||
fun onColorizeNotifUpdate(doColorize: Boolean) {}
|
fun onColorizeNotifUpdate(doColorize: Boolean) {}
|
||||||
fun onNotifActionUpdate(useAltAction: Boolean) {}
|
fun onNotifActionUpdate(useAltAction: Boolean) {}
|
||||||
fun onLibDisplayModeUpdate(displayMode: DisplayMode) {}
|
fun onLibDisplayModeUpdate(displayMode: DisplayMode) {}
|
||||||
|
fun onShowCoverUpdate(showCovers: Boolean) {}
|
||||||
|
fun onQualityCoverUpdate(doQualityCovers: Boolean) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,9 @@
|
||||||
<string name="setting_color_notif">Colorize notification</string>]
|
<string name="setting_color_notif">Colorize notification</string>]
|
||||||
<string name="setting_color_desc">Show album art on notification</string>
|
<string name="setting_color_desc">Show album art on notification</string>
|
||||||
|
|
||||||
|
<string name="setting_show_covers">Show album covers</string>
|
||||||
|
<string name="setting_show_covers_desc">Turn off to save memory usage</string>
|
||||||
|
|
||||||
<string name="setting_quality_covers">Ignore MediaStore covers</string>
|
<string name="setting_quality_covers">Ignore MediaStore covers</string>
|
||||||
<string name="setting_quality_covers_desc">Results in higher quality album covers, but causes slower loading times</string>
|
<string name="setting_quality_covers_desc">Results in higher quality album covers, but causes slower loading times</string>
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,19 @@
|
||||||
app:key="KEY_LIBRARY_DISPLAY_MODE"
|
app:key="KEY_LIBRARY_DISPLAY_MODE"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:title="@string/setting_show_covers"
|
||||||
|
app:defaultValue="true"
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
app:key="KEY_SHOW_COVERS"
|
||||||
|
app:summary="@string/setting_show_covers_desc" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:title="@string/setting_quality_covers"
|
android:title="@string/setting_quality_covers"
|
||||||
app:summary="@string/setting_quality_covers_desc"
|
app:summary="@string/setting_quality_covers_desc"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:key="KEY_QUALITY_COVERS"
|
app:key="KEY_QUALITY_COVERS"
|
||||||
|
app:dependency="KEY_SHOW_COVERS"
|
||||||
app:defaultValue="false" />
|
app:defaultValue="false" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
|
@ -46,6 +54,7 @@
|
||||||
app:defaultValue="true"
|
app:defaultValue="true"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:key="KEY_COLOR_NOTIF"
|
app:key="KEY_COLOR_NOTIF"
|
||||||
|
app:dependency="KEY_SHOW_COVERS"
|
||||||
app:summary="@string/setting_color_desc" />
|
app:summary="@string/setting_color_desc" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
|
|
Loading…
Reference in a new issue