coil: fix mosaics on odd image sizes

Round the image sizes we use for our mosaics so that they are even.
Previously we didn't, and that resulted in bad mosaics being created.
This commit is contained in:
OxygenCobalt 2021-11-26 11:41:01 -07:00
parent c0b2dee3ff
commit 14c9b81532
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 10 additions and 9 deletions

View file

@ -126,7 +126,7 @@ abstract class AuxioFetcher : Fetcher {
context, MediaItem.fromUri(uri) context, MediaItem.fromUri(uri)
) )
// future.get is a blocking call that makes the us spin until the future is done. // future.get is a blocking call that makes us spin until the future is done.
// This is bad for a co-routine, as it prevents cancellation and by extension // This is bad for a co-routine, as it prevents cancellation and by extension
// messes with the image loading process and causes frustrating bugs. // messes with the image loading process and causes frustrating bugs.
// To fix this we wrap this around in a withContext call to make it suspend and make // To fix this we wrap this around in a withContext call to make it suspend and make
@ -212,10 +212,11 @@ abstract class AuxioFetcher : Fetcher {
} }
} }
// Use whatever size coil gives us to create the mosaic. If there is no size, default // Use whatever size coil gives us to create the mosaic, rounding it to even so that we
// to a 512x512 mosaic. // get a symmetrical mosaic [and to prevent bugs]. If there is no size, default to a
// 512x512 mosaic.
val mosaicSize = when (size) { val mosaicSize = when (size) {
is PixelSize -> size is PixelSize -> PixelSize(size.width.roundEven(), size.height.roundEven())
else -> PixelSize(512, 512) else -> PixelSize(512, 512)
} }
@ -263,4 +264,6 @@ abstract class AuxioFetcher : Fetcher {
dataSource = DataSource.DISK dataSource = DataSource.DISK
) )
} }
private fun Int.roundEven(): Int = if (mod(2) != 0) inc() else this
} }

View file

@ -205,7 +205,7 @@ class MusicStore private constructor() {
*/ */
fun requireInstance(): MusicStore { fun requireInstance(): MusicStore {
return requireNotNull(maybeGetInstance()) { return requireNotNull(maybeGetInstance()) {
"MusicStore instance was not loaded or loading failed." "Required MusicStore instance was not available."
} }
} }

View file

@ -145,8 +145,6 @@ class PlaybackFragment : Fragment() {
} }
} }
logD(resources.configuration.smallestScreenWidthDp)
logD("Fragment Created.") logD("Fragment Created.")
return binding.root return binding.root

View file

@ -245,7 +245,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
private fun playWithUriInternal(uri: Uri, context: Context) { private fun playWithUriInternal(uri: Uri, context: Context) {
logD("Playing with uri $uri") logD("Playing with uri $uri")
val musicStore = MusicStore.requireInstance() val musicStore = MusicStore.maybeGetInstance() ?: return
musicStore.findSongForUri(uri, context.contentResolver)?.let { song -> musicStore.findSongForUri(uri, context.contentResolver)?.let { song ->
playSong(song) playSong(song)

View file

@ -22,10 +22,10 @@
<string name="lbl_sort">Sort</string> <string name="lbl_sort">Sort</string>
<string name="lbl_sort_name">Name</string> <string name="lbl_sort_name">Name</string>
<string name="lbl_sort_asc">Ascending</string>
<string name="lbl_sort_artist">Artist</string> <string name="lbl_sort_artist">Artist</string>
<string name="lbl_sort_album">Album</string> <string name="lbl_sort_album">Album</string>
<string name="lbl_sort_year">Year</string> <string name="lbl_sort_year">Year</string>
<string name="lbl_sort_asc">Ascending</string>
<string name="lbl_playback">Now Playing</string> <string name="lbl_playback">Now Playing</string>
<string name="lbl_play">Play</string> <string name="lbl_play">Play</string>