全文搜索添加停止按钮

pull/2076/head 3.22.071618
kunfei 2 years ago
parent 5b87f2f94a
commit f924f74ee8
  1. 18
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  2. 11
      app/src/main/res/layout/activity_search_content.xml

@ -20,10 +20,7 @@ import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.applyTint
import io.legado.app.utils.observeEvent
import io.legado.app.utils.postEvent
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
@ -80,9 +77,8 @@ class SearchContentActivity :
searchView.clearFocus()
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
if (viewModel.lastQuery != query) {
startContentSearch(query)
}
startContentSearch(query)
searchView.clearFocus()
return false
}
@ -107,6 +103,9 @@ class SearchContentActivity :
mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0)
}
}
binding.fbStop.setOnClickListener {
searchJob?.cancel()
}
}
@SuppressLint("SetTextI18n")
@ -158,6 +157,7 @@ class SearchContentActivity :
}.forEach { bookChapter ->
ensureActive()
binding.refreshProgressBar.isAutoLoading = true
binding.fbStop.visible()
val searchResults = withContext(IO) {
if (isLocalBook || viewModel.cacheChapterNames.contains(bookChapter.getFileName())) {
viewModel.searchChapter(this, query, bookChapter)
@ -181,8 +181,12 @@ class SearchContentActivity :
adapter.addItem(noSearchResult)
}
}.onFailure {
binding.fbStop.invisible()
binding.refreshProgressBar.isAutoLoading = false
AppLog.put("全文搜索出错\n${it.localizedMessage}", it)
}.onSuccess {
binding.fbStop.invisible()
binding.refreshProgressBar.isAutoLoading = false
}
}
}

@ -77,5 +77,16 @@
tools:ignore="UnusedAttribute" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fb_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@drawable/ic_stop_black_24dp"
android:visibility="invisible"
android:contentDescription="@string/stop"
app:fabSize="mini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save