parent
19db53473d
commit
6878ecac86
1 changed files with 31 additions and 27 deletions
|
|
@ -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 ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue