This commit is contained in:
Horis
2025-01-27 16:10:58 +08:00
parent 56a0b15a43
commit d8b18fadc3
3 changed files with 20 additions and 10 deletions
@@ -191,7 +191,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
override fun onQueryTextChange(newText: String): Boolean { override fun onQueryTextChange(newText: String): Boolean {
if (newText.isBlank()) viewModel.stop() viewModel.stop()
binding.fbStartStop.invisible()
upHistory(newText.trim()) upHistory(newText.trim())
return false return false
} }
@@ -246,15 +247,19 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
private fun initOtherView() { private fun initOtherView() {
binding.fbStop.backgroundTintList = binding.fbStartStop.backgroundTintList =
Selector.colorBuild() Selector.colorBuild()
.setDefaultColor(accentColor) .setDefaultColor(accentColor)
.setPressedColor(ColorUtils.darkenColor(accentColor)) .setPressedColor(ColorUtils.darkenColor(accentColor))
.create() .create()
binding.fbStop.setOnClickListener { binding.fbStartStop.setOnClickListener {
isManualStopSearch = true if (viewModel.isSearchLiveData.value == true) {
viewModel.stop() isManualStopSearch = true
binding.refreshProgressBar.isAutoLoading = false viewModel.stop()
binding.refreshProgressBar.isAutoLoading = false
} else {
viewModel.search("")
}
} }
binding.tvClearHistory.setOnClickListener { alertClearHistory() } binding.tvClearHistory.setOnClickListener { alertClearHistory() }
} }
@@ -374,7 +379,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private fun startSearch() { private fun startSearch() {
binding.refreshProgressBar.visible() binding.refreshProgressBar.visible()
binding.refreshProgressBar.isAutoLoading = true binding.refreshProgressBar.isAutoLoading = true
binding.fbStop.visible() binding.fbStartStop.setImageResource(R.drawable.ic_stop_black_24dp)
binding.fbStartStop.visible()
} }
/** /**
@@ -383,7 +389,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private fun searchFinally() { private fun searchFinally() {
binding.refreshProgressBar.isAutoLoading = false binding.refreshProgressBar.isAutoLoading = false
binding.refreshProgressBar.gone() binding.refreshProgressBar.gone()
binding.fbStop.invisible() if (viewModel.hasMore) {
binding.fbStartStop.setImageResource(R.drawable.ic_play_24dp)
} else {
binding.fbStartStop.invisible()
}
} }
override fun observeLiveBus() { override fun observeLiveBus() {
@@ -47,9 +47,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
} }
override fun onSearchFinish(isEmpty: Boolean, hasMore: Boolean) { override fun onSearchFinish(isEmpty: Boolean, hasMore: Boolean) {
this@SearchViewModel.hasMore = hasMore
isSearchLiveData.postValue(false) isSearchLiveData.postValue(false)
searchFinishLiveData.postValue(isEmpty) searchFinishLiveData.postValue(isEmpty)
this@SearchViewModel.hasMore = hasMore
} }
override fun onSearchCancel(exception: Throwable?) { override fun onSearchCancel(exception: Throwable?) {
@@ -94,7 +94,7 @@
</LinearLayout> </LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fb_stop" android:id="@+id/fb_start_stop"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_margin="16dp"