Skip to content

Commit cf2ca2d

Browse files
committed
删除收藏列表的 sync state 同步, close #2566
1 parent 5ee4227 commit cf2ca2d

File tree

2 files changed

+1
-55
lines changed

2 files changed

+1
-55
lines changed

app/shared/ui-subject/src/commonMain/kotlin/ui/subject/collection/CollectionPage.kt

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import androidx.compose.runtime.State
6767
import androidx.compose.runtime.derivedStateOf
6868
import androidx.compose.runtime.getValue
6969
import androidx.compose.runtime.mutableStateListOf
70-
import androidx.compose.runtime.mutableStateMapOf
7170
import androidx.compose.runtime.mutableStateOf
7271
import androidx.compose.runtime.remember
7372
import androidx.compose.runtime.rememberCoroutineScope
@@ -84,8 +83,6 @@ import androidx.compose.ui.text.style.TextAlign
8483
import androidx.compose.ui.unit.DpSize
8584
import androidx.compose.ui.unit.dp
8685
import androidx.lifecycle.compose.collectAsStateWithLifecycle
87-
import androidx.paging.CombinedLoadStates
88-
import androidx.paging.LoadState
8986
import androidx.paging.PagingData
9087
import androidx.paging.compose.LazyPagingItems
9188
import androidx.paging.compose.collectWithLifecycle
@@ -152,7 +149,6 @@ class UserCollectionsState(
152149
collectionCountsState: State<SubjectCollectionCounts?>,
153150
val subjectProgressStateFactory: SubjectProgressStateFactory,
154151
val createEditableSubjectCollectionTypeState: (subjectCollection: SubjectCollectionInfo) -> EditableSubjectCollectionTypeState,
155-
val onPagerFetchingAnyRemoteSource: (Boolean) -> Unit,
156152
private val backgroundScope: CoroutineScope,
157153
defaultQuery: CollectionsFilterQuery = CollectionsFilterQuery(
158154
type = UnifiedCollectionType.DOING,
@@ -177,13 +173,6 @@ class UserCollectionsState(
177173

178174
private val restarter = FlowRestarter()
179175

180-
// true 表示这个 PagingData 的 remote mediator 正在加载, 即正在从 ani server 获取数据.
181-
// 从 server 获取收藏数据时可能会触发 user 的 full sync 操作, 需要等待 full sync 完成后才能获取到收藏数据.
182-
//
183-
// 记录每个 type 的 remote mediator 是否正在加载
184-
// 只要有一个在加载, 我们就通知 view model 轮询获取 full sync 状态.
185-
private val remotePagingStates = mutableStateMapOf<Int, Boolean>()
186-
187176
fun selectTypeIndex(index: Int) {
188177
currentQuery = currentQuery.copy(type = availableTypes[index])
189178
}
@@ -203,30 +192,10 @@ class UserCollectionsState(
203192
emitAll(startSearch(query))
204193
}
205194

206-
LazyPagingItems(pagingFlow).apply {
207-
addLoadStateListener { checkPagingState(typeIndex, it) }
208-
}
195+
LazyPagingItems(pagingFlow)
209196
}
210197
}
211198

212-
// listener is called on main thread
213-
private fun checkPagingState(typeIndex: Int, loadState: CombinedLoadStates) {
214-
val ms = loadState.mediator
215-
if (ms == null) {
216-
// 没有 remote mediator state, 说明没从 server 获取数据.
217-
remotePagingStates[typeIndex] = false
218-
onPagerFetchingAnyRemoteSource(remotePagingStates.values.any { it })
219-
return
220-
}
221-
remotePagingStates.put(
222-
typeIndex,
223-
// 加载中的状态, 正在从 server 获取数据.
224-
!ms.isIdle && !ms.hasError && ms.refresh is LoadState.Loading,
225-
)
226-
227-
onPagerFetchingAnyRemoteSource(remotePagingStates.values.any { it })
228-
}
229-
230199
fun refresh() {
231200
restarter.restart()
232201
}

app/shared/ui-subject/src/commonMain/kotlin/ui/subject/collection/UserCollectionsViewModel.kt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ package me.him188.ani.app.ui.subject.collection
1212
import androidx.compose.foundation.lazy.grid.LazyGridState
1313
import androidx.compose.runtime.Stable
1414
import androidx.compose.runtime.getValue
15-
import kotlinx.coroutines.delay
1615
import kotlinx.coroutines.flow.MutableStateFlow
1716
import kotlinx.coroutines.flow.collectLatest
1817
import kotlinx.coroutines.flow.filter
1918
import kotlinx.coroutines.flow.firstOrNull
2019
import kotlinx.coroutines.flow.flowOf
2120
import kotlinx.coroutines.flow.map
22-
import kotlinx.coroutines.launch
2321
import me.him188.ani.app.data.models.bangumi.BangumiSyncState
2422
import me.him188.ani.app.data.models.preference.MyCollectionsSettings
2523
import me.him188.ani.app.data.models.subject.SubjectCollectionInfo
@@ -43,7 +41,6 @@ import me.him188.ani.datasources.api.topic.toggleCollected
4341
import me.him188.ani.utils.logging.info
4442
import org.koin.core.component.KoinComponent
4543
import org.koin.core.component.inject
46-
import kotlin.time.Duration.Companion.seconds
4744

4845
@Stable
4946
class UserCollectionsViewModel : AbstractViewModel(), KoinComponent {
@@ -74,26 +71,6 @@ class UserCollectionsViewModel : AbstractViewModel(), KoinComponent {
7471
collectionCountsState = subjectCollectionRepository.subjectCollectionCountsFlow().produceState(null),
7572
subjectProgressStateFactory,
7673
createEditableSubjectCollectionTypeState = { createEditableSubjectCollectionTypeState(it) },
77-
onPagerFetchingAnyRemoteSource = { enable ->
78-
if (!enable) {
79-
backgroundScope.launch {
80-
try {
81-
fullSyncTasker.cancelAndJoin()
82-
} finally {
83-
fullSyncState.emit(BangumiSyncState.Finished(0, null))
84-
}
85-
}
86-
return@UserCollectionsState
87-
}
88-
89-
fullSyncTasker.launch {
90-
while (true) {
91-
val state = subjectCollectionRepository.getBangumiFullSyncState()
92-
fullSyncState.emit(state)
93-
delay(1.seconds)
94-
}
95-
}
96-
},
9774
backgroundScope,
9875
)
9976

0 commit comments

Comments
 (0)