diff --git a/composeApp/src/commonMain/kotlin/com/corner/catvodcore/viewmodel/SiteViewModel.kt b/composeApp/src/commonMain/kotlin/com/corner/catvodcore/viewmodel/SiteViewModel.kt index 0c28892..c78da39 100644 --- a/composeApp/src/commonMain/kotlin/com/corner/catvodcore/viewmodel/SiteViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/corner/catvodcore/viewmodel/SiteViewModel.kt @@ -12,8 +12,8 @@ import com.corner.catvodcore.util.Http import com.corner.catvodcore.util.Jsons import com.corner.catvodcore.util.Utils import com.corner.catvodcore.viewmodel.GlobalModel +import com.corner.util.copyAdd import com.github.catvod.crawler.Spider -import com.github.catvod.crawler.SpiderDebug import io.ktor.http.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -270,16 +270,16 @@ object SiteViewModel { if (result.list.isEmpty()) return for (vod in result.list) vod.site = site if (quick) { - quickSearch.value.add(Collect.create(result.list)) + quickSearch.value.copyAdd(Collect.create(result.list)) if(quickSearch.value.size == 0){ - quickSearch.value.add(Collect.all()) + quickSearch.value.copyAdd(Collect.all()) } // 同样的数据添加到全部 quickSearch.value[0].list.addAll(result.list) } else { - search.value.add(Collect.create(result.list)) + search.value.copyAdd(Collect.create(result.list)) if(search.value.size == 0){ - search.value.add(Collect.all()) + search.value.copyAdd(Collect.all()) } // 同样的数据添加到全部 search.value[0].list.addAll(result.list) diff --git a/composeApp/src/commonMain/kotlin/com/corner/util/extensions.kt b/composeApp/src/commonMain/kotlin/com/corner/util/extensions.kt index 3eab675..bd82682 100644 --- a/composeApp/src/commonMain/kotlin/com/corner/util/extensions.kt +++ b/composeApp/src/commonMain/kotlin/com/corner/util/extensions.kt @@ -3,11 +3,13 @@ package com.corner.util import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color +import cn.hutool.core.collection.CollectionUtil import cn.hutool.core.util.CharUtil import com.corner.catvod.enum.bean.Site import io.ktor.util.* import kotlinx.coroutines.Job import org.apache.commons.lang3.StringUtils +import java.util.concurrent.CopyOnWriteArrayList import java.util.concurrent.TimeUnit fun Site.isEmpty():Boolean{ @@ -83,4 +85,13 @@ fun String.trimBlankChar():String{ var Color.Companion.FirefoxGray:Color get() = Color(59, 59, 60) - set(value) {} \ No newline at end of file + set(value) {} + + +fun CopyOnWriteArrayList.copyAdd(item: E? = null, list: CopyOnWriteArrayList? = null): CopyOnWriteArrayList { + return CopyOnWriteArrayList().apply { + addAll(this) + if(item != null) add(item) + if(CollectionUtil.isNotEmpty(list)) addAll(list!!) + } +} \ No newline at end of file