Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jan 27, 2025
1 parent 13cd03b commit 9ef1240
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private var historyFlowJob: Job? = null
private var booksFlowJob: Job? = null
private var precisionSearchMenuItem: MenuItem? = null
private var isManualStopSearch = false

override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.llInputHelp.setBackgroundColor(backgroundColor)
Expand Down Expand Up @@ -180,6 +181,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override fun onQueryTextSubmit(query: String): Boolean {
searchView.clearFocus()
query.trim().let { searchKey ->
isManualStopSearch = false
viewModel.saveSearchKey(searchKey)
viewModel.searchKey = ""
viewModel.search(searchKey)
Expand Down Expand Up @@ -234,6 +236,14 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}
}
})
binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (!recyclerView.canScrollVertically(1)) {
scrollToBottom()
}
}
})
}

private fun initOtherView() {
Expand All @@ -244,6 +254,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
.create()
binding.fbStartStop.setOnClickListener {
if (viewModel.isSearchLiveData.value == true) {
isManualStopSearch = true
viewModel.stop()
binding.refreshProgressBar.isAutoLoading = false
} else {
Expand Down Expand Up @@ -295,6 +306,21 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}
}

/**
* 滚动到底部事件
*/
private fun scrollToBottom() {
if (isManualStopSearch) {
return
}
if (viewModel.isSearchLiveData.value == false
&& viewModel.searchKey.isNotEmpty()
&& viewModel.hasMore
) {
viewModel.search("")
}
}

/**
* 打开关闭输入帮助
*/
Expand Down

0 comments on commit 9ef1240

Please sign in to comment.