Skip to content

Commit

Permalink
fix: 搜索页面 集合不能更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Greatwallcorner committed Nov 8, 2024
1 parent d08337d commit dd9109c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion composeApp/src/commonMain/kotlin/com/corner/util/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -83,4 +85,13 @@ fun String.trimBlankChar():String{

var Color.Companion.FirefoxGray:Color
get() = Color(59, 59, 60)
set(value) {}
set(value) {}


fun <E> CopyOnWriteArrayList<E>.copyAdd(item: E? = null, list: CopyOnWriteArrayList<E>? = null): CopyOnWriteArrayList<E> {
return CopyOnWriteArrayList<E>().apply {
addAll(this)
if(item != null) add(item)
if(CollectionUtil.isNotEmpty(list)) addAll(list!!)
}
}

0 comments on commit dd9109c

Please sign in to comment.