|
|
@ -20,7 +20,6 @@ import io.legado.app.help.coroutine.CompositeCoroutine |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
import io.legado.app.utils.getPrefBoolean |
|
|
|
import io.legado.app.utils.getPrefString |
|
|
|
|
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import io.legado.app.utils.toastOnUi |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
@ -31,7 +30,6 @@ import kotlinx.coroutines.flow.callbackFlow |
|
|
|
import kotlinx.coroutines.flow.flowOn |
|
|
|
import kotlinx.coroutines.flow.flowOn |
|
|
|
import kotlinx.coroutines.flow.map |
|
|
|
import kotlinx.coroutines.flow.map |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import splitties.init.appCtx |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
import java.util.concurrent.Executors |
|
|
|
import java.util.concurrent.Executors |
|
|
@ -50,7 +48,6 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a |
|
|
|
private var bookSourceList = arrayListOf<BookSource>() |
|
|
|
private var bookSourceList = arrayListOf<BookSource>() |
|
|
|
private val searchBooks = Collections.synchronizedList(arrayListOf<SearchBook>()) |
|
|
|
private val searchBooks = Collections.synchronizedList(arrayListOf<SearchBook>()) |
|
|
|
private val tocMap = ConcurrentHashMap<String, List<BookChapter>>() |
|
|
|
private val tocMap = ConcurrentHashMap<String, List<BookChapter>>() |
|
|
|
private val searchGroup get() = appCtx.getPrefString("searchGroup") ?: "" |
|
|
|
|
|
|
|
private var searchCallback: SourceCallback? = null |
|
|
|
private var searchCallback: SourceCallback? = null |
|
|
|
val searchDataFlow = callbackFlow { |
|
|
|
val searchDataFlow = callbackFlow { |
|
|
|
|
|
|
|
|
|
|
@ -129,11 +126,13 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a |
|
|
|
appDb.searchBookDao.clear(name, author) |
|
|
|
appDb.searchBookDao.clear(name, author) |
|
|
|
searchBooks.clear() |
|
|
|
searchBooks.clear() |
|
|
|
bookSourceList.clear() |
|
|
|
bookSourceList.clear() |
|
|
|
|
|
|
|
val searchGroup = AppConfig.searchGroup |
|
|
|
if (searchGroup.isBlank()) { |
|
|
|
if (searchGroup.isBlank()) { |
|
|
|
bookSourceList.addAll(appDb.bookSourceDao.allEnabled) |
|
|
|
bookSourceList.addAll(appDb.bookSourceDao.allEnabled) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val sources = appDb.bookSourceDao.getEnabledByGroup(searchGroup) |
|
|
|
val sources = appDb.bookSourceDao.getEnabledByGroup(searchGroup) |
|
|
|
if (sources.isEmpty()) { |
|
|
|
if (sources.isEmpty()) { |
|
|
|
|
|
|
|
AppConfig.searchGroup = "" |
|
|
|
bookSourceList.addAll(appDb.bookSourceDao.allEnabled) |
|
|
|
bookSourceList.addAll(appDb.bookSourceDao.allEnabled) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bookSourceList.addAll(sources) |
|
|
|
bookSourceList.addAll(sources) |
|
|
@ -224,15 +223,25 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a |
|
|
|
private fun getDbSearchBooks(): List<SearchBook> { |
|
|
|
private fun getDbSearchBooks(): List<SearchBook> { |
|
|
|
return if (screenKey.isEmpty()) { |
|
|
|
return if (screenKey.isEmpty()) { |
|
|
|
if (AppConfig.changeSourceCheckAuthor) { |
|
|
|
if (AppConfig.changeSourceCheckAuthor) { |
|
|
|
appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup) |
|
|
|
appDb.searchBookDao.getChangeSourceSearch(name, author, AppConfig.searchGroup) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
appDb.searchBookDao.getChangeSourceSearch(name, "", searchGroup) |
|
|
|
appDb.searchBookDao.getChangeSourceSearch(name, "", AppConfig.searchGroup) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (AppConfig.changeSourceCheckAuthor) { |
|
|
|
if (AppConfig.changeSourceCheckAuthor) { |
|
|
|
appDb.searchBookDao.getChangeSourceSearch(name, author, screenKey, searchGroup) |
|
|
|
appDb.searchBookDao.getChangeSourceSearch( |
|
|
|
|
|
|
|
name, |
|
|
|
|
|
|
|
author, |
|
|
|
|
|
|
|
screenKey, |
|
|
|
|
|
|
|
AppConfig.searchGroup |
|
|
|
|
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
appDb.searchBookDao.getChangeSourceSearch(name, "", screenKey, searchGroup) |
|
|
|
appDb.searchBookDao.getChangeSourceSearch( |
|
|
|
|
|
|
|
name, |
|
|
|
|
|
|
|
"", |
|
|
|
|
|
|
|
screenKey, |
|
|
|
|
|
|
|
AppConfig.searchGroup |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|