Merge pull request #74 from KKL369/master

修复书籍搜索“精准搜索”
pull/78/head
kunfei 5 years ago committed by GitHub
commit bd8e745838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -76,6 +76,9 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
!getPrefBoolean(PreferKey.precisionSearch)
)
precisionSearchMenuItem?.isChecked = getPrefBoolean(PreferKey.precisionSearch)
search_view.query.toString().trim()?.let {
search_view.setQuery(it, true)
}
}
R.id.menu_source_manage -> startActivity<BookSourceActivity>()
else -> if (item.groupId == R.id.source_group) {
@ -85,6 +88,9 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
} else {
putPrefString("searchGroup", item.title.toString())
}
search_view.query.toString().trim()?.let {
search_view.setQuery(it, true)
}
}
}
return super.onCompatOptionsItemSelected(item)

@ -72,8 +72,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
val books = arrayListOf<SearchBook>()
searchBooks.forEach { searchBook ->
if (context.getPrefBoolean(PreferKey.precisionSearch)) {
if (searchBook.name.contains(searchKey)
|| searchBook.author.contains(searchKey)
if (searchBook.name.equals(searchKey, true)
|| searchBook.author.equals(searchKey, true)
) books.add(searchBook)
} else
books.add(searchBook)

Loading…
Cancel
Save