Scroll back to last seen item(from unread list) (#935)

* refactor: use initial items in unread reading-view-model

* chore: remove code comment
This commit is contained in:
drgnchan 2025-01-24 11:34:21 +08:00 committed by GitHub
parent 54e022169a
commit 74d0c50da7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,6 +48,8 @@ class ReadingViewModel @Inject constructor(
private val currentFeed: Feed?
get() = readingUiState.value.articleWithFeed?.feed
private var initialArticleItems: List<ArticleFlowItem> = emptyList()
fun initData(articleId: String) {
setLoading()
viewModelScope.launch(ioDispatcher) {
@ -151,7 +153,11 @@ class ReadingViewModel @Inject constructor(
}
fun prefetchArticleId(pagingItems: ItemSnapshotList<ArticleFlowItem>) {
val items = pagingItems.items
if (initialArticleItems.isEmpty()) {
initialArticleItems = pagingItems.items
}
val items = initialArticleItems
val currentId = currentArticle?.id
val index = items.indexOfFirst { item ->
item is ArticleFlowItem.Article && item.articleWithFeed.article.id == currentId