Fully documented all Kotlin files and added TODOs to functions that need to be updated in some way

This commit is contained in:
denizk0461
2023-04-23 11:57:03 +02:00
parent 2534849329
commit fbad84aa09
33 changed files with 1220 additions and 571 deletions
@@ -8,18 +8,57 @@ import com.denizk0461.studip.model.DietaryPrefObject
import com.denizk0461.studip.model.DietaryPreferences
import com.denizk0461.studip.model.OfferDate
/**
* View model for [com.denizk0461.studip.fragment.CanteenFragment]
*
* @param app reference to the app
*/
class CanteenViewModel(app: Application) : TemplateViewModel(app) {
// Instantiate a parser, should the user want to refresh the canteen offers
private val parser = StwParser()
/**
* Retrieves all Stud.IP events.
*
* @return all Stud.IP events exposed through a LiveData object
*/
val allOffers: LiveData<List<CanteenOffer>> = repo.allOffers
/**
* Retrieve the user's dietary preferences.
*
* @return dietary preferences
*/
fun getDietaryPrefs(): DietaryPrefObject = repo.getDietaryPrefsAsObj()
/**
* Retrieves all canteen offer date objects.
*
* @return a list of instances of canteen offer dates
*/
fun getDates(): List<OfferDate> = returnBlocking { repo.getDates() }
fun fetchOffers(onRefreshUpdate: (status: Int) -> Unit, onFinish: () -> Unit) { doAsync { parser.parse(onRefreshUpdate, onFinish) }}
// Fetch the canteen offers asynchronously. Updates will be provided through a LiveData object.
fun fetchOffers(onRefreshUpdate: (status: Int) -> Unit, onFinish: () -> Unit) {
doAsync { parser.parse(onRefreshUpdate, onFinish) }
}
fun setPreference(pref: DietaryPreferences, newValue: Boolean) { repo.setPreference(pref, newValue) }
/**
* Updates a given dietary preference to a new value.
*
* @param pref preference to be updated
* @param newValue value to set the preference to
*/
fun setPreference(pref: DietaryPreferences, newValue: Boolean) {
repo.setPreference(pref, newValue)
}
/**
* Retrieves a single user-specified dietary preference.
*
* @param pref the dietary preference that should be retrieved
* @return whether the preference needs to be met
*/
fun getPreference(pref: DietaryPreferences): Boolean = repo.getPreference(pref)
}