Archived
Updated EventPageFragment.kt to have access to its own ViewModel and, by extension, its own reference to the database, which forgoes the need to transport data from EventFragment.kt through StudIPEventPageAdapter.kt to EventPageFragment.kt and allows for filtering for a specific day's items through the database rather than needing to iterate through the list via an extension function manually. Also implemented DiffUtil to perform individual updates rather than calling notifyDataSetChanged() every time a single item has been changed.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.denizk0461.studip.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.denizk0461.studip.model.StudIPEvent
|
||||
|
||||
/**
|
||||
* View model for [com.denizk0461.studip.fragment.EventPageFragment]
|
||||
*
|
||||
* @param app reference to the app
|
||||
*/
|
||||
class EventPageViewModel(app: Application) : AppViewModel(app) {
|
||||
|
||||
/**
|
||||
* Retrieves Stud.IP events for a specific day, ordered by their timeslots, then their IDs.
|
||||
*
|
||||
* @return Stud.IP events for a certain day exposed through a LiveData object
|
||||
*/
|
||||
fun getEventsForDay(day: Int): LiveData<List<StudIPEvent>> = repo.getEventsForDay(day)
|
||||
|
||||
/**
|
||||
* Updates a schedule element.
|
||||
*
|
||||
* @param event the event to update
|
||||
*/
|
||||
fun update(event: StudIPEvent) { doAsync { repo.update(event) } }
|
||||
|
||||
/**
|
||||
* Deletes a schedule element.
|
||||
*
|
||||
* @param event the event to delete
|
||||
*/
|
||||
fun delete(event: StudIPEvent) { doAsync { repo.delete(event) } }
|
||||
}
|
||||
Reference in New Issue
Block a user