Made some improvements to the dietary preference handling, but CanteenOfferPageAdapter.kt still needs some work for the filtering to work properly; it should only filter out elements if they meet NO preferences!

This commit is contained in:
denizk0461
2023-04-18 15:39:49 +02:00
parent c385da4287
commit 4d9ad39578
12 changed files with 252 additions and 113 deletions
@@ -2,18 +2,32 @@ package com.denizk0461.studip.viewmodel
import android.app.Application
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.denizk0461.studip.data.StwParser
import com.denizk0461.studip.model.CanteenOffer
import com.denizk0461.studip.model.DietaryPrefObject
import com.denizk0461.studip.model.DietaryPreferences
class CanteenViewModel(app: Application) : TemplateViewModel(app) {
private val parser = StwParser()
// bad pattern i know
private val mutableOffers = MutableLiveData<List<CanteenOffer>>()
val allOffers: LiveData<List<CanteenOffer>> = repo.allOffers
fun getOffersByPreference(): LiveData<List<CanteenOffer>> =
repo.getOffersByPreference()
fun getOffersByPreference(): LiveData<List<CanteenOffer>> {
val of = repo.getOffersByPreference()
mutableOffers.postValue(of.value)
return of
}
fun getDietaryPrefs(): DietaryPrefObject = repo.getDietaryPrefsAsObj()
fun forceRefresh() {
mutableOffers.value = mutableOffers.value
}
// fun insertOffers(offers: List<CanteenOffer>) { doAsync { repo.insertOffers(offers) }}
fun nukeOffers() { doAsync { repo.nukeOffers() }}