mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -85,6 +85,9 @@ interface BookSourceDao {
|
||||
@Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'")
|
||||
fun getEnabledByGroup(group: String): List<BookSource>
|
||||
|
||||
@Query("select * from book_sources where enabled = 1 and bookSourceType = :type")
|
||||
fun getEnabledByType(type: Int): List<BookSource>
|
||||
|
||||
@get:Query("select * from book_sources where trim(bookUrlPattern) <> '' order by enabled desc, customOrder")
|
||||
val hasBookUrlPattern: List<BookSource>
|
||||
|
||||
|
||||
@@ -301,6 +301,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
val doublePageHorizontal: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.doublePageHorizontal, true)
|
||||
|
||||
var searchGroup: String
|
||||
get() = appCtx.getPrefString("searchGroup") ?: ""
|
||||
set(value) {
|
||||
appCtx.putPrefString("searchGroup", value)
|
||||
}
|
||||
|
||||
private fun getPrefUserAgent(): String {
|
||||
val ua = appCtx.getPrefString(PreferKey.userAgent)
|
||||
if (ua.isNullOrBlank()) {
|
||||
|
||||
@@ -60,14 +60,14 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
||||
}
|
||||
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
|
||||
if (it) {
|
||||
val searchGroup = getPrefString("searchGroup")
|
||||
if (!searchGroup.isNullOrEmpty()) {
|
||||
val searchGroup = AppConfig.searchGroup
|
||||
if (searchGroup.isNotEmpty()) {
|
||||
launch {
|
||||
alert("搜索结果为空") {
|
||||
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
|
||||
cancelButton()
|
||||
okButton {
|
||||
putPrefString("searchGroup", "")
|
||||
AppConfig.searchGroup = ""
|
||||
viewModel.startSearch()
|
||||
}
|
||||
}
|
||||
@@ -221,9 +221,9 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
||||
if (!item.isChecked) {
|
||||
item.isChecked = true
|
||||
if (item.title.toString() == getString(R.string.all_source)) {
|
||||
putPrefString("searchGroup", "")
|
||||
AppConfig.searchGroup = ""
|
||||
} else {
|
||||
putPrefString("searchGroup", item.title.toString())
|
||||
AppConfig.searchGroup = item.title.toString()
|
||||
}
|
||||
viewModel.startOrStopSearch()
|
||||
viewModel.refresh()
|
||||
|
||||
@@ -20,7 +20,6 @@ import io.legado.app.help.coroutine.CompositeCoroutine
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.utils.getPrefBoolean
|
||||
import io.legado.app.utils.getPrefString
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
@@ -31,7 +30,6 @@ import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withContext
|
||||
import splitties.init.appCtx
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executors
|
||||
@@ -50,7 +48,6 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
private var bookSourceList = arrayListOf<BookSource>()
|
||||
private val searchBooks = Collections.synchronizedList(arrayListOf<SearchBook>())
|
||||
private val tocMap = ConcurrentHashMap<String, List<BookChapter>>()
|
||||
private val searchGroup get() = appCtx.getPrefString("searchGroup") ?: ""
|
||||
private var searchCallback: SourceCallback? = null
|
||||
val searchDataFlow = callbackFlow {
|
||||
|
||||
@@ -129,11 +126,13 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
appDb.searchBookDao.clear(name, author)
|
||||
searchBooks.clear()
|
||||
bookSourceList.clear()
|
||||
val searchGroup = AppConfig.searchGroup
|
||||
if (searchGroup.isBlank()) {
|
||||
bookSourceList.addAll(appDb.bookSourceDao.allEnabled)
|
||||
} else {
|
||||
val sources = appDb.bookSourceDao.getEnabledByGroup(searchGroup)
|
||||
if (sources.isEmpty()) {
|
||||
AppConfig.searchGroup = ""
|
||||
bookSourceList.addAll(appDb.bookSourceDao.allEnabled)
|
||||
} else {
|
||||
bookSourceList.addAll(sources)
|
||||
@@ -224,15 +223,25 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
private fun getDbSearchBooks(): List<SearchBook> {
|
||||
return if (screenKey.isEmpty()) {
|
||||
if (AppConfig.changeSourceCheckAuthor) {
|
||||
appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup)
|
||||
appDb.searchBookDao.getChangeSourceSearch(name, author, AppConfig.searchGroup)
|
||||
} else {
|
||||
appDb.searchBookDao.getChangeSourceSearch(name, "", searchGroup)
|
||||
appDb.searchBookDao.getChangeSourceSearch(name, "", AppConfig.searchGroup)
|
||||
}
|
||||
} else {
|
||||
if (AppConfig.changeSourceCheckAuthor) {
|
||||
appDb.searchBookDao.getChangeSourceSearch(name, author, screenKey, searchGroup)
|
||||
appDb.searchBookDao.getChangeSourceSearch(
|
||||
name,
|
||||
author,
|
||||
screenKey,
|
||||
AppConfig.searchGroup
|
||||
)
|
||||
} else {
|
||||
appDb.searchBookDao.getChangeSourceSearch(name, "", screenKey, searchGroup)
|
||||
appDb.searchBookDao.getChangeSourceSearch(
|
||||
name,
|
||||
"",
|
||||
screenKey,
|
||||
AppConfig.searchGroup
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
private var searchBook: SearchBook? = null
|
||||
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
|
||||
if (it) {
|
||||
val searchGroup = getPrefString("searchGroup")
|
||||
if (!searchGroup.isNullOrEmpty()) {
|
||||
val searchGroup = AppConfig.searchGroup
|
||||
if (searchGroup.isNotEmpty()) {
|
||||
launch {
|
||||
alert("搜索结果为空") {
|
||||
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
|
||||
cancelButton()
|
||||
okButton {
|
||||
putPrefString("searchGroup", "")
|
||||
AppConfig.searchGroup = ""
|
||||
viewModel.startSearch()
|
||||
}
|
||||
}
|
||||
@@ -245,9 +245,9 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
if (!item.isChecked) {
|
||||
item.isChecked = true
|
||||
if (item.title.toString() == getString(R.string.all_source)) {
|
||||
putPrefString("searchGroup", "")
|
||||
AppConfig.searchGroup = ""
|
||||
} else {
|
||||
putPrefString("searchGroup", item.title.toString())
|
||||
AppConfig.searchGroup = item.title.toString()
|
||||
}
|
||||
viewModel.startOrStopSearch()
|
||||
viewModel.refresh()
|
||||
|
||||
Reference in New Issue
Block a user