fix(manga/details): Fix "Theme buttons based on cover"

Palette doesn't like copy's bitmap, could be because of mutability is disabled or perhaps because it's set to HARDWARE configured, not entirely sure, because Google didn't document it. Classic Google behaviour :^)
This commit is contained in:
Ahmad Ansori Palembani 2024-08-24 20:30:19 +07:00
parent e9b4292295
commit 889b20797e
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
3 changed files with 10 additions and 9 deletions

View file

@ -11,6 +11,7 @@
-->
## Fixes
- Fixed crashes caused by certain extension implementation
- Fixed "Theme buttons based on cover" doesn't work properly
## Other
- More StorIO to SQLDelight migration effort

View file

@ -586,15 +586,16 @@ class MangaDetailsController :
)
} ?: drawable
val bitmap = (copy as? BitmapDrawable)?.bitmap
// Don't use 'copy', Palette doesn't like its bitmap, could be caused by mutability is disabled,
// or perhaps because it's HARDWARE configured, not entirely sure why, the behaviour is not
// documented by Google.
val bitmap = (drawable as? BitmapDrawable)?.bitmap
// Generate the Palette on a background thread.
if (bitmap != null) {
Palette.from(bitmap).generate {
if (it == null) return@generate
Palette.from(bitmap).generate { palette ->
if (presenter.preferences.themeMangaDetails().get()) {
launchUI {
view.context.getResourceColor(R.attr.colorSecondary)
val vibrantColor = it.getBestColor() ?: return@launchUI
val vibrantColor = palette?.getBestColor() ?: return@launchUI
manga?.vibrantCoverColor = vibrantColor
setAccentColorValue(vibrantColor)
setHeaderColorValue(vibrantColor)

View file

@ -68,14 +68,13 @@ object MangaCoverMetadata {
}
val bitmap = BitmapFactory.decodeFile(file.filePath, options)
if (bitmap != null) {
Palette.from(bitmap).generate {
if (it == null) return@generate
Palette.from(bitmap).generate { palette ->
if (isInLibrary) {
it.dominantSwatch?.let { swatch ->
palette?.dominantSwatch?.let { swatch ->
addCoverColor(mangaId, swatch.rgb, swatch.titleTextColor)
}
}
val color = it.getBestColor() ?: return@generate
val color = palette?.getBestColor() ?: return@generate
setVibrantColor(mangaId, color)
}
}