diff --git a/app/src/main/java/io/legado/app/model/webBook/SearchModel.kt b/app/src/main/java/io/legado/app/model/webBook/SearchModel.kt index 0e92d9acd..c8cc3b82f 100644 --- a/app/src/main/java/io/legado/app/model/webBook/SearchModel.kt +++ b/app/src/main/java/io/legado/app/model/webBook/SearchModel.kt @@ -8,7 +8,6 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.help.config.AppConfig import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getPrefString import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExecutorCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher @@ -60,7 +59,7 @@ class SearchModel(private val scope: CoroutineScope) { initSearchPool() mSearchId = searchId searchPage = 1 - val searchGroup = appCtx.getPrefString("searchGroup") ?: "" + val searchGroup = AppConfig.searchGroup bookSourceList.clear() searchBooks.clear() callBack?.onSearchSuccess(searchBooks) @@ -69,6 +68,7 @@ class SearchModel(private val scope: CoroutineScope) { } else { val sources = appDb.bookSourceDao.getEnabledByGroup(searchGroup) if (sources.isEmpty()) { + AppConfig.searchGroup = "" bookSourceList.addAll(appDb.bookSourceDao.allEnabled) } else { bookSourceList.addAll(sources) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index d7bb6354b..ba49a97f4 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -298,7 +298,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ */ private fun upGroupMenu() { val menu: Menu = binding.toolBar.menu - val selectedGroup = getPrefString("searchGroup") + val selectedGroup = AppConfig.searchGroup menu.removeGroup(R.id.source_group) val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) var hasSelectedGroup = false diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt index 4ddf26683..481a30437 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt @@ -331,7 +331,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c */ private fun upGroupMenu() { val menu: Menu = binding.toolBar.menu - val selectedGroup = getPrefString("searchGroup") + val selectedGroup = AppConfig.searchGroup menu.removeGroup(R.id.source_group) val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) var hasSelectedGroup = false diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index edd79ab82..bb6463608 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -22,6 +22,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchKeyword import io.legado.app.databinding.ActivityBookSearchBinding +import io.legado.app.help.config.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.* import io.legado.app.ui.book.info.BookInfoActivity @@ -66,14 +67,14 @@ class SearchActivity : VMBaseActivity() 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.searchKey = "" viewModel.search(searchView.query.toString()) } @@ -123,9 +124,9 @@ class SearchActivity : VMBaseActivity if (item.groupId == R.id.source_group) { 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() } searchView.query?.toString()?.trim()?.let { searchView.setQuery(it, true) @@ -280,7 +281,7 @@ class SearchActivity : VMBaseActivity - val selectedGroup = getPrefString("searchGroup") + val selectedGroup = AppConfig.searchGroup menu.removeGroup(R.id.source_group) val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) var hasSelectedGroup = false