merge(fix): 237-incorrect-scroll-position into develop

This commit is contained in:
Acclorite 2025-06-28 11:43:13 +03:00
commit 0f5de57067
No known key found for this signature in database
GPG key ID: 6E54C611F6EE8593

View file

@ -493,13 +493,18 @@ class ReaderModel @Inject constructor(
}
@OptIn(FlowPreview::class)
fun updateProgress(listState: LazyListState) {
viewModelScope.launch(Dispatchers.Main) {
suspend fun updateProgress(listState: LazyListState) {
snapshotFlow {
listState.firstVisibleItemIndex to listState.firstVisibleItemScrollOffset
}.distinctUntilChanged().debounce(300).collectLatest { (index, offset) ->
if (
_state.value.isLoading ||
listState.layoutInfo.totalItemsCount == 0 ||
_state.value.text.isEmpty() ||
_state.value.errorMessage != null
) return@collectLatest
val progress = calculateProgress(index)
if (progress == _state.value.book.progress) return@collectLatest
val (currentChapter, currentChapterProgress) = calculateCurrentChapter(index)
Log.i(
@ -524,7 +529,6 @@ class ReaderModel @Inject constructor(
HistoryScreen.refreshListChannel.trySend(0)
}
}
}
fun findChapterIndexAndLength(index: Int): Pair<Int, Int> {
return findCurrentChapter(index)?.let { chapter ->