refactor (search filter) : syncing main tytype chips and bottom dialog tytype chips (#811)

This commit is contained in:
coxju 2023-12-15 19:50:37 +05:30 committed by GitHub
parent fe30a85a1c
commit 91dc83e6a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -256,12 +256,12 @@ class SearchFragment : Fragment() {
builder.behavior.state = BottomSheetBehavior.STATE_EXPANDED
val binding: HomeSelectMainpageBinding = HomeSelectMainpageBinding.inflate(
val selectMainpageBinding: HomeSelectMainpageBinding = HomeSelectMainpageBinding.inflate(
builder.layoutInflater,
null,
false
)
builder.setContentView(binding.root)
builder.setContentView(selectMainpageBinding.root)
builder.show()
builder.let { dialog ->
val isMultiLang = ctx.getApiProviderLangSettings().let { set ->
@ -315,16 +315,23 @@ class SearchFragment : Fragment() {
arrayAdapter.notifyDataSetChanged()
}
val selectedSearchTypes = DataStoreHelper.searchPreferenceTags
bindChips(
binding.tvtypesChipsScroll.tvtypesChips,
selectMainpageBinding.tvtypesChipsScroll.tvtypesChips,
selectedSearchTypes,
TvType.values().toList()
validAPIs.flatMap { api -> api.supportedTypes }.distinct()
) { list ->
updateList(list)
// refresh selected chips in main chips
if (selectedSearchTypes.toSet() != list.toSet()) {
selectedSearchTypes.clear()
selectedSearchTypes.addAll(list)
updateChips(binding?.tvtypesChipsScroll?.tvtypesChips, selectedSearchTypes)
}
}
cancelBtt?.setOnClickListener {
dialog.dismissSafe()
}
@ -343,6 +350,9 @@ class SearchFragment : Fragment() {
dialog.setOnDismissListener {
DataStoreHelper.searchPreferenceProviders = currentSelectedApis.toList()
selectedApis = currentSelectedApis
// run search when dialog is close
search(binding?.mainSearch?.query?.toString())
}
updateList(selectedSearchTypes.toList())
}