fixed bug on opening a book on android
This commit is contained in:
parent
6990e3c233
commit
0084c478a3
@ -232,9 +232,11 @@ private fun BookReaderApp(
|
||||
is AppState.Error, AppState.LoadingStartup -> defaultLibraryScanPath().orEmpty()
|
||||
}
|
||||
val nextState = runCatching {
|
||||
val book = Fb2Format.parse(request.bytes, request.displayName)
|
||||
saveActiveReadingFileId(request.id)
|
||||
AppState.Reader(
|
||||
fileId = request.id,
|
||||
book = Fb2Format.parse(request.bytes, request.displayName),
|
||||
book = book,
|
||||
libraryItems = emptyList(),
|
||||
scanPath = scanPath,
|
||||
)
|
||||
|
||||
@ -47,9 +47,11 @@ internal suspend fun loadStartupState(): AppState {
|
||||
}
|
||||
platformRequest?.let { request ->
|
||||
return runCatching {
|
||||
val book = Fb2Format.parse(request.bytes, request.displayName)
|
||||
saveActiveReadingFileId(request.id)
|
||||
AppState.Reader(
|
||||
fileId = request.id,
|
||||
book = Fb2Format.parse(request.bytes, request.displayName),
|
||||
book = book,
|
||||
libraryItems = emptyList(),
|
||||
scanPath = scanPath,
|
||||
)
|
||||
|
||||
@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@ -67,6 +68,7 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -105,7 +107,7 @@ internal fun BookView(
|
||||
) {
|
||||
val stats = remember(book) { BookStats.from(book) }
|
||||
val contentPlan = remember(book) { buildReaderContentPlan(book) }
|
||||
val listState = rememberLazyListState()
|
||||
val listState = remember(fileId) { LazyListState() }
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
var restored by remember(fileId) { mutableStateOf(false) }
|
||||
@ -162,6 +164,7 @@ internal fun BookView(
|
||||
readAloudResumeSentenceIndex,
|
||||
backStack,
|
||||
)
|
||||
val currentReadingPositionProvider by rememberUpdatedState { currentReadingPosition() }
|
||||
|
||||
fun openPosition(position: ReadingPosition, backStack: List<ReadingPosition>) {
|
||||
scope.launch {
|
||||
@ -226,6 +229,11 @@ internal fun BookView(
|
||||
|
||||
DisposableEffect(fileId) {
|
||||
onDispose {
|
||||
if (restored) {
|
||||
scope.launch {
|
||||
saveLibraryReadingPosition(fileId, currentReadingPositionProvider())
|
||||
}
|
||||
}
|
||||
ReadAloudPlatform.stop()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user