Skip to content

Commit ddc7801

Browse files
committed
update cover color state when set cover in reader
1 parent c28b290 commit ddc7801

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

app/src/main/java/eu/kanade/tachiyomi/data/coil/MangaCoverMetadata.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object MangaCoverMetadata {
3434
}.toMap(),
3535
)
3636
val colors = preferences.coverColors().get()
37-
MangaCover.coverColorMap = ConcurrentHashMap(
37+
MangaCover.dominantCoverColorMap = ConcurrentHashMap(
3838
colors.mapNotNull {
3939
val splits = it.split("|")
4040
val id = splits.firstOrNull()?.toLongOrNull()
@@ -54,7 +54,7 @@ object MangaCoverMetadata {
5454
* It's called along with [MangaCoverFetcher.fetch] everytime a cover is **displayed** (anywhere).
5555
*
5656
* When called:
57-
* - It removes saved colors from saved Prefs of [MangaCover.coverColorMap] if manga is not favorite.
57+
* - It removes saved colors from saved Prefs of [MangaCover.dominantCoverColorMap] if manga is not favorite.
5858
* - If a favorite manga already restored [MangaCover.dominantCoverColors] then it
5959
* will skip actually reading bitmap, only extract ratio. Except when [MangaCover.vibrantCoverColor]
6060
* is not loaded then it will read bitmap & extract vibrant color.
@@ -145,13 +145,13 @@ object MangaCoverMetadata {
145145

146146
fun MangaCover.remove() {
147147
MangaCover.coverRatioMap.remove(mangaId)
148-
MangaCover.coverColorMap.remove(mangaId)
148+
MangaCover.dominantCoverColorMap.remove(mangaId)
149149
}
150150

151151
fun savePrefs() {
152152
val mapCopy = MangaCover.coverRatioMap.toMap()
153153
preferences.coverRatios().set(mapCopy.map { "${it.key}|${it.value}" }.toSet())
154-
val mapColorCopy = MangaCover.coverColorMap.toMap()
154+
val mapColorCopy = MangaCover.dominantCoverColorMap.toMap()
155155
preferences.coverColors().set(mapColorCopy.map { "${it.key}|${it.value.first}|${it.value.second}" }.toSet())
156156
}
157157
}

app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import androidx.compose.runtime.getValue
1515
import androidx.compose.runtime.mutableStateOf
1616
import androidx.compose.runtime.remember
1717
import androidx.compose.runtime.rememberCoroutineScope
18-
import androidx.compose.runtime.rememberUpdatedState
1918
import androidx.compose.runtime.saveable.rememberSaveable
2019
import androidx.compose.runtime.setValue
2120
import androidx.compose.ui.Modifier
@@ -159,7 +158,6 @@ class MangaScreen(
159158
}
160159

161160
val uiPreferences = remember { Injekt.get<UiPreferences>() }
162-
val seedColorState = rememberUpdatedState(newValue = successState.seedColor)
163161

164162
val content = @Composable {
165163
val slideDistance = rememberSlideDistance()
@@ -196,7 +194,7 @@ class MangaScreen(
196194
}
197195
}
198196

199-
val seedColor = seedColorState.value
197+
val seedColor = successState.seedColor
200198
if (uiPreferences.themeCoverBased().get() && seedColor != null) {
201199
DynamicMaterialTheme(
202200
seedColor = seedColor,

app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ class MangaScreenModel(
513513
}
514514
val vibrantColor = it.getBestColor() ?: return@launchUI
515515
mangaCover.vibrantCoverColor = vibrantColor
516+
updateSuccessState {
517+
it.copy(seedColor = Color(vibrantColor))
518+
}
516519
}
517520
}
518521
}
@@ -1887,11 +1890,10 @@ class MangaScreenModel(
18871890
* a list of <keyword, related mangas>
18881891
*/
18891892
val relatedMangaCollection: List<RelatedManga>? = null,
1893+
val seedColor: Color? = manga.asMangaCover().vibrantCoverColor?.let { Color(it) }
18901894
// KMK <--
18911895
) : State {
18921896
// KMK -->
1893-
val seedColor: Color? = MangaCover.vibrantCoverColorMap[manga.id]?.let { Color(it) }
1894-
18951897
/**
18961898
* a value of null will be treated as still loading, so if all searching were failed and won't update
18971899
* 'relatedMangaCollection` then we should return empty list

domain/src/main/java/tachiyomi/domain/manga/model/MangaCover.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ data class MangaCover(
4242
* [dominantCoverColors] is used to set cover/text's color in Library (Favorite) grid view.
4343
* It contains only color for in-library (favorite) mangas.
4444
*
45-
* It reads/saves to a hashmap in [MangaCover.coverColorMap].
45+
* It reads/saves to a hashmap in [MangaCover.dominantCoverColorMap].
4646
*
4747
* Format: <first: cover color, second: text color>.
4848
*
@@ -54,10 +54,10 @@ data class MangaCover(
5454
*/
5555
@Suppress("KDocUnresolvedReference")
5656
var dominantCoverColors: Pair<Int, Int>?
57-
get() = coverColorMap[mangaId]
57+
get() = dominantCoverColorMap[mangaId]
5858
set(value) {
5959
value ?: return
60-
coverColorMap[mangaId] = value.first to value.second
60+
dominantCoverColorMap[mangaId] = value.first to value.second
6161
}
6262

6363
var ratio: Float?
@@ -66,6 +66,7 @@ data class MangaCover(
6666
value ?: return
6767
coverRatioMap[mangaId] = value
6868
}
69+
6970
companion object {
7071
/**
7172
* [vibrantCoverColorMap] store color generated while browsing library.
@@ -74,13 +75,13 @@ data class MangaCover(
7475
val vibrantCoverColorMap: HashMap<Long, Int?> = hashMapOf()
7576

7677
/**
77-
* [coverColorMap] stores favorite manga's cover & text's color as a joined string in Prefs.
78+
* [dominantCoverColorMap] stores favorite manga's cover & text's color as a joined string in Prefs.
7879
* They will be loaded each time *[App]* is initialized with *[MangaCoverMetadata.load]*.
7980
*
8081
* They will be saved back when *[MainActivity.onPause]* is triggered.
8182
*/
8283
@Suppress("KDocUnresolvedReference")
83-
var coverColorMap = ConcurrentHashMap<Long, Pair<Int, Int>>()
84+
var dominantCoverColorMap = ConcurrentHashMap<Long, Pair<Int, Int>>()
8485

8586
var coverRatioMap = ConcurrentHashMap<Long, Float>()
8687
// KMK <--

presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fun UpdatesWidget(
8989
cover = cover,
9090
modifier = GlanceModifier.clickable(actionStartActivity(intent)),
9191
// KMK -->
92-
color = MangaCover.coverColorMap[mangaId]?.first?.let { Color(it) },
92+
color = MangaCover.dominantCoverColorMap[mangaId]?.first?.let { Color(it) },
9393
// KMK <--
9494
)
9595
}

0 commit comments

Comments
 (0)