Archived
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:
@@ -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() }}
|
||||
|
||||
Reference in New Issue
Block a user