kunfei 4 лет назад
Родитель
Сommit
76bd5c3b3c

+ 3 - 0
app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt

@@ -85,6 +85,9 @@ interface BookSourceDao {
     @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'")
     @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'")
     fun getEnabledByGroup(group: String): List<BookSource>
     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")
     @get:Query("select * from book_sources where trim(bookUrlPattern) <> '' order by enabled desc, customOrder")
     val hasBookUrlPattern: List<BookSource>
     val hasBookUrlPattern: List<BookSource>
 
 

+ 6 - 0
app/src/main/java/io/legado/app/help/config/AppConfig.kt

@@ -301,6 +301,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
     val doublePageHorizontal: Boolean
     val doublePageHorizontal: Boolean
         get() = appCtx.getPrefBoolean(PreferKey.doublePageHorizontal, true)
         get() = appCtx.getPrefBoolean(PreferKey.doublePageHorizontal, true)
 
 
+    var searchGroup: String
+        get() = appCtx.getPrefString("searchGroup") ?: ""
+        set(value) {
+            appCtx.putPrefString("searchGroup", value)
+        }
+
     private fun getPrefUserAgent(): String {
     private fun getPrefUserAgent(): String {
         val ua = appCtx.getPrefString(PreferKey.userAgent)
         val ua = appCtx.getPrefString(PreferKey.userAgent)
         if (ua.isNullOrBlank()) {
         if (ua.isNullOrBlank()) {

+ 5 - 5
app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt

@@ -60,14 +60,14 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
         }
         }
     private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
     private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
         if (it) {
         if (it) {
-            val searchGroup = getPrefString("searchGroup")
-            if (!searchGroup.isNullOrEmpty()) {
+            val searchGroup = AppConfig.searchGroup
+            if (searchGroup.isNotEmpty()) {
                 launch {
                 launch {
                     alert("搜索结果为空") {
                     alert("搜索结果为空") {
                         setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
                         setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
                         cancelButton()
                         cancelButton()
                         okButton {
                         okButton {
-                            putPrefString("searchGroup", "")
+                            AppConfig.searchGroup = ""
                             viewModel.startSearch()
                             viewModel.startSearch()
                         }
                         }
                     }
                     }
@@ -221,9 +221,9 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
                 if (!item.isChecked) {
                 if (!item.isChecked) {
                     item.isChecked = true
                     item.isChecked = true
                     if (item.title.toString() == getString(R.string.all_source)) {
                     if (item.title.toString() == getString(R.string.all_source)) {
-                        putPrefString("searchGroup", "")
+                        AppConfig.searchGroup = ""
                     } else {
                     } else {
-                        putPrefString("searchGroup", item.title.toString())
+                        AppConfig.searchGroup = item.title.toString()
                     }
                     }
                     viewModel.startOrStopSearch()
                     viewModel.startOrStopSearch()
                     viewModel.refresh()
                     viewModel.refresh()

+ 16 - 7
app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt

@@ -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
+                )
             }
             }
         }
         }
     }
     }

+ 5 - 5
app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt

@@ -75,14 +75,14 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
     private var searchBook: SearchBook? = null
     private var searchBook: SearchBook? = null
     private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
     private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
         if (it) {
         if (it) {
-            val searchGroup = getPrefString("searchGroup")
-            if (!searchGroup.isNullOrEmpty()) {
+            val searchGroup = AppConfig.searchGroup
+            if (searchGroup.isNotEmpty()) {
                 launch {
                 launch {
                     alert("搜索结果为空") {
                     alert("搜索结果为空") {
                         setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
                         setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
                         cancelButton()
                         cancelButton()
                         okButton {
                         okButton {
-                            putPrefString("searchGroup", "")
+                            AppConfig.searchGroup = ""
                             viewModel.startSearch()
                             viewModel.startSearch()
                         }
                         }
                     }
                     }
@@ -245,9 +245,9 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
                 if (!item.isChecked) {
                 if (!item.isChecked) {
                     item.isChecked = true
                     item.isChecked = true
                     if (item.title.toString() == getString(R.string.all_source)) {
                     if (item.title.toString() == getString(R.string.all_source)) {
-                        putPrefString("searchGroup", "")
+                        AppConfig.searchGroup = ""
                     } else {
                     } else {
-                        putPrefString("searchGroup", item.title.toString())
+                        AppConfig.searchGroup = item.title.toString()
                     }
                     }
                     viewModel.startOrStopSearch()
                     viewModel.startOrStopSearch()
                     viewModel.refresh()
                     viewModel.refresh()