parent
19db53473d
commit
6878ecac86
1 changed files with 31 additions and 27 deletions
|
|
@ -493,36 +493,40 @@ class ReaderModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
fun updateProgress(listState: LazyListState) {
|
suspend fun updateProgress(listState: LazyListState) {
|
||||||
viewModelScope.launch(Dispatchers.Main) {
|
snapshotFlow {
|
||||||
snapshotFlow {
|
listState.firstVisibleItemIndex to listState.firstVisibleItemScrollOffset
|
||||||
listState.firstVisibleItemIndex to listState.firstVisibleItemScrollOffset
|
}.distinctUntilChanged().debounce(300).collectLatest { (index, offset) ->
|
||||||
}.distinctUntilChanged().debounce(300).collectLatest { (index, offset) ->
|
if (
|
||||||
val progress = calculateProgress(index)
|
_state.value.isLoading ||
|
||||||
if (progress == _state.value.book.progress) return@collectLatest
|
listState.layoutInfo.totalItemsCount == 0 ||
|
||||||
val (currentChapter, currentChapterProgress) = calculateCurrentChapter(index)
|
_state.value.text.isEmpty() ||
|
||||||
|
_state.value.errorMessage != null
|
||||||
|
) return@collectLatest
|
||||||
|
|
||||||
Log.i(
|
val progress = calculateProgress(index)
|
||||||
READER,
|
val (currentChapter, currentChapterProgress) = calculateCurrentChapter(index)
|
||||||
"Changed progress|currentChapter: $progress; ${currentChapter?.title}"
|
|
||||||
|
Log.i(
|
||||||
|
READER,
|
||||||
|
"Changed progress|currentChapter: $progress; ${currentChapter?.title}"
|
||||||
|
)
|
||||||
|
_state.update {
|
||||||
|
it.copy(
|
||||||
|
book = it.book.copy(
|
||||||
|
progress = progress,
|
||||||
|
scrollIndex = index,
|
||||||
|
scrollOffset = offset
|
||||||
|
),
|
||||||
|
currentChapter = currentChapter,
|
||||||
|
currentChapterProgress = currentChapterProgress
|
||||||
)
|
)
|
||||||
_state.update {
|
|
||||||
it.copy(
|
|
||||||
book = it.book.copy(
|
|
||||||
progress = progress,
|
|
||||||
scrollIndex = index,
|
|
||||||
scrollOffset = offset
|
|
||||||
),
|
|
||||||
currentChapter = currentChapter,
|
|
||||||
currentChapterProgress = currentChapterProgress
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateBookUseCase(_state.value.book)
|
|
||||||
|
|
||||||
LibraryScreen.refreshListChannel.trySend(0)
|
|
||||||
HistoryScreen.refreshListChannel.trySend(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBookUseCase(_state.value.book)
|
||||||
|
|
||||||
|
LibraryScreen.refreshListChannel.trySend(0)
|
||||||
|
HistoryScreen.refreshListChannel.trySend(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue