搜索优化

This commit is contained in:
Cold Mint 2022-07-13 13:52:56 +08:00
parent 1afe92d237
commit 1fd6b0f666
16 changed files with 24 additions and 6 deletions

View File

@ -730,7 +730,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
initNav() initNav()
observeStartViewModel() observeStartViewModel()
checkAppUpdate() checkAppUpdate()
CommentDialog(this).show() // CommentDialog(this).show()
} else { } else {
startViewModel.initAllData() startViewModel.initAllData()
} }

View File

@ -64,12 +64,14 @@ class SearchActivity : BaseActivity<ActivitySearchBinding>() {
override fun onQueryTextChange(newText: String?): Boolean { override fun onQueryTextChange(newText: String?): Boolean {
if (newText != null && newText.isNotBlank()) { if (newText != null && newText.isNotBlank()) {
viewBinding.searchSuggestionsView.setText(R.string.search_suggestions_loading)
Search.instance.suggestions(newText, Search.instance.suggestions(newText,
object : ApiCallBack<SearchSuggestionsData> { object : ApiCallBack<SearchSuggestionsData> {
override fun onResponse(t: SearchSuggestionsData) { override fun onResponse(t: SearchSuggestionsData) {
val dataList = t.data val dataList = t.data
if (dataList.isNullOrEmpty()) { if (dataList.isNullOrEmpty()) {
viewBinding.recyclerView.isVisible = false viewBinding.recyclerView.isVisible = false
viewBinding.searchSuggestionsView.setText(R.string.search_suggestions_null)
} else { } else {
val adapter = val adapter =
SearchSuggestionsAdapter( SearchSuggestionsAdapter(
@ -89,15 +91,20 @@ class SearchActivity : BaseActivity<ActivitySearchBinding>() {
} }
viewBinding.recyclerView.adapter = adapter viewBinding.recyclerView.adapter = adapter
viewBinding.recyclerView.isVisible = true viewBinding.recyclerView.isVisible = true
val s = String.format(getString(R.string.search_suggestions_number),dataList.size)
viewBinding.searchSuggestionsView.text = s
} }
} }
override fun onFailure(e: Exception) { override fun onFailure(e: Exception) {
viewBinding.recyclerView.isVisible = false viewBinding.recyclerView.isVisible = false
viewBinding.searchSuggestionsView.setText(R.string.search_suggestions_null)
} }
}) })
} else { } else {
viewBinding.searchSuggestionsView.setText(R.string.search_suggestions_null)
viewBinding.recyclerView.isVisible = false viewBinding.recyclerView.isVisible = false
} }
return true return true

View File

@ -152,7 +152,7 @@ class TextStyleMaker private constructor() {
}, },
startIndex, startIndex,
start3Index + start3.length, start3Index + start3.length,
Spannable.SPAN_INCLUSIVE_EXCLUSIVE Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
) )
} else { } else {
break break

View File

@ -35,7 +35,7 @@
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated" style="@style/Widget.Material3.CardView.Outlined"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp"> android:layout_margin="8dp">
@ -55,6 +55,14 @@
android:queryBackground="@null" android:queryBackground="@null"
android:queryHint="@string/search" /> android:queryHint="@string/search" />
<TextView
android:id="@+id/searchSuggestionsView"
android:layout_marginTop="8dp"
style="@style/TextAppearance.Material3.BodySmall"
android:text="@string/search_suggestions_null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -69,7 +77,7 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated" style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp" android:layout_marginHorizontal="8dp"

View File

@ -849,5 +849,8 @@
<string name="search_type_purchase_plan">套餐</string> <string name="search_type_purchase_plan">套餐</string>
<string name="search_type_mod_all">全部</string> <string name="search_type_mod_all">全部</string>
<string name="hotSearch">热门搜索</string> <string name="hotSearch">热门搜索</string>
<string name="search_suggestions_null">无搜索建议。</string>
<string name="search_suggestions_number">共%1$d个搜索建议。</string>
<string name="search_suggestions_loading">获取建议...</string>
</resources> </resources>

View File

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle. # Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the # For customization when using a Version Control System, please read the
# header note. # header note.
#Fri Jul 08 20:18:44 CST 2022 #Wed Jul 13 11:04:51 CST 2022
sdk.dir=D\:\\Document\\AndroidSdk sdk.dir=D\:\\Android_SDK