fix: 修复阅读界面导航与朗读配置问题
This commit is contained in:
@@ -273,7 +273,8 @@ val appModule = module {
|
|||||||
readBookStyleConfigRepository = get(),
|
readBookStyleConfigRepository = get(),
|
||||||
readAloudSettingsRepository = get(),
|
readAloudSettingsRepository = get(),
|
||||||
localPreferencesRepository = get(),
|
localPreferencesRepository = get(),
|
||||||
highlightRuleRepository = get()
|
highlightRuleRepository = get(),
|
||||||
|
uploadRepository = get()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
viewModelOf(::ChangeCoverViewModel)
|
viewModelOf(::ChangeCoverViewModel)
|
||||||
|
|||||||
@@ -1048,7 +1048,7 @@ class ReadBookController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun upScreenTimeOut() {
|
private fun upScreenTimeOut() {
|
||||||
val keepLightPrefer = viewModel.readPreferences.value.keepLight.toIntOrNull() ?: 0
|
val keepLightPrefer = ReadConfig.keepLight.toLongOrNull() ?: 0L
|
||||||
screenTimeOut = keepLightPrefer * 1000L
|
screenTimeOut = keepLightPrefer * 1000L
|
||||||
screenOffTimerStartInternal()
|
screenOffTimerStartInternal()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2300,7 +2300,7 @@ private fun ReadMenuLiquidSlider(
|
|||||||
val animationScope = rememberCoroutineScope()
|
val animationScope = rememberCoroutineScope()
|
||||||
var didDrag by remember { mutableStateOf(false) }
|
var didDrag by remember { mutableStateOf(false) }
|
||||||
val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
|
val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
|
||||||
val dampedDragAnimation = remember(animationScope) {
|
val dampedDragAnimation = remember(animationScope, trackWidth, rangeStart, rangeEnd, isLtr) {
|
||||||
DampedDragAnimation(
|
DampedDragAnimation(
|
||||||
animationScope = animationScope,
|
animationScope = animationScope,
|
||||||
initialValue = value(),
|
initialValue = value(),
|
||||||
@@ -3057,8 +3057,12 @@ private fun BrightnessBar(
|
|||||||
glassThumbEnabled: Boolean = false,
|
glassThumbEnabled: Boolean = false,
|
||||||
) {
|
) {
|
||||||
val activity = LocalActivity.current
|
val activity = LocalActivity.current
|
||||||
var sliderValue by remember { mutableFloatStateOf(brightness.toFloat()) }
|
var sliderValue by remember(vertical, buttonGlassEnabled) {
|
||||||
var sliderDragging by remember { mutableStateOf(false) }
|
mutableFloatStateOf(brightness.toFloat())
|
||||||
|
}
|
||||||
|
var sliderDragging by remember(vertical, buttonGlassEnabled) {
|
||||||
|
mutableStateOf(false)
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(brightness, brightnessAuto) {
|
LaunchedEffect(brightness, brightnessAuto) {
|
||||||
if (brightnessAuto) {
|
if (brightnessAuto) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import io.legado.app.data.repository.ReadAloudSettingsRepository
|
|||||||
import io.legado.app.data.repository.ReadBookStyleConfigRepository
|
import io.legado.app.data.repository.ReadBookStyleConfigRepository
|
||||||
import io.legado.app.data.repository.ReadPreferences
|
import io.legado.app.data.repository.ReadPreferences
|
||||||
import io.legado.app.data.repository.ReadSettingsRepository
|
import io.legado.app.data.repository.ReadSettingsRepository
|
||||||
|
import io.legado.app.data.repository.UploadRepository
|
||||||
import io.legado.app.domain.model.ReadingProgress
|
import io.legado.app.domain.model.ReadingProgress
|
||||||
import io.legado.app.domain.usecase.GetReadingProgressUseCase
|
import io.legado.app.domain.usecase.GetReadingProgressUseCase
|
||||||
import io.legado.app.domain.usecase.UploadReadingProgressUseCase
|
import io.legado.app.domain.usecase.UploadReadingProgressUseCase
|
||||||
@@ -137,6 +138,7 @@ class ReadBookViewModel(
|
|||||||
private val readAloudSettingsRepository: ReadAloudSettingsRepository,
|
private val readAloudSettingsRepository: ReadAloudSettingsRepository,
|
||||||
private val localPreferencesRepository: LocalPreferencesRepository,
|
private val localPreferencesRepository: LocalPreferencesRepository,
|
||||||
private val highlightRuleRepository: HighlightRuleRepository,
|
private val highlightRuleRepository: HighlightRuleRepository,
|
||||||
|
private val uploadRepository: UploadRepository,
|
||||||
) : BaseViewModel(application), ReadBook.CallBack {
|
) : BaseViewModel(application), ReadBook.CallBack {
|
||||||
|
|
||||||
// --- MVI State ---
|
// --- MVI State ---
|
||||||
@@ -847,11 +849,12 @@ class ReadBookViewModel(
|
|||||||
is ReadBookIntent.ExportAllHttpTtsAsUrl -> {
|
is ReadBookIntent.ExportAllHttpTtsAsUrl -> {
|
||||||
execute {
|
execute {
|
||||||
val json = exportHttpTtsJson()
|
val json = exportHttpTtsJson()
|
||||||
val dataUrl = "data:application/json;base64," + Base64.encodeToString(
|
val url = uploadRepository.upload(
|
||||||
json.toByteArray(Charsets.UTF_8),
|
fileName = "httpTTS.json",
|
||||||
Base64.NO_WRAP
|
file = json,
|
||||||
|
contentType = "application/json"
|
||||||
)
|
)
|
||||||
"legado://import/httpTTS?src=" + URLEncoder.encode(dataUrl, "UTF-8")
|
"legado://import/httpTTS?src=" + URLEncoder.encode(url, "UTF-8")
|
||||||
}.onSuccess { url ->
|
}.onSuccess { url ->
|
||||||
context.sendToClip(url)
|
context.sendToClip(url)
|
||||||
_effects.tryEmit(ReadBookEffect.ShowToast(context.getString(R.string.copy_url)))
|
_effects.tryEmit(ReadBookEffect.ShowToast(context.getString(R.string.copy_url)))
|
||||||
@@ -2024,15 +2027,6 @@ class ReadBookViewModel(
|
|||||||
ReadBook.resetData(book)
|
ReadBook.resetData(book)
|
||||||
}
|
}
|
||||||
_uiState.update { it.copy(isInitFinish = true) }
|
_uiState.update { it.copy(isInitFinish = true) }
|
||||||
// 旋转后 ChapterProvider 的 doublePage/visibleWidth 已在 onSizeChanged 中更新,
|
|
||||||
// 但 ReloadContent 因 isInitFinish=false 被跳过。此处确保内容用新布局重新加载。
|
|
||||||
if (isSameBook) {
|
|
||||||
_effects.tryEmit(
|
|
||||||
ReadBookEffect.UpdateReadViewConfig(
|
|
||||||
setOf(ConfigUpdateAction.UpdateLayout, ConfigUpdateAction.ReloadContent)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (!book.isLocal && book.tocUrl.isEmpty() && !loadBookInfo(book)) {
|
if (!book.isLocal && book.tocUrl.isEmpty() && !loadBookInfo(book)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ fun ContentEditSheet(
|
|||||||
pendingLocateOffset = null
|
pendingLocateOffset = null
|
||||||
return@LaunchedEffect
|
return@LaunchedEffect
|
||||||
}
|
}
|
||||||
val offset = locateOffset.coerceIn(0, layoutTextLength)
|
val offset = locateOffset.coerceIn(0, layoutTextLength - 1)
|
||||||
val cursorTop = layoutResult.getCursorRect(offset).top.toInt()
|
val cursorTop = layoutResult.getCursorRect(offset).top.toInt()
|
||||||
editorScrollState.scrollTo((cursorTop - 120).coerceIn(0, editorScrollState.maxValue))
|
editorScrollState.scrollTo((cursorTop - 120).coerceIn(0, editorScrollState.maxValue))
|
||||||
pendingLocateOffset = null
|
pendingLocateOffset = null
|
||||||
|
|||||||
@@ -5,10 +5,18 @@ import android.content.Intent
|
|||||||
import androidx.navigation3.runtime.NavKey
|
import androidx.navigation3.runtime.NavKey
|
||||||
import io.legado.app.ui.rss.article.MainRouteRssSort
|
import io.legado.app.ui.rss.article.MainRouteRssSort
|
||||||
import io.legado.app.ui.rss.read.MainRouteRssRead
|
import io.legado.app.ui.rss.read.MainRouteRssRead
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
object MainNavigator {
|
object MainNavigator {
|
||||||
|
|
||||||
private var backNavigationInProgress = false
|
private var backNavigationInProgress = false
|
||||||
|
private val navigationScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
||||||
|
private var backNavigationResetJob: Job? = null
|
||||||
|
|
||||||
fun navigateToRoute(backStack: MutableList<NavKey>, route: NavKey) {
|
fun navigateToRoute(backStack: MutableList<NavKey>, route: NavKey) {
|
||||||
val currentRoute = backStack.lastOrNull()
|
val currentRoute = backStack.lastOrNull()
|
||||||
@@ -186,8 +194,8 @@ object MainNavigator {
|
|||||||
if (backNavigationInProgress) {
|
if (backNavigationInProgress) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
backNavigationInProgress = true
|
|
||||||
if (backStack.size > 1) {
|
if (backStack.size > 1) {
|
||||||
|
backNavigationInProgress = true
|
||||||
backStack.removeLastOrNull()
|
backStack.removeLastOrNull()
|
||||||
} else {
|
} else {
|
||||||
activity.finish()
|
activity.finish()
|
||||||
@@ -195,7 +203,11 @@ object MainNavigator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onBackStackChanged() {
|
fun onBackStackChanged() {
|
||||||
backNavigationInProgress = false
|
backNavigationResetJob?.cancel()
|
||||||
|
backNavigationResetJob = navigationScope.launch {
|
||||||
|
delay(500)
|
||||||
|
backNavigationInProgress = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveStartRoute(intent: Intent?): NavKey {
|
fun resolveStartRoute(intent: Intent?): NavKey {
|
||||||
|
|||||||
Reference in New Issue
Block a user