2023-04-16 18:19:06 +02:00
|
|
|
package com.denizk0461.studip.viewmodel
|
|
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
|
import androidx.lifecycle.LiveData
|
|
|
|
|
import com.denizk0461.studip.data.StwParser
|
|
|
|
|
import com.denizk0461.studip.model.CanteenOffer
|
2023-04-18 15:39:49 +02:00
|
|
|
import com.denizk0461.studip.model.DietaryPrefObject
|
2023-04-18 10:25:45 +02:00
|
|
|
import com.denizk0461.studip.model.DietaryPreferences
|
2023-04-20 21:35:09 +02:00
|
|
|
import com.denizk0461.studip.model.OfferDate
|
2023-04-16 18:19:06 +02:00
|
|
|
|
|
|
|
|
class CanteenViewModel(app: Application) : TemplateViewModel(app) {
|
|
|
|
|
|
|
|
|
|
private val parser = StwParser()
|
|
|
|
|
|
|
|
|
|
val allOffers: LiveData<List<CanteenOffer>> = repo.allOffers
|
|
|
|
|
|
2023-04-18 15:39:49 +02:00
|
|
|
fun getDietaryPrefs(): DietaryPrefObject = repo.getDietaryPrefsAsObj()
|
|
|
|
|
|
2023-04-20 21:35:09 +02:00
|
|
|
fun getDates(): List<OfferDate> = returnBlocking { repo.getDates() }
|
|
|
|
|
|
2023-04-18 10:25:45 +02:00
|
|
|
fun fetchOffers(onRefreshUpdate: (status: Int) -> Unit, onFinish: () -> Unit) { doAsync { parser.parse(onRefreshUpdate, onFinish) }}
|
|
|
|
|
|
|
|
|
|
fun setPreference(pref: DietaryPreferences, newValue: Boolean) { repo.setPreference(pref, newValue) }
|
|
|
|
|
fun getPreference(pref: DietaryPreferences): Boolean = repo.getPreference(pref)
|
2023-04-16 18:19:06 +02:00
|
|
|
}
|