refactor: Update seedColor usage in ReaderActivity
- Using state to update seed color when there is change - Fix: loading seed color in case manga is late to init - improve: change chapter's slider's text color
This commit is contained in:
parent
c49c4c9c6d
commit
e25ff219eb
4 changed files with 41 additions and 14 deletions
|
|
@ -51,6 +51,7 @@ enum class MangaCover(val ratio: Float) {
|
||||||
alpha: Float = 1f,
|
alpha: Float = 1f,
|
||||||
bgColor: Color? = null,
|
bgColor: Color? = null,
|
||||||
@ColorInt tint: Int? = null,
|
@ColorInt tint: Int? = null,
|
||||||
|
/** Perform action when cover loaded, specifically generating color map */
|
||||||
onCoverLoaded: ((DomainMangaCover) -> Unit)? = null,
|
onCoverLoaded: ((DomainMangaCover) -> Unit)? = null,
|
||||||
size: Size = Size.Normal,
|
size: Size = Size.Normal,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ fun ChapterNavigator(
|
||||||
val backgroundColor = MaterialTheme.colorScheme
|
val backgroundColor = MaterialTheme.colorScheme
|
||||||
.surfaceColorAtElevation(3.dp)
|
.surfaceColorAtElevation(3.dp)
|
||||||
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
|
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
|
||||||
|
val textColor = MaterialTheme.colorScheme.onSurface
|
||||||
val buttonColor = IconButtonDefaults.filledIconButtonColors(
|
val buttonColor = IconButtonDefaults.filledIconButtonColors(
|
||||||
containerColor = backgroundColor,
|
containerColor = backgroundColor,
|
||||||
disabledContainerColor = backgroundColor,
|
disabledContainerColor = backgroundColor,
|
||||||
|
|
@ -123,7 +124,12 @@ fun ChapterNavigator(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
// SY -->
|
// SY -->
|
||||||
Text(text = currentPageText)
|
Text(
|
||||||
|
text = currentPageText,
|
||||||
|
// KMK -->
|
||||||
|
color = textColor,
|
||||||
|
// KMK <--
|
||||||
|
)
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
||||||
val interactionSource = remember { MutableInteractionSource() }
|
val interactionSource = remember { MutableInteractionSource() }
|
||||||
|
|
@ -146,7 +152,12 @@ fun ChapterNavigator(
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(text = totalPages.toString())
|
Text(
|
||||||
|
text = totalPages.toString(),
|
||||||
|
// KMK -->
|
||||||
|
color = textColor,
|
||||||
|
// KMK <--
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ object MangaCoverMetadata {
|
||||||
* + [onlyDominantColor] = false
|
* + [onlyDominantColor] = false
|
||||||
* - Manga doesn't have vibrant color
|
* - Manga doesn't have vibrant color
|
||||||
*/
|
*/
|
||||||
options.inSampleSize = 4
|
options.inSampleSize = SUB_SAMPLE
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* + [onlyDominantColor] = true
|
* + [onlyDominantColor] = true
|
||||||
|
|
@ -154,4 +154,6 @@ object MangaCoverMetadata {
|
||||||
val mapColorCopy = MangaCover.dominantCoverColorMap.toMap()
|
val mapColorCopy = MangaCover.dominantCoverColorMap.toMap()
|
||||||
preferences.coverColors().set(mapColorCopy.map { "${it.key}|${it.value.first}|${it.value.second}" }.toSet())
|
preferences.coverColors().set(mapColorCopy.map { "${it.key}|${it.value.first}|${it.value.second}" }.toSet())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const val SUB_SAMPLE = 4
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ import tachiyomi.core.common.util.lang.launchIO
|
||||||
import tachiyomi.core.common.util.lang.launchNonCancellable
|
import tachiyomi.core.common.util.lang.launchNonCancellable
|
||||||
import tachiyomi.core.common.util.lang.withUIContext
|
import tachiyomi.core.common.util.lang.withUIContext
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
|
import tachiyomi.domain.manga.model.MangaCover
|
||||||
import tachiyomi.domain.manga.model.asMangaCover
|
import tachiyomi.domain.manga.model.asMangaCover
|
||||||
import tachiyomi.domain.source.service.SourceManager
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
|
|
@ -386,8 +387,6 @@ class ReaderActivity : BaseActivity() {
|
||||||
*/
|
*/
|
||||||
private fun initializeMenu() {
|
private fun initializeMenu() {
|
||||||
// KMK -->
|
// KMK -->
|
||||||
val seedColor = viewModel.manga?.asMangaCover()?.vibrantCoverColor?.let { ComposeColor(it) }
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun pageNumberContent() {
|
fun pageNumberContent() {
|
||||||
// KMK <--
|
// KMK <--
|
||||||
|
|
@ -407,7 +406,7 @@ class ReaderActivity : BaseActivity() {
|
||||||
// KMK -->
|
// KMK -->
|
||||||
binding.pageNumber.setComposeContent {
|
binding.pageNumber.setComposeContent {
|
||||||
TachiyomiTheme(
|
TachiyomiTheme(
|
||||||
seedColor = seedColor.takeIf { themeCoverBased }
|
seedColor = seedColorState().takeIf { themeCoverBased },
|
||||||
) {
|
) {
|
||||||
pageNumberContent()
|
pageNumberContent()
|
||||||
}
|
}
|
||||||
|
|
@ -688,15 +687,15 @@ class ReaderActivity : BaseActivity() {
|
||||||
// KMK -->
|
// KMK -->
|
||||||
binding.dialogRoot.setComposeContent {
|
binding.dialogRoot.setComposeContent {
|
||||||
TachiyomiTheme(
|
TachiyomiTheme(
|
||||||
seedColor = seedColor.takeIf { themeCoverBased }
|
seedColor = seedColorState().takeIf { themeCoverBased },
|
||||||
) {
|
) {
|
||||||
dialogRootContent()
|
dialogRootContent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val colorScheme = seedColor?.let {
|
val colorScheme = seedColorStatic()?.let {
|
||||||
dynamicColorScheme(
|
dynamicColorScheme(
|
||||||
seedColor = seedColor,
|
seedColor = it,
|
||||||
isDark = isNightMode(),
|
isDark = isNightMode(),
|
||||||
isAmoled = themeDarkAmoled,
|
isAmoled = themeDarkAmoled,
|
||||||
style = themeCoverBasedStyle,
|
style = themeCoverBasedStyle,
|
||||||
|
|
@ -725,6 +724,22 @@ class ReaderActivity : BaseActivity() {
|
||||||
enableExhAutoScroll()
|
enableExhAutoScroll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KMK -->
|
||||||
|
@Composable
|
||||||
|
private fun seedColorState(): ComposeColor? {
|
||||||
|
val state by viewModel.state.collectAsState()
|
||||||
|
return state.manga?.asMangaCover()?.vibrantCoverColor?.let { ComposeColor(it) }
|
||||||
|
?: seedColorStatic()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun seedColorStatic(): ComposeColor? {
|
||||||
|
return viewModel.manga?.asMangaCover()?.vibrantCoverColor?.let { ComposeColor(it) }
|
||||||
|
?: intent.extras?.getLong("manga")?.takeIf { it > 0 }
|
||||||
|
?.let { MangaCover.vibrantCoverColorMap[it] }
|
||||||
|
?.let { ComposeColor(it) }
|
||||||
|
}
|
||||||
|
// KMK <--
|
||||||
|
|
||||||
private fun enableExhAutoScroll() {
|
private fun enableExhAutoScroll() {
|
||||||
readerPreferences.autoscrollInterval().changes()
|
readerPreferences.autoscrollInterval().changes()
|
||||||
.combine(viewModel.state.map { it.autoScroll }.distinctUntilChanged()) { interval, enabled ->
|
.combine(viewModel.state.map { it.autoScroll }.distinctUntilChanged()) { interval, enabled ->
|
||||||
|
|
@ -891,15 +906,12 @@ class ReaderActivity : BaseActivity() {
|
||||||
* Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer.
|
* Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer.
|
||||||
*/
|
*/
|
||||||
private fun updateViewer() {
|
private fun updateViewer() {
|
||||||
// KMK -->
|
|
||||||
val manga = viewModel.manga
|
|
||||||
// KMK <--
|
|
||||||
val prevViewer = viewModel.state.value.viewer
|
val prevViewer = viewModel.state.value.viewer
|
||||||
val newViewer = ReadingMode.toViewer(
|
val newViewer = ReadingMode.toViewer(
|
||||||
viewModel.getMangaReadingMode(),
|
viewModel.getMangaReadingMode(),
|
||||||
this,
|
this,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
seedColor = manga?.asMangaCover()?.vibrantCoverColor,
|
seedColor = seedColorStatic()?.toArgb(),
|
||||||
// KMK <--
|
// KMK <--
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -929,6 +941,7 @@ class ReaderActivity : BaseActivity() {
|
||||||
viewModel.state.value.lastShiftDoubleState?.let { newViewer.config.shiftDoublePage = it }
|
viewModel.state.value.lastShiftDoubleState?.let { newViewer.config.shiftDoublePage = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val manga = viewModel.state.value.manga
|
||||||
val defaultReaderType = manga?.defaultReaderType(
|
val defaultReaderType = manga?.defaultReaderType(
|
||||||
manga.mangaType(sourceName = sourceManager.get(manga.source)?.name),
|
manga.mangaType(sourceName = sourceManager.get(manga.source)?.name),
|
||||||
)
|
)
|
||||||
|
|
@ -948,7 +961,7 @@ class ReaderActivity : BaseActivity() {
|
||||||
loadingIndicator = ReaderProgressIndicator(
|
loadingIndicator = ReaderProgressIndicator(
|
||||||
context = this,
|
context = this,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
seedColor = manga?.asMangaCover()?.vibrantCoverColor,
|
seedColor = seedColorStatic()?.toArgb(),
|
||||||
// KMK <--
|
// KMK <--
|
||||||
)
|
)
|
||||||
binding.readerContainer.addView(loadingIndicator)
|
binding.readerContainer.addView(loadingIndicator)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue