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 10:25:45 +02:00
|
|
|
import com.denizk0461.studip.model.DietaryPreferences
|
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 10:25:45 +02:00
|
|
|
fun getOffersByPreference(): LiveData<List<CanteenOffer>> =
|
|
|
|
|
repo.getOffersByPreference()
|
|
|
|
|
|
2023-04-17 14:19:06 +02:00
|
|
|
// fun insertOffers(offers: List<CanteenOffer>) { doAsync { repo.insertOffers(offers) }}
|
2023-04-16 18:19:06 +02:00
|
|
|
fun nukeOffers() { doAsync { repo.nukeOffers() }}
|
|
|
|
|
|
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
|
|
|
}
|