pull/1649/head
kunfei 3 years ago
parent 797e236bf3
commit b0b2cc302b
  1. 5
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt

@ -4,6 +4,7 @@ import android.app.Application
import android.os.Bundle
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import cn.hutool.core.collection.ConcurrentHashSet
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern
@ -33,7 +34,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
var name: String = ""
var author: String = ""
val dataFlow = callbackFlow<List<SearchBook>> {
val searchBooks = arrayListOf<SearchBook>()
val searchBooks = ConcurrentHashSet<SearchBook>()
searchSuccess = {
if (!searchBooks.contains(it)) {
@ -44,7 +45,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
appDb.searchBookDao.getEnableHasCover(name, author).let {
searchBooks.addAll(it)
trySend(searchBooks)
trySend(ArrayList(searchBooks))
}
if (searchBooks.size <= 1) {

@ -4,6 +4,7 @@ import android.app.Application
import android.os.Bundle
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import cn.hutool.core.collection.ConcurrentHashSet
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppPattern
@ -27,7 +28,6 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import splitties.init.appCtx
import timber.log.Timber
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.Executors
import kotlin.math.min
@ -41,7 +41,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
private var tasks = CompositeCoroutine()
private var screenKey: String = ""
private var bookSourceList = arrayListOf<BookSource>()
private val searchBooks = CopyOnWriteArrayList<SearchBook>()
private val searchBooks = ConcurrentHashSet<SearchBook>()
private val searchGroup get() = appCtx.getPrefString("searchGroup") ?: ""
private var searchCallback: SourceCallback? = null
val searchDataFlow = callbackFlow {
@ -50,9 +50,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
override fun searchSuccess(searchBook: SearchBook) {
appDb.searchBookDao.insert(searchBook)
val index = searchBooks.indexOf(searchBook)
when {
index >= 0 -> searchBooks[index] = searchBook
screenKey.isEmpty() -> searchBooks.add(searchBook)
searchBook.name.contains(screenKey) -> searchBooks.add(searchBook)
else -> return

Loading…
Cancel
Save