@@ -67,7 +67,6 @@ import androidx.compose.runtime.State
6767import androidx.compose.runtime.derivedStateOf
6868import androidx.compose.runtime.getValue
6969import androidx.compose.runtime.mutableStateListOf
70- import androidx.compose.runtime.mutableStateMapOf
7170import androidx.compose.runtime.mutableStateOf
7271import androidx.compose.runtime.remember
7372import androidx.compose.runtime.rememberCoroutineScope
@@ -84,8 +83,6 @@ import androidx.compose.ui.text.style.TextAlign
8483import androidx.compose.ui.unit.DpSize
8584import androidx.compose.ui.unit.dp
8685import androidx.lifecycle.compose.collectAsStateWithLifecycle
87- import androidx.paging.CombinedLoadStates
88- import androidx.paging.LoadState
8986import androidx.paging.PagingData
9087import androidx.paging.compose.LazyPagingItems
9188import 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 }
0 commit comments