fixed bug on opening a book on android

This commit is contained in:
Sergey Chernov 2026-05-27 10:43:18 +03:00
parent 6990e3c233
commit 0084c478a3
3 changed files with 15 additions and 3 deletions

View File

@ -232,9 +232,11 @@ private fun BookReaderApp(
is AppState.Error, AppState.LoadingStartup -> defaultLibraryScanPath().orEmpty() is AppState.Error, AppState.LoadingStartup -> defaultLibraryScanPath().orEmpty()
} }
val nextState = runCatching { val nextState = runCatching {
val book = Fb2Format.parse(request.bytes, request.displayName)
saveActiveReadingFileId(request.id)
AppState.Reader( AppState.Reader(
fileId = request.id, fileId = request.id,
book = Fb2Format.parse(request.bytes, request.displayName), book = book,
libraryItems = emptyList(), libraryItems = emptyList(),
scanPath = scanPath, scanPath = scanPath,
) )

View File

@ -47,9 +47,11 @@ internal suspend fun loadStartupState(): AppState {
} }
platformRequest?.let { request -> platformRequest?.let { request ->
return runCatching { return runCatching {
val book = Fb2Format.parse(request.bytes, request.displayName)
saveActiveReadingFileId(request.id)
AppState.Reader( AppState.Reader(
fileId = request.id, fileId = request.id,
book = Fb2Format.parse(request.bytes, request.displayName), book = book,
libraryItems = emptyList(), libraryItems = emptyList(),
scanPath = scanPath, scanPath = scanPath,
) )

View File

@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -67,6 +68,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -105,7 +107,7 @@ internal fun BookView(
) { ) {
val stats = remember(book) { BookStats.from(book) } val stats = remember(book) { BookStats.from(book) }
val contentPlan = remember(book) { buildReaderContentPlan(book) } val contentPlan = remember(book) { buildReaderContentPlan(book) }
val listState = rememberLazyListState() val listState = remember(fileId) { LazyListState() }
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() } val snackbarHostState = remember { SnackbarHostState() }
var restored by remember(fileId) { mutableStateOf(false) } var restored by remember(fileId) { mutableStateOf(false) }
@ -162,6 +164,7 @@ internal fun BookView(
readAloudResumeSentenceIndex, readAloudResumeSentenceIndex,
backStack, backStack,
) )
val currentReadingPositionProvider by rememberUpdatedState { currentReadingPosition() }
fun openPosition(position: ReadingPosition, backStack: List<ReadingPosition>) { fun openPosition(position: ReadingPosition, backStack: List<ReadingPosition>) {
scope.launch { scope.launch {
@ -226,6 +229,11 @@ internal fun BookView(
DisposableEffect(fileId) { DisposableEffect(fileId) {
onDispose { onDispose {
if (restored) {
scope.launch {
saveLibraryReadingPosition(fileId, currentReadingPositionProvider())
}
}
ReadAloudPlatform.stop() ReadAloudPlatform.stop()
} }
} }