fix: 吧页面闪退
This commit is contained in:
parent
6c6ad0d4a9
commit
20651f5add
|
|
@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.merge
|
import kotlinx.coroutines.flow.merge
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
abstract class ForumThreadListViewModel :
|
abstract class ForumThreadListViewModel :
|
||||||
BaseViewModel<ForumThreadListUiIntent, ForumThreadListPartialChange, ForumThreadListUiState, ForumThreadListUiEvent>() {
|
BaseViewModel<ForumThreadListUiIntent, ForumThreadListPartialChange, ForumThreadListUiState, ForumThreadListUiEvent>() {
|
||||||
|
|
@ -140,12 +141,13 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
|
||||||
|
|
||||||
private fun ForumThreadListUiIntent.LoadMore.producePartialChange(): Flow<ForumThreadListPartialChange.LoadMore> {
|
private fun ForumThreadListUiIntent.LoadMore.producePartialChange(): Flow<ForumThreadListPartialChange.LoadMore> {
|
||||||
val flow = if (threadListIds.isNotEmpty()) {
|
val flow = if (threadListIds.isNotEmpty()) {
|
||||||
|
val size = min(threadListIds.size, 30)
|
||||||
TiebaApi.getInstance().threadList(
|
TiebaApi.getInstance().threadList(
|
||||||
forumId,
|
forumId,
|
||||||
forumName,
|
forumName,
|
||||||
currentPage,
|
currentPage,
|
||||||
sortType,
|
sortType,
|
||||||
threadListIds.subList(0, 30).joinToString(separator = ",") { "$it" }
|
threadListIds.subList(0, size).joinToString(separator = ",") { "$it" }
|
||||||
).map { response ->
|
).map { response ->
|
||||||
if (response.data_ == null) ForumThreadListPartialChange.LoadMore.Failure(
|
if (response.data_ == null) ForumThreadListPartialChange.LoadMore.Failure(
|
||||||
NullPointerException("未知错误")
|
NullPointerException("未知错误")
|
||||||
|
|
@ -157,7 +159,7 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
|
||||||
}
|
}
|
||||||
ForumThreadListPartialChange.LoadMore.Success(
|
ForumThreadListPartialChange.LoadMore.Success(
|
||||||
threadList = threadList,
|
threadList = threadList,
|
||||||
threadListIds = threadListIds.drop(30),
|
threadListIds = threadListIds.drop(size),
|
||||||
currentPage = currentPage,
|
currentPage = currentPage,
|
||||||
hasMore = threadList.isNotEmpty()
|
hasMore = threadList.isNotEmpty()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue