优化
This commit is contained in:
@@ -52,9 +52,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
setHasStableIds(true)
|
setHasStableIds(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private val searchScopeAdapter by lazy {
|
|
||||||
SearchScopeAdapter(this)
|
|
||||||
}
|
|
||||||
private val historyKeyAdapter by lazy {
|
private val historyKeyAdapter by lazy {
|
||||||
HistoryKeyAdapter(this, this).apply {
|
HistoryKeyAdapter(this, this).apply {
|
||||||
setHasStableIds(true)
|
setHasStableIds(true)
|
||||||
@@ -63,6 +60,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
private val searchView: SearchView by lazy {
|
private val searchView: SearchView by lazy {
|
||||||
binding.titleBar.findViewById(R.id.search_view)
|
binding.titleBar.findViewById(R.id.search_view)
|
||||||
}
|
}
|
||||||
|
private var menu: Menu? = null
|
||||||
private var historyFlowJob: Job? = null
|
private var historyFlowJob: Job? = null
|
||||||
private var booksFlowJob: Job? = null
|
private var booksFlowJob: Job? = null
|
||||||
private var precisionSearchMenuItem: MenuItem? = null
|
private var precisionSearchMenuItem: MenuItem? = null
|
||||||
@@ -110,6 +108,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
|
|
||||||
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.book_search, menu)
|
menuInflater.inflate(R.menu.book_search, menu)
|
||||||
|
this.menu = menu
|
||||||
|
upSearchScopeMenu()
|
||||||
precisionSearchMenuItem = menu.findItem(R.id.menu_precision_search)
|
precisionSearchMenuItem = menu.findItem(R.id.menu_precision_search)
|
||||||
precisionSearchMenuItem?.isChecked = getPrefBoolean(PreferKey.precisionSearch)
|
precisionSearchMenuItem?.isChecked = getPrefBoolean(PreferKey.precisionSearch)
|
||||||
return super.onCompatCreateOptionsMenu(menu)
|
return super.onCompatCreateOptionsMenu(menu)
|
||||||
@@ -171,10 +171,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
|
|
||||||
private fun initRecyclerView() {
|
private fun initRecyclerView() {
|
||||||
binding.recyclerView.setEdgeEffectColor(primaryColor)
|
binding.recyclerView.setEdgeEffectColor(primaryColor)
|
||||||
binding.rvSearchScope.setEdgeEffectColor(primaryColor)
|
|
||||||
binding.rvBookshelfSearch.setEdgeEffectColor(primaryColor)
|
binding.rvBookshelfSearch.setEdgeEffectColor(primaryColor)
|
||||||
binding.rvHistoryKey.setEdgeEffectColor(primaryColor)
|
binding.rvHistoryKey.setEdgeEffectColor(primaryColor)
|
||||||
binding.rvSearchScope.adapter = searchScopeAdapter
|
|
||||||
binding.rvBookshelfSearch.layoutManager = FlexboxLayoutManager(this)
|
binding.rvBookshelfSearch.layoutManager = FlexboxLayoutManager(this)
|
||||||
binding.rvBookshelfSearch.adapter = bookAdapter
|
binding.rvBookshelfSearch.adapter = bookAdapter
|
||||||
binding.rvHistoryKey.layoutManager = FlexboxLayoutManager(this)
|
binding.rvHistoryKey.layoutManager = FlexboxLayoutManager(this)
|
||||||
@@ -217,14 +215,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
viewModel.stop()
|
viewModel.stop()
|
||||||
binding.refreshProgressBar.isAutoLoading = false
|
binding.refreshProgressBar.isAutoLoading = false
|
||||||
}
|
}
|
||||||
binding.tvToggleSearchScope.setOnClickListener { alertSearchScope() }
|
|
||||||
binding.tvClearHistory.setOnClickListener { alertClearHistory() }
|
binding.tvClearHistory.setOnClickListener { alertClearHistory() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
|
|
||||||
viewModel.searchScope.stateLiveData.observe(this) {
|
viewModel.searchScope.stateLiveData.observe(this) {
|
||||||
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
|
upSearchScopeMenu()
|
||||||
}
|
}
|
||||||
viewModel.isSearchLiveData.observe(this) {
|
viewModel.isSearchLiveData.observe(this) {
|
||||||
if (it) {
|
if (it) {
|
||||||
@@ -241,6 +237,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun upSearchScopeMenu() {
|
||||||
|
menu?.findItem(R.id.menu_search_scope)?.title =
|
||||||
|
"${getString(R.string.search_scope)}-${viewModel.searchScope.display}"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理传入数据
|
* 处理传入数据
|
||||||
*/
|
*/
|
||||||
@@ -248,7 +249,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
val searchScope = intent?.getStringExtra("searchScope")
|
val searchScope = intent?.getStringExtra("searchScope")
|
||||||
searchScope?.let {
|
searchScope?.let {
|
||||||
viewModel.searchScope.update(searchScope)
|
viewModel.searchScope.update(searchScope)
|
||||||
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
|
upSearchScopeMenu()
|
||||||
}
|
}
|
||||||
val key = intent?.getStringExtra("key")
|
val key = intent?.getStringExtra("key")
|
||||||
if (key.isNullOrBlank()) {
|
if (key.isNullOrBlank()) {
|
||||||
@@ -280,7 +281,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
if (visible) {
|
if (visible) {
|
||||||
upHistory(searchView.query.toString())
|
upHistory(searchView.query.toString())
|
||||||
binding.llInputHelp.visibility = VISIBLE
|
binding.llInputHelp.visibility = VISIBLE
|
||||||
searchScopeAdapter.setItems(viewModel.searchScope.displayNames)
|
|
||||||
} else {
|
} else {
|
||||||
binding.llInputHelp.visibility = GONE
|
binding.llInputHelp.visibility = GONE
|
||||||
}
|
}
|
||||||
@@ -388,7 +388,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
override fun onSearchScopeOk(searchScope: SearchScope) {
|
override fun onSearchScopeOk(searchScope: SearchScope) {
|
||||||
searchScope.save()
|
searchScope.save()
|
||||||
viewModel.searchScope.update(searchScope.toString())
|
viewModel.searchScope.update(searchScope.toString())
|
||||||
searchScopeAdapter.setItems(searchScope.displayNames)
|
|
||||||
if (!binding.llInputHelp.isVisible) {
|
if (!binding.llInputHelp.isVisible) {
|
||||||
searchView.query?.toString()?.trim()?.let {
|
searchView.query?.toString()?.trim()?.let {
|
||||||
searchView.setQuery(it, true)
|
searchView.setQuery(it, true)
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package io.legado.app.ui.book.search
|
package io.legado.app.ui.book.search
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import io.legado.app.R
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.utils.splitNotBlank
|
import io.legado.app.utils.splitNotBlank
|
||||||
|
import splitties.init.appCtx
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索范围
|
* 搜索范围
|
||||||
@@ -26,6 +28,7 @@ data class SearchScope(private var scope: String) {
|
|||||||
|
|
||||||
fun update(scope: String) {
|
fun update(scope: String) {
|
||||||
this.scope = scope
|
this.scope = scope
|
||||||
|
stateLiveData.postValue(scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update(groups: List<String>) {
|
fun update(groups: List<String>) {
|
||||||
@@ -41,6 +44,9 @@ data class SearchScope(private var scope: String) {
|
|||||||
if (scope.contains("::")) {
|
if (scope.contains("::")) {
|
||||||
return scope.substringBefore("::")
|
return scope.substringBefore("::")
|
||||||
}
|
}
|
||||||
|
if (scope.isEmpty()) {
|
||||||
|
return appCtx.getString(R.string.all_source)
|
||||||
|
}
|
||||||
return scope
|
return scope
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +64,7 @@ data class SearchScope(private var scope: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
list.add("全部书源")
|
list.add(appCtx.getString(R.string.all_source))
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
@@ -83,12 +89,12 @@ data class SearchScope(private var scope: String) {
|
|||||||
}
|
}
|
||||||
if (oldScope.size != newScope.size) {
|
if (oldScope.size != newScope.size) {
|
||||||
update(newScope)
|
update(newScope)
|
||||||
stateLiveData.postValue("")
|
stateLiveData.postValue(scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
scope = ""
|
scope = ""
|
||||||
stateLiveData.postValue("")
|
stateLiveData.postValue(scope)
|
||||||
return appDb.bookSourceDao.allEnabled
|
return appDb.bookSourceDao.allEnabled
|
||||||
}
|
}
|
||||||
return list.sortedBy { it.customOrder }
|
return list.sortedBy { it.customOrder }
|
||||||
|
|||||||
@@ -48,35 +48,6 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/title_bar">
|
app:layout_constraintTop_toBottomOf="@id/title_bar">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:padding="6dp"
|
|
||||||
android:text="@string/search_scope" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_toggle_search_scope"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
|
||||||
android:padding="6dp"
|
|
||||||
android:text="@string/toggle_search_scope" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/rv_search_scope"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_book_show"
|
android:id="@+id/tv_book_show"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user