Improve fliters & chip styles

-- Removed filter apply & close, filter is saved on dismiss
This commit is contained in:
Rahul Patel
2024-07-15 01:16:07 +05:30
committed by Aayush Gupta
parent ec9e237a4d
commit 388e2d9a35
12 changed files with 145 additions and 246 deletions

View File

@@ -247,22 +247,22 @@ class SearchResultsFragment : BaseFragment<FragmentSearchResultBinding>(),
viewModel.observeSearchResults(query)
}
private fun filter(appList: MutableList<App>): List<App> {
val tempList:MutableList<App> = mutableListOf()
tempList.addAll(appList)
private fun filter(appList: List<App>): List<App> {
val filter = viewModel.filterProvider.getSavedFilter()
return tempList
return appList
.asSequence()
.filter { it.displayName.isNotEmpty() } // Some of the apps may not have metadata
.filter { if (!filter.paidApps) it.isFree else true }
.filter { if (!filter.appsWithAds) !it.containsAds else true }
.filter { if (!filter.gsfDependentApps) it.dependencies.dependentPackages.isEmpty() else true }
.filter { if (filter.rating > 0) it.rating.average >= filter.rating else true }
.filter { if (filter.downloads > 0) it.installs >= filter.downloads else true }
.filter { app ->
app.displayName.isNotEmpty() &&
(filter.paidApps || app.isFree) &&
(filter.appsWithAds || !app.containsAds) &&
(filter.gsfDependentApps || app.dependencies.dependentPackages.isEmpty()) &&
(filter.rating <= 0 || app.rating.average >= filter.rating) &&
(filter.downloads <= 0 || app.installs >= filter.downloads)
}
.toList()
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
if (key == PREFERENCE_FILTER) query?.let { queryViewModel(it) }
}

View File

@@ -19,6 +19,7 @@
package com.aurora.store.view.ui.sheets
import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import com.aurora.store.R
@@ -43,18 +44,11 @@ class FilterSheet : BaseDialogSheet<SheetFilterBinding>() {
attachSingleChips()
attachMultipleChips()
attachActions()
}
private fun attachActions() {
binding.btnPositive.setOnClickListener {
filterProvider.saveFilter(filter)
dismissAllowingStateLoss()
}
binding.btnNegative.setOnClickListener {
dismissAllowingStateLoss()
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
filterProvider.saveFilter(filter)
}
private fun attachSingleChips() {
@@ -88,29 +82,25 @@ class FilterSheet : BaseDialogSheet<SheetFilterBinding>() {
val downloadValues = resources.getStringArray(R.array.filterDownloadsValues)
val ratingLabels = resources.getStringArray(R.array.filterRatingLabels)
val ratingValues = resources.getStringArray(R.array.filterRatingValues)
var i = 0
for (downloadLabel in downloadLabels) {
downloadLabels.forEachIndexed { index, value ->
val chip = Chip(requireContext())
chip.id = i
chip.text = downloadLabel
chip.isChecked = filter.downloads == downloadValues[i].toInt()
chip.id = index
chip.text = value
chip.isChecked = filter.downloads == downloadValues[index].toInt()
binding.downloadChips.addView(chip)
i++
}
binding.downloadChips.setOnCheckedStateChangeListener { _, checkedIds ->
filter = filter.copy(downloads = downloadValues[checkedIds[0]].toInt())
}
i = 0
for (ratingLabel in ratingLabels) {
val chip = Chip(requireContext())
chip.id = i
chip.text = ratingLabel
chip.isChecked = filter.rating == ratingValues[i].toFloat()
ratingLabels.forEachIndexed { index, value ->
val chip = Chip(requireActivity())
chip.id = index
chip.text = value
chip.isChecked = filter.rating == ratingValues[index].toFloat()
binding.ratingChips.addView(chip)
i++
}
binding.ratingChips.setOnCheckedStateChangeListener { _, checkedIds ->