update cover color state when set cover in reader
This commit is contained in:
parent
c28b290f24
commit
ddc7801436
5 changed files with 16 additions and 15 deletions
|
|
@ -34,7 +34,7 @@ object MangaCoverMetadata {
|
|||
}.toMap(),
|
||||
)
|
||||
val colors = preferences.coverColors().get()
|
||||
MangaCover.coverColorMap = ConcurrentHashMap(
|
||||
MangaCover.dominantCoverColorMap = ConcurrentHashMap(
|
||||
colors.mapNotNull {
|
||||
val splits = it.split("|")
|
||||
val id = splits.firstOrNull()?.toLongOrNull()
|
||||
|
|
@ -54,7 +54,7 @@ object MangaCoverMetadata {
|
|||
* It's called along with [MangaCoverFetcher.fetch] everytime a cover is **displayed** (anywhere).
|
||||
*
|
||||
* When called:
|
||||
* - It removes saved colors from saved Prefs of [MangaCover.coverColorMap] if manga is not favorite.
|
||||
* - It removes saved colors from saved Prefs of [MangaCover.dominantCoverColorMap] if manga is not favorite.
|
||||
* - If a favorite manga already restored [MangaCover.dominantCoverColors] then it
|
||||
* will skip actually reading bitmap, only extract ratio. Except when [MangaCover.vibrantCoverColor]
|
||||
* is not loaded then it will read bitmap & extract vibrant color.
|
||||
|
|
@ -145,13 +145,13 @@ object MangaCoverMetadata {
|
|||
|
||||
fun MangaCover.remove() {
|
||||
MangaCover.coverRatioMap.remove(mangaId)
|
||||
MangaCover.coverColorMap.remove(mangaId)
|
||||
MangaCover.dominantCoverColorMap.remove(mangaId)
|
||||
}
|
||||
|
||||
fun savePrefs() {
|
||||
val mapCopy = MangaCover.coverRatioMap.toMap()
|
||||
preferences.coverRatios().set(mapCopy.map { "${it.key}|${it.value}" }.toSet())
|
||||
val mapColorCopy = MangaCover.coverColorMap.toMap()
|
||||
val mapColorCopy = MangaCover.dominantCoverColorMap.toMap()
|
||||
preferences.coverColors().set(mapColorCopy.map { "${it.key}|${it.value.first}|${it.value.second}" }.toSet())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import androidx.compose.runtime.getValue
|
|||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
|
|
@ -159,7 +158,6 @@ class MangaScreen(
|
|||
}
|
||||
|
||||
val uiPreferences = remember { Injekt.get<UiPreferences>() }
|
||||
val seedColorState = rememberUpdatedState(newValue = successState.seedColor)
|
||||
|
||||
val content = @Composable {
|
||||
val slideDistance = rememberSlideDistance()
|
||||
|
|
@ -196,7 +194,7 @@ class MangaScreen(
|
|||
}
|
||||
}
|
||||
|
||||
val seedColor = seedColorState.value
|
||||
val seedColor = successState.seedColor
|
||||
if (uiPreferences.themeCoverBased().get() && seedColor != null) {
|
||||
DynamicMaterialTheme(
|
||||
seedColor = seedColor,
|
||||
|
|
|
|||
|
|
@ -513,6 +513,9 @@ class MangaScreenModel(
|
|||
}
|
||||
val vibrantColor = it.getBestColor() ?: return@launchUI
|
||||
mangaCover.vibrantCoverColor = vibrantColor
|
||||
updateSuccessState {
|
||||
it.copy(seedColor = Color(vibrantColor))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1887,11 +1890,10 @@ class MangaScreenModel(
|
|||
* a list of <keyword, related mangas>
|
||||
*/
|
||||
val relatedMangaCollection: List<RelatedManga>? = null,
|
||||
val seedColor: Color? = manga.asMangaCover().vibrantCoverColor?.let { Color(it) }
|
||||
// KMK <--
|
||||
) : State {
|
||||
// KMK -->
|
||||
val seedColor: Color? = MangaCover.vibrantCoverColorMap[manga.id]?.let { Color(it) }
|
||||
|
||||
/**
|
||||
* a value of null will be treated as still loading, so if all searching were failed and won't update
|
||||
* 'relatedMangaCollection` then we should return empty list
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ data class MangaCover(
|
|||
* [dominantCoverColors] is used to set cover/text's color in Library (Favorite) grid view.
|
||||
* It contains only color for in-library (favorite) mangas.
|
||||
*
|
||||
* It reads/saves to a hashmap in [MangaCover.coverColorMap].
|
||||
* It reads/saves to a hashmap in [MangaCover.dominantCoverColorMap].
|
||||
*
|
||||
* Format: <first: cover color, second: text color>.
|
||||
*
|
||||
|
|
@ -54,10 +54,10 @@ data class MangaCover(
|
|||
*/
|
||||
@Suppress("KDocUnresolvedReference")
|
||||
var dominantCoverColors: Pair<Int, Int>?
|
||||
get() = coverColorMap[mangaId]
|
||||
get() = dominantCoverColorMap[mangaId]
|
||||
set(value) {
|
||||
value ?: return
|
||||
coverColorMap[mangaId] = value.first to value.second
|
||||
dominantCoverColorMap[mangaId] = value.first to value.second
|
||||
}
|
||||
|
||||
var ratio: Float?
|
||||
|
|
@ -66,6 +66,7 @@ data class MangaCover(
|
|||
value ?: return
|
||||
coverRatioMap[mangaId] = value
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* [vibrantCoverColorMap] store color generated while browsing library.
|
||||
|
|
@ -74,13 +75,13 @@ data class MangaCover(
|
|||
val vibrantCoverColorMap: HashMap<Long, Int?> = hashMapOf()
|
||||
|
||||
/**
|
||||
* [coverColorMap] stores favorite manga's cover & text's color as a joined string in Prefs.
|
||||
* [dominantCoverColorMap] stores favorite manga's cover & text's color as a joined string in Prefs.
|
||||
* They will be loaded each time *[App]* is initialized with *[MangaCoverMetadata.load]*.
|
||||
*
|
||||
* They will be saved back when *[MainActivity.onPause]* is triggered.
|
||||
*/
|
||||
@Suppress("KDocUnresolvedReference")
|
||||
var coverColorMap = ConcurrentHashMap<Long, Pair<Int, Int>>()
|
||||
var dominantCoverColorMap = ConcurrentHashMap<Long, Pair<Int, Int>>()
|
||||
|
||||
var coverRatioMap = ConcurrentHashMap<Long, Float>()
|
||||
// KMK <--
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ fun UpdatesWidget(
|
|||
cover = cover,
|
||||
modifier = GlanceModifier.clickable(actionStartActivity(intent)),
|
||||
// KMK -->
|
||||
color = MangaCover.coverColorMap[mangaId]?.first?.let { Color(it) },
|
||||
color = MangaCover.dominantCoverColorMap[mangaId]?.first?.let { Color(it) },
|
||||
// KMK <--
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue