|
|
@ -44,7 +44,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
private lateinit var bookAdapter: BookAdapter |
|
|
|
private lateinit var bookAdapter: BookAdapter |
|
|
|
private lateinit var historyKeyAdapter: HistoryKeyAdapter |
|
|
|
private lateinit var historyKeyAdapter: HistoryKeyAdapter |
|
|
|
private lateinit var loadMoreView: LoadMoreView |
|
|
|
private lateinit var loadMoreView: LoadMoreView |
|
|
|
private lateinit var serchView: SearchView |
|
|
|
private lateinit var searchView: SearchView |
|
|
|
private var historyData: LiveData<List<SearchKeyword>>? = null |
|
|
|
private var historyData: LiveData<List<SearchKeyword>>? = null |
|
|
|
private var bookData: LiveData<List<Book>>? = null |
|
|
|
private var bookData: LiveData<List<Book>>? = null |
|
|
|
private var menu: Menu? = null |
|
|
|
private var menu: Menu? = null |
|
|
@ -57,7 +57,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
binding.llHistory.setBackgroundColor(backgroundColor) |
|
|
|
binding.llHistory.setBackgroundColor(backgroundColor) |
|
|
|
serchView = binding.titleBar.findViewById(R.id.search_view) |
|
|
|
searchView = binding.titleBar.findViewById(R.id.search_view) |
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
|
initSearchView() |
|
|
|
initSearchView() |
|
|
|
initOtherView() |
|
|
|
initOtherView() |
|
|
@ -87,8 +87,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
!getPrefBoolean(PreferKey.precisionSearch) |
|
|
|
!getPrefBoolean(PreferKey.precisionSearch) |
|
|
|
) |
|
|
|
) |
|
|
|
precisionSearchMenuItem?.isChecked = getPrefBoolean(PreferKey.precisionSearch) |
|
|
|
precisionSearchMenuItem?.isChecked = getPrefBoolean(PreferKey.precisionSearch) |
|
|
|
serchView.query?.toString()?.trim()?.let { |
|
|
|
searchView.query?.toString()?.trim()?.let { |
|
|
|
serchView.setQuery(it, true) |
|
|
|
searchView.setQuery(it, true) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_source_manage -> startActivity<BookSourceActivity>() |
|
|
|
R.id.menu_source_manage -> startActivity<BookSourceActivity>() |
|
|
@ -99,8 +99,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
putPrefString("searchGroup", item.title.toString()) |
|
|
|
putPrefString("searchGroup", item.title.toString()) |
|
|
|
} |
|
|
|
} |
|
|
|
serchView.query?.toString()?.trim()?.let { |
|
|
|
searchView.query?.toString()?.trim()?.let { |
|
|
|
serchView.setQuery(it, true) |
|
|
|
searchView.setQuery(it, true) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -108,14 +108,14 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initSearchView() { |
|
|
|
private fun initSearchView() { |
|
|
|
ATH.setTint(serchView, primaryTextColor) |
|
|
|
ATH.setTint(searchView, primaryTextColor) |
|
|
|
serchView.onActionViewExpanded() |
|
|
|
searchView.onActionViewExpanded() |
|
|
|
serchView.isSubmitButtonEnabled = true |
|
|
|
searchView.isSubmitButtonEnabled = true |
|
|
|
serchView.queryHint = getString(R.string.search_book_key) |
|
|
|
searchView.queryHint = getString(R.string.search_book_key) |
|
|
|
serchView.clearFocus() |
|
|
|
searchView.clearFocus() |
|
|
|
serchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { |
|
|
|
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { |
|
|
|
override fun onQueryTextSubmit(query: String?): Boolean { |
|
|
|
override fun onQueryTextSubmit(query: String?): Boolean { |
|
|
|
serchView.clearFocus() |
|
|
|
searchView.clearFocus() |
|
|
|
query?.let { |
|
|
|
query?.let { |
|
|
|
viewModel.saveSearchKey(query) |
|
|
|
viewModel.saveSearchKey(query) |
|
|
|
viewModel.search(it) |
|
|
|
viewModel.search(it) |
|
|
@ -130,8 +130,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
serchView.setOnQueryTextFocusChangeListener { _, hasFocus -> |
|
|
|
searchView.setOnQueryTextFocusChangeListener { _, hasFocus -> |
|
|
|
if (!hasFocus && serchView.query.toString().trim().isEmpty()) { |
|
|
|
if (!hasFocus && searchView.query.toString().trim().isEmpty()) { |
|
|
|
finish() |
|
|
|
finish() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
openOrCloseHistory(hasFocus) |
|
|
|
openOrCloseHistory(hasFocus) |
|
|
@ -207,9 +207,9 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
|
|
|
|
|
|
|
|
private fun receiptIntent(intent: Intent? = null) { |
|
|
|
private fun receiptIntent(intent: Intent? = null) { |
|
|
|
intent?.getStringExtra("key")?.let { |
|
|
|
intent?.getStringExtra("key")?.let { |
|
|
|
serchView.setQuery(it, true) |
|
|
|
searchView.setQuery(it, true) |
|
|
|
} ?: let { |
|
|
|
} ?: let { |
|
|
|
serchView.requestFocus() |
|
|
|
searchView.requestFocus() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -227,7 +227,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun openOrCloseHistory(open: Boolean) { |
|
|
|
private fun openOrCloseHistory(open: Boolean) { |
|
|
|
if (open) { |
|
|
|
if (open) { |
|
|
|
upHistory(serchView.query.toString()) |
|
|
|
upHistory(searchView.query.toString()) |
|
|
|
binding.llHistory.visibility = VISIBLE |
|
|
|
binding.llHistory.visibility = VISIBLE |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
binding.llHistory.visibility = GONE |
|
|
|
binding.llHistory.visibility = GONE |
|
|
@ -299,7 +299,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 更新搜索结果 |
|
|
|
* 更新搜索结果 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Synchronized |
|
|
|
|
|
|
|
private fun upSearchItems(items: List<SearchBook>) { |
|
|
|
private fun upSearchItems(items: List<SearchBook>) { |
|
|
|
adapter.setItems(items) |
|
|
|
adapter.setItems(items) |
|
|
|
} |
|
|
|
} |
|
|
@ -351,14 +350,14 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel |
|
|
|
override fun searchHistory(key: String) { |
|
|
|
override fun searchHistory(key: String) { |
|
|
|
launch { |
|
|
|
launch { |
|
|
|
when { |
|
|
|
when { |
|
|
|
serchView.query.toString() == key -> { |
|
|
|
searchView.query.toString() == key -> { |
|
|
|
serchView.setQuery(key, true) |
|
|
|
searchView.setQuery(key, true) |
|
|
|
} |
|
|
|
} |
|
|
|
withContext(IO) { App.db.bookDao.findByName(key).isEmpty() } -> { |
|
|
|
withContext(IO) { App.db.bookDao.findByName(key).isEmpty() } -> { |
|
|
|
serchView.setQuery(key, true) |
|
|
|
searchView.setQuery(key, true) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> { |
|
|
|
else -> { |
|
|
|
serchView.setQuery(key, false) |
|
|
|
searchView.setQuery(key, false) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|