Filtering fixed, but it still doesn't quite work as I wanted it to. e.g. selecting 'pork' and 'vegan' shows no elements, because of course nothing is both vegan and contains pork, but I wanted it to show options that are either or. Should leave it the way it is?

This commit is contained in:
denizk0461
2023-04-20 10:17:04 +02:00
parent b9378901f4
commit 576592f0d0
2 changed files with 13 additions and 4 deletions
@@ -32,6 +32,10 @@ class CanteenFragment : Fragment() {
private lateinit var viewPagerAdapter: CanteenOfferPageAdapter
private val viewModel: CanteenViewModel by viewModels()
private var elements: List<CanteenOffer> = listOf()
private var dateSize = 0
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentCanteenBinding.inflate(inflater, container, false)
return binding.root
@@ -77,12 +81,16 @@ class CanteenFragment : Fragment() {
liveData = viewModel.allOffers
liveData.observe(viewLifecycleOwner) { offers ->
elements = offers
val groupedElements = offers.groupElements().distinct()
dates = groupedElements.map { it.date }.distinct()
createTabLayoutMediator()
// this.groupedElements = groupedElements
this.dateSize = dates.size
viewPagerAdapter.setNewItems(groupedElements, dates.size)
// TODO this must be changed. if an exception is raised, then this will not fire
@@ -113,7 +121,8 @@ class CanteenFragment : Fragment() {
private fun setPreference(pref: DietaryPreferences, newValue: Boolean) {
viewModel.setPreference(pref, newValue)
viewPagerAdapter.refreshView(getPrefRegex())
// viewPagerAdapter.refreshView(getPrefRegex())
viewPagerAdapter.setNewItems(elements.groupElements().distinct(), dateSize)
}
private fun getPreference(pref: DietaryPreferences): Boolean =
@@ -137,6 +146,8 @@ class CanteenFragment : Fragment() {
}
}
// Log.d("eek!6", "preference: $prefsRegex, list: $filteredForPreferences")
// val a = filteredForPreferences.map {
// CanteenOfferGroupElement(
// it.title,
+1 -3
View File
@@ -61,9 +61,7 @@
android:id="@+id/chip_pref_fish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_fish"
app:chipIcon="@drawable/cross"
app:checkedIcon="@drawable/flatware"/>
android:text="@string/pref_fish"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"