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 56a0b15 commit d8b18fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 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 @@ -191,7 +191,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}

override fun onQueryTextChange(newText: String): Boolean {
if (newText.isBlank()) viewModel.stop()
viewModel.stop()
binding.fbStartStop.invisible()
upHistory(newText.trim())
return false
}
Expand Down Expand Up @@ -246,15 +247,19 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}

private fun initOtherView() {
binding.fbStop.backgroundTintList =
binding.fbStartStop.backgroundTintList =
Selector.colorBuild()
.setDefaultColor(accentColor)
.setPressedColor(ColorUtils.darkenColor(accentColor))
.create()
binding.fbStop.setOnClickListener {
isManualStopSearch = true
viewModel.stop()
binding.refreshProgressBar.isAutoLoading = false
binding.fbStartStop.setOnClickListener {
if (viewModel.isSearchLiveData.value == true) {
isManualStopSearch = true
viewModel.stop()
binding.refreshProgressBar.isAutoLoading = false
} else {
viewModel.search("")
}
}
binding.tvClearHistory.setOnClickListener { alertClearHistory() }
}
Expand Down Expand Up @@ -374,7 +379,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private fun startSearch() {
binding.refreshProgressBar.visible()
binding.refreshProgressBar.isAutoLoading = true
binding.fbStop.visible()
binding.fbStartStop.setImageResource(R.drawable.ic_stop_black_24dp)
binding.fbStartStop.visible()
}

/**
Expand All @@ -383,7 +389,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private fun searchFinally() {
binding.refreshProgressBar.isAutoLoading = false
binding.refreshProgressBar.gone()
binding.fbStop.invisible()
if (viewModel.hasMore) {
binding.fbStartStop.setImageResource(R.drawable.ic_play_24dp)
} else {
binding.fbStartStop.invisible()
}
}

override fun observeLiveBus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
}

override fun onSearchFinish(isEmpty: Boolean, hasMore: Boolean) {
this@SearchViewModel.hasMore = hasMore
isSearchLiveData.postValue(false)
searchFinishLiveData.postValue(isEmpty)
this@SearchViewModel.hasMore = hasMore
}

override fun onSearchCancel(exception: Throwable?) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_book_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fb_stop"
android:id="@+id/fb_start_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
Expand Down

0 comments on commit d8b18fa

Please sign in to comment.