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