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:
denizk0461
2023-04-28 11:18:05 +02:00
parent ee0934f29b
commit aa5d32e64a
11 changed files with 200 additions and 142 deletions
@@ -21,6 +21,14 @@ interface AppDAO {
@get:Query("SELECT * FROM studipevents ORDER BY timeslotId, id")
val allEvents: LiveData<List<StudIPEvent>>
/**
* 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
*/
@Query("SELECT * FROM studipevents WHERE day = :day ORDER BY timeslotId, id")
fun getEventsForDay(day: Int): LiveData<List<StudIPEvent>>
/**
* Updates a given Stud.IP element.
*
@@ -26,11 +26,11 @@ class AppRepository(app: Application) {
private val blankDietaryPrefs: String = DietaryPreferences.C_FALSE.toString().repeat(10)
/**
* Retrieves all Stud.IP events.
* Retrieves Stud.IP events for a specific day, ordered by their timeslots, then their IDs.
*
* @return all Stud.IP events exposed through a LiveData object
* @return Stud.IP events for a certain day exposed through a LiveData object
*/
val allEvents: LiveData<List<StudIPEvent>> = dao.allEvents
fun getEventsForDay(day: Int): LiveData<List<StudIPEvent>> = dao.getEventsForDay(day)
/**
* Inserts a list of Stud.IP events into the database.
@@ -166,13 +166,6 @@ class AppRepository(app: Application) {
*/
fun nukeOfferDates() { dao.nukeOfferDates() }
/**
* Inserts a date into the database.
*
* @param date object to be saved to the database
*/
fun insert(date: OfferDate) { dao.insert(date) }
/**
* Inserts a list of dates into the database.
*
@@ -180,13 +173,6 @@ class AppRepository(app: Application) {
*/
fun insertDates(dates: List<OfferDate>) { dao.insertDates(dates) }
/**
* Inserts a canteen into the database.
*
* @param canteen object to be saved to the database
*/
fun insert(canteen: OfferCanteen) { dao.insert(canteen) }
/**
* Inserts a list of canteens into the database.
*
@@ -194,13 +180,6 @@ class AppRepository(app: Application) {
*/
fun insertCanteens(canteens: List<OfferCanteen>) { dao.insertCanteens(canteens) }
/**
* Inserts a canteen offer category into the database.
*
* @param category object to be saved to the database
*/
fun insert(category: OfferCategory) { dao.insert(category) }
/**
* Inserts a list of categories into the database.
*
@@ -208,13 +187,6 @@ class AppRepository(app: Application) {
*/
fun insertCategories(categories: List<OfferCategory>) { dao.insertCategories(categories) }
/**
* Inserts a canteen offer item into the database.
*
* @param item object to be saved to the database
*/
fun insert(item: OfferItem) { dao.insert(item) }
/**
* Inserts a list of items into the database.
*