mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
46d7d585e0
commit
6fe2f6529f
@ -21,7 +21,6 @@ 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.about.AppLogDialog
|
||||
@ -68,13 +67,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
private var precisionSearchMenuItem: MenuItem? = null
|
||||
private var isManualStopSearch = false
|
||||
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = searchFinish@{ isEmpty ->
|
||||
val searchGroup = AppConfig.searchGroup
|
||||
if (!isEmpty || searchGroup.isEmpty()) return@searchFinish
|
||||
if (!isEmpty || viewModel.searchScope.isAll()) return@searchFinish
|
||||
launch {
|
||||
alert("搜索结果为空") {
|
||||
val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch)
|
||||
if (precisionSearch) {
|
||||
setMessage("${searchGroup}分组搜索结果为空,是否关闭精准搜索?")
|
||||
setMessage("${viewModel.searchScope.display}分组搜索结果为空,是否关闭精准搜索?")
|
||||
yesButton {
|
||||
appCtx.putPrefBoolean(PreferKey.precisionSearch, false)
|
||||
precisionSearchMenuItem?.isChecked = false
|
||||
@ -82,10 +80,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
viewModel.search(searchView.query.toString())
|
||||
}
|
||||
} else {
|
||||
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组?")
|
||||
setMessage("${viewModel.searchScope.display}分组搜索结果为空,是否切换到全部分组?")
|
||||
yesButton {
|
||||
AppConfig.searchGroup = ""
|
||||
viewModel.searchKey = ""
|
||||
viewModel.searchScope.update("")
|
||||
viewModel.searchScope.save()
|
||||
viewModel.search(searchView.query.toString())
|
||||
}
|
||||
}
|
||||
@ -222,7 +220,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
searchScopeAdapter.setItems(viewModel.searchScope.getShowNames())
|
||||
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
|
||||
viewModel.isSearchLiveData.observe(this) {
|
||||
if (it) {
|
||||
startSearch()
|
||||
@ -245,7 +243,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
val searchScope = intent?.getStringExtra("searchScope")
|
||||
searchScope?.let {
|
||||
viewModel.searchScope.update(searchScope)
|
||||
searchScopeAdapter.setItems(viewModel.searchScope.getShowNames())
|
||||
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
|
||||
}
|
||||
val key = intent?.getStringExtra("key")
|
||||
if (key.isNullOrBlank()) {
|
||||
@ -277,7 +275,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
if (visible) {
|
||||
upHistory(searchView.query.toString())
|
||||
binding.llInputHelp.visibility = VISIBLE
|
||||
searchScopeAdapter.setItems(viewModel.searchScope.getShowNames())
|
||||
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
|
||||
} else {
|
||||
binding.llInputHelp.visibility = GONE
|
||||
}
|
||||
@ -385,7 +383,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
override fun onSearchScopeOk(searchScope: SearchScope) {
|
||||
searchScope.save()
|
||||
viewModel.searchScope.update(searchScope.toString())
|
||||
searchScopeAdapter.setItems(searchScope.getShowNames())
|
||||
searchScopeAdapter.setItems(searchScope.displayNames)
|
||||
}
|
||||
|
||||
private fun alertSearchScope() {
|
||||
|
@ -31,20 +31,29 @@ data class SearchScope(private var scope: String) {
|
||||
scope = "${source.bookSourceName}::${source.bookSourceUrl}"
|
||||
}
|
||||
|
||||
val display: String
|
||||
get() {
|
||||
if (scope.contains("::")) {
|
||||
return scope.substringBefore("::")
|
||||
}
|
||||
return scope
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索范围显示
|
||||
*/
|
||||
fun getShowNames(): List<String> {
|
||||
val list = arrayListOf<String>()
|
||||
if (scope.contains("::")) {
|
||||
list.add(scope.substringBefore("::"))
|
||||
} else {
|
||||
scope.splitNotBlank(",").forEach {
|
||||
list.add(it)
|
||||
val displayNames: List<String>
|
||||
get() {
|
||||
val list = arrayListOf<String>()
|
||||
if (scope.contains("::")) {
|
||||
list.add(scope.substringBefore("::"))
|
||||
} else {
|
||||
scope.splitNotBlank(",").forEach {
|
||||
list.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
list.add("全部书源")
|
||||
if (list.isEmpty()) {
|
||||
list.add("全部书源")
|
||||
}
|
||||
return list
|
||||
}
|
||||
@ -72,6 +81,10 @@ data class SearchScope(private var scope: String) {
|
||||
return list.sortedBy { it.customOrder }
|
||||
}
|
||||
|
||||
fun isAll(): Boolean {
|
||||
return scope.isEmpty()
|
||||
}
|
||||
|
||||
fun save() {
|
||||
AppConfig.searchScope = scope
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user