Archived
Canteen adapter now tells the user when no offers are available for a given day
This commit is contained in:
@@ -4,6 +4,7 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.denizk0461.studip.R
|
||||
import com.denizk0461.studip.databinding.ItemCanteenBinding
|
||||
import com.denizk0461.studip.databinding.ItemCanteenLineBinding
|
||||
import com.denizk0461.studip.databinding.ItemIconBinding
|
||||
@@ -44,11 +45,44 @@ class CanteenOfferItemAdapter(
|
||||
// Returns the amount of offers for a given canteen and day
|
||||
override fun getItemCount(): Int = offers.size
|
||||
|
||||
// TODO inflate a view saying "no events" if none are available for a given day
|
||||
override fun onBindViewHolder(holder: OfferViewHolder, position: Int) {
|
||||
// Retrieve item for current position
|
||||
val currentItem = offers[position]
|
||||
|
||||
// If an item has been added to mark that there are no offers available, tell the user
|
||||
if (currentItem.category == "NO\$ITEMS") {
|
||||
|
||||
// Set the text to "No offers" (localised)
|
||||
holder.binding.textCategory.text =
|
||||
holder.binding.root.context.getString(R.string.canteen_no_offer_header)
|
||||
|
||||
// Inflate a single line without binding it to the line container
|
||||
val line = ItemCanteenLineBinding.inflate(
|
||||
LayoutInflater.from(holder.binding.root.context),
|
||||
)
|
||||
|
||||
// Set content to tell the user that no offers are available (localised)
|
||||
line.textContent.text =
|
||||
holder.binding.root.context.getString(R.string.canteen_no_offer_desc)
|
||||
|
||||
// Inflate a new icon holder
|
||||
val img = ItemIconBinding.inflate(LayoutInflater.from(holder.binding.root.context))
|
||||
|
||||
// Set a cross icon
|
||||
img.imageView.setImageDrawable(
|
||||
AppCompatResources.getDrawable(
|
||||
holder.binding.root.context,
|
||||
DietaryPreferences.indexToDrawable[11]!!,
|
||||
)
|
||||
)
|
||||
|
||||
// Bind the new icon to the line view
|
||||
line.imageViewContainer.addView(img.root)
|
||||
|
||||
// Bind the new line to the line container
|
||||
holder.binding.lineContainer.addView(line.root)
|
||||
|
||||
} else { // Proceed normally if items are available
|
||||
// Set category text / header of the item
|
||||
holder.binding.textCategory.text = currentItem.category
|
||||
|
||||
@@ -108,6 +142,7 @@ class CanteenOfferItemAdapter(
|
||||
holder.binding.lineContainer.addView(line.root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a star to mark allergens present in an offer. Allergens will be displayed as a star '*'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.denizk0461.studip.data
|
||||
|
||||
import android.util.Log
|
||||
import com.denizk0461.studip.db.AppRepository
|
||||
import com.denizk0461.studip.model.*
|
||||
import org.jsoup.Jsoup
|
||||
@@ -24,6 +25,9 @@ class StwParser {
|
||||
// Unique primary key value for the item elements
|
||||
private var itemId = 0
|
||||
|
||||
// Determine whether there are offers for a given date
|
||||
private var dateHasItems = false
|
||||
|
||||
/**
|
||||
* Parses through a list of canteen plans and saves them to persistent storage.
|
||||
*
|
||||
@@ -137,11 +141,18 @@ class StwParser {
|
||||
*/
|
||||
repo.insert(OfferDate(dateId, date))
|
||||
|
||||
dateHasItems = false
|
||||
|
||||
// Iterate through all categories offered on a given day
|
||||
dayPlan.getElementsByClass("food-category").forEach { category ->
|
||||
|
||||
dateHasItems = true
|
||||
|
||||
// Retrieve the category text
|
||||
val categoryTitle = category.getElementsByClass("category-name")[0].text()
|
||||
|
||||
Log.d("AAA?", "$date on $categoryTitle")
|
||||
|
||||
// Save the category to persistent storage
|
||||
repo.insert(OfferCategory(categoryId, dateId, canteenId, categoryTitle))
|
||||
|
||||
@@ -184,16 +195,38 @@ class StwParser {
|
||||
)
|
||||
)
|
||||
|
||||
// Increment the item ID to avoid overriding
|
||||
// Increment the item ID to avoid conflict
|
||||
itemId += 1
|
||||
}
|
||||
// Increment the category ID to avoid overriding
|
||||
// Increment the category ID to avoid conflict
|
||||
categoryId += 1
|
||||
}
|
||||
// Increment the date ID to avoid overriding
|
||||
|
||||
/*
|
||||
* If no items were found for the day, insert items that will tell the user that nothing
|
||||
* is available. Text will then be handled in the adapter class.
|
||||
*/
|
||||
if (!dateHasItems) {
|
||||
repo.insert(OfferCategory(categoryId, dateId, canteenId, "NO\$ITEMS"))
|
||||
repo.insert(
|
||||
OfferItem(
|
||||
itemId,
|
||||
categoryId,
|
||||
title = "NO\$ITEMS",
|
||||
price = "",
|
||||
dietaryPreferences = "..........",
|
||||
allergens = "",
|
||||
)
|
||||
)
|
||||
// Increment the IDs to avoid conflict
|
||||
categoryId += 1
|
||||
itemId += 1
|
||||
}
|
||||
|
||||
// Increment the date ID to avoid conflict
|
||||
dateId += 1
|
||||
}
|
||||
// Increment the canteen ID to avoid overriding
|
||||
// Increment the canteen ID to avoid conflict
|
||||
canteenId += 1
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ enum class DietaryPreferences(val value: String) {
|
||||
8 to R.drawable.carrot,
|
||||
9 to R.drawable.deer,
|
||||
10 to R.drawable.circle,
|
||||
11 to R.drawable.cross,
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
<string name="sheet_schedule_update_lecturers_hint">Dozierende(r)</string>
|
||||
<string name="sheet_schedule_update_room_hint">Raum</string>
|
||||
|
||||
<string name="canteen_no_offer_header">Kein Angebot</string>
|
||||
<string name="canteen_no_offer_desc">Für diesen Tag sind keine Angebote vorhanden</string>
|
||||
|
||||
<string name="sheet_licences_header">Lizenzen</string>
|
||||
|
||||
<string name="title_schedule">Dein Stundenplan</string>
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
<string name="sheet_schedule_update_room_hint">Room</string>
|
||||
<string name="sheet_schedule_update_timeslot_middle" translatable="false">–</string>
|
||||
|
||||
<string name="canteen_no_offer_header">No offers</string>
|
||||
<string name="canteen_no_offer_desc">There are no offers available for this day</string>
|
||||
|
||||
<string name="sheet_licences_header">Licences</string>
|
||||
<string name="sheet_licences_content" translatable="false">Android developer resources provided by Google.\nhttps://developer.android.com/\n\nCrash reporting provided by Google.\nhttps://firebase.google.com/products/crashlytics/\n\nDesign guidelines, icons, and colour palette provided by Google.\nhttps://m3.material.io/\n\nAdditional icons provided by Flaticon.\nhttps://www.flaticon.com/\n\nWeb scraping functionality provided by Jonathan Hedley.\nhttps://jhy.io/ | https://jsoup.org/</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user