fix: 阅读界面相关优化
This commit is contained in:
@@ -259,6 +259,8 @@ sealed interface ReadBookIntent {
|
||||
data class SetSearchResultIndex(val index: Int) : ReadBookIntent
|
||||
data class SetShowingSearchResult(val value: Boolean) : ReadBookIntent
|
||||
data class NavigateToSearchResult(val result: SearchResult, val index: Int) : ReadBookIntent
|
||||
data object RestoreLastBookProgress : ReadBookIntent
|
||||
data object KeepCurrentBookProgress : ReadBookIntent
|
||||
|
||||
// Read aloud
|
||||
data object ToggleReadAloud : ReadBookIntent
|
||||
@@ -670,6 +672,7 @@ sealed interface ReadBookSheet {
|
||||
sealed interface ReadBookDialog {
|
||||
data class ConfirmRestoreProgress(val progress: BookProgress) : ReadBookDialog
|
||||
data class SureSyncProgress(val progress: BookProgress) : ReadBookDialog
|
||||
data object RestoreLastBookProgress : ReadBookDialog
|
||||
data object ConfirmSkipToChapter : ReadBookDialog
|
||||
data class ConfirmChapterPay(val chapterTitle: String) : ReadBookDialog
|
||||
}
|
||||
@@ -1070,7 +1073,10 @@ sealed interface ConfigUpdate {
|
||||
override val actions = emptySet<ConfigUpdateAction>()
|
||||
}
|
||||
data class DoubleHorizontalPage(val value: String) : ConfigUpdate {
|
||||
override val actions = emptySet<ConfigUpdateAction>()
|
||||
override val actions = setOf(
|
||||
ConfigUpdateAction.UpdateLayout,
|
||||
ConfigUpdateAction.ReloadContent,
|
||||
)
|
||||
}
|
||||
data class ProgressBarBehavior(val value: String) : ConfigUpdate {
|
||||
override val actions = emptySet<ConfigUpdateAction>()
|
||||
|
||||
@@ -682,7 +682,7 @@ class ReadBookController(
|
||||
}
|
||||
|
||||
is ReadBookEffect.UpScreenTimeOut -> {
|
||||
screenOffTimerStart()
|
||||
upScreenTimeOut()
|
||||
}
|
||||
|
||||
is ReadBookEffect.ToggleBrightnessAuto -> {
|
||||
|
||||
@@ -904,7 +904,7 @@ private fun MenuTitleBar(
|
||||
) {
|
||||
// Back button
|
||||
MenuTitleGlassButton(
|
||||
onClick = { onIntent(ReadBookIntent.ReadMenuBack) },
|
||||
onClick = { onIntent(ReadBookIntent.CloseReadBook) },
|
||||
icon = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = "Back",
|
||||
state = state,
|
||||
@@ -1156,15 +1156,15 @@ private fun ReadMenuGlassButtonSurface(
|
||||
) {
|
||||
val shape = CircleShape
|
||||
val tint = when {
|
||||
selected -> LegadoTheme.colorScheme.onPrimaryContainer
|
||||
selected -> LegadoTheme.colorScheme.primary
|
||||
else -> LegadoTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
val containerColor = when {
|
||||
selected -> LegadoTheme.colorScheme.primaryContainer
|
||||
selected -> LegadoTheme.colorScheme.secondaryContainer
|
||||
else -> LegadoTheme.colorScheme.surfaceContainerLow
|
||||
}
|
||||
val border = if (selected) {
|
||||
BorderStroke(1.5.dp, LegadoTheme.colorScheme.primary)
|
||||
BorderStroke(1.5.dp, LegadoTheme.colorScheme.secondary)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -1973,6 +1973,7 @@ private fun ReadMenuLiquidSlider(
|
||||
val accentColor = LegadoTheme.colorScheme.secondary
|
||||
val trackColor = LegadoTheme.colorScheme.surfaceContainerLow
|
||||
val thumbColor = Color.White.copy(alpha = 0.9f).compositeOver(LegadoTheme.colorScheme.surfaceContainerLow)
|
||||
val enabledAlpha = if (enabled) 1f else 0.38f
|
||||
|
||||
val trackBackdrop = rememberLayerBackdrop()
|
||||
|
||||
@@ -2051,7 +2052,7 @@ private fun ReadMenuLiquidSlider(
|
||||
},
|
||||
innerShadow = null,
|
||||
onDrawSurface = {
|
||||
drawRect(trackColor)
|
||||
drawRect(trackColor.copy(alpha = enabledAlpha))
|
||||
},
|
||||
)
|
||||
.pointerInput(enabled, animationScope, isLtr, trackWidth) {
|
||||
@@ -2072,7 +2073,7 @@ private fun ReadMenuLiquidSlider(
|
||||
Box(
|
||||
Modifier
|
||||
.clip(ContinuousCapsule)
|
||||
.background(accentColor)
|
||||
.background(accentColor.copy(alpha = enabledAlpha))
|
||||
.height(6f.dp)
|
||||
.layout { measurable, constraints ->
|
||||
val placeable = measurable.measure(constraints)
|
||||
@@ -2087,12 +2088,13 @@ private fun ReadMenuLiquidSlider(
|
||||
Box(
|
||||
Modifier
|
||||
.graphicsLayer {
|
||||
alpha = enabledAlpha
|
||||
translationX =
|
||||
(-size.width / 2f + trackWidth * progress)
|
||||
.coerceIn(-size.width / 4f, trackWidth - size.width * 3f / 4f) *
|
||||
if (isLtr) 1f else -1f
|
||||
}
|
||||
.then(dampedDragAnimation.modifier)
|
||||
.then(if (enabled) dampedDragAnimation.modifier else Modifier)
|
||||
.drawBackdrop(
|
||||
backdrop = rememberCombinedBackdrop(
|
||||
backdrop,
|
||||
@@ -2724,6 +2726,7 @@ private fun BrightnessBar(
|
||||
}
|
||||
|
||||
fun commitSliderValue(value: Float) {
|
||||
if (brightnessAuto) return
|
||||
val target = value.roundToInt().coerceIn(0, 100)
|
||||
sliderDragging = false
|
||||
sliderValue = target.toFloat()
|
||||
@@ -2751,6 +2754,7 @@ private fun BrightnessBar(
|
||||
AppVerticalSlider(
|
||||
value = sliderValue.coerceIn(0f, 100f),
|
||||
onValueChange = { value ->
|
||||
if (brightnessAuto) return@AppVerticalSlider
|
||||
sliderDragging = true
|
||||
sliderValue = value.coerceIn(0f, 100f)
|
||||
},
|
||||
@@ -2793,6 +2797,7 @@ private fun BrightnessBar(
|
||||
ReadMenuSlider(
|
||||
value = sliderValue.coerceIn(0f, 100f),
|
||||
onValueChange = { value ->
|
||||
if (brightnessAuto) return@ReadMenuSlider
|
||||
sliderDragging = true
|
||||
sliderValue = value.coerceIn(0f, 100f)
|
||||
},
|
||||
|
||||
@@ -66,6 +66,7 @@ fun ReadBookScreen(
|
||||
// Dialogs driven by activeDialog state
|
||||
val restoreDialog = state.activeDialog as? ReadBookDialog.ConfirmRestoreProgress
|
||||
val syncDialog = state.activeDialog as? ReadBookDialog.SureSyncProgress
|
||||
val restoreLastProgressDialog = state.activeDialog as? ReadBookDialog.RestoreLastBookProgress
|
||||
val skipDialog = state.activeDialog as? ReadBookDialog.ConfirmSkipToChapter
|
||||
val payDialog = state.activeDialog as? ReadBookDialog.ConfirmChapterPay
|
||||
|
||||
@@ -95,6 +96,16 @@ fun ReadBookScreen(
|
||||
dismissText = stringResource(R.string.cancel),
|
||||
onDismiss = { onIntent(ReadBookIntent.DismissDialog) },
|
||||
)
|
||||
AppAlertDialog(
|
||||
show = restoreLastProgressDialog != null,
|
||||
onDismissRequest = { onIntent(ReadBookIntent.KeepCurrentBookProgress) },
|
||||
title = stringResource(R.string.draw),
|
||||
text = stringResource(R.string.restore_last_book_process),
|
||||
confirmText = stringResource(R.string.ok),
|
||||
onConfirm = { onIntent(ReadBookIntent.RestoreLastBookProgress) },
|
||||
dismissText = stringResource(R.string.cancel),
|
||||
onDismiss = { onIntent(ReadBookIntent.KeepCurrentBookProgress) },
|
||||
)
|
||||
AppAlertDialog(
|
||||
show = skipDialog != null,
|
||||
onDismissRequest = { onIntent(ReadBookIntent.DismissDialog) },
|
||||
|
||||
@@ -60,7 +60,6 @@ import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.service.BaseReadAloudService
|
||||
import io.legado.app.ui.book.read.page.entities.TextChapter
|
||||
import io.legado.app.ui.book.read.page.entities.TextPage
|
||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||
import io.legado.app.ui.book.read.page.provider.TextChapterLayout
|
||||
import io.legado.app.ui.book.searchContent.SearchResult
|
||||
import io.legado.app.ui.config.otherConfig.OtherConfig
|
||||
@@ -236,6 +235,8 @@ class ReadBookViewModel(
|
||||
searchResultList = intent.results.toImmutableList(),
|
||||
searchResultIndex = intent.index,
|
||||
isShowingSearchResult = true,
|
||||
searchMenuVisible = true,
|
||||
menuState = ReadBookMenuState(),
|
||||
searchContentQuery = intent.query ?: it.searchContentQuery,
|
||||
)
|
||||
}
|
||||
@@ -250,10 +251,21 @@ class ReadBookViewModel(
|
||||
}
|
||||
|
||||
is ReadBookIntent.NavigateToSearchResult -> {
|
||||
ReadBook.saveCurrentBookProgress()
|
||||
_uiState.update { it.copy(searchResultIndex = intent.index) }
|
||||
navigateToSearchResult(intent.result)
|
||||
}
|
||||
|
||||
is ReadBookIntent.RestoreLastBookProgress -> {
|
||||
_uiState.update { it.copy(activeDialog = null) }
|
||||
ReadBook.restoreLastBookProgress()
|
||||
}
|
||||
|
||||
is ReadBookIntent.KeepCurrentBookProgress -> {
|
||||
ReadBook.lastBookProgress = null
|
||||
_uiState.update { it.copy(activeDialog = null) }
|
||||
}
|
||||
|
||||
is ReadBookIntent.ToggleReadAloud -> {
|
||||
if (!BaseReadAloudService.isRun) {
|
||||
openReadMenuRoute(ReadBookMenuRoute.ReadAloud)
|
||||
@@ -2886,8 +2898,6 @@ class ReadBookViewModel(
|
||||
viewModelScope.launch {
|
||||
readSettingsRepository.setDoubleHorizontalPage(update.value)
|
||||
}
|
||||
ChapterProvider.upLayout()
|
||||
ReadBook.loadContent(false)
|
||||
}
|
||||
is ConfigUpdate.ProgressBarBehavior -> {
|
||||
ReadConfig.progressBarBehavior = update.value
|
||||
@@ -3375,7 +3385,12 @@ class ReadBookViewModel(
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
isShowingSearchResult = false,
|
||||
searchMenuVisible = false
|
||||
searchMenuVisible = false,
|
||||
activeDialog = if (ReadBook.lastBookProgress != null) {
|
||||
ReadBookDialog.RestoreLastBookProgress
|
||||
} else {
|
||||
it.activeDialog
|
||||
}
|
||||
)
|
||||
}
|
||||
_effects.tryEmit(ReadBookEffect.ExitSearch)
|
||||
|
||||
Reference in New Issue
Block a user