Button for switching an event's timestamps to show the academic quarter is now properly animated (I think)

This commit is contained in:
denizk0461
2023-04-27 12:47:50 +02:00
parent a6a1309bce
commit 1828a4b02e
4 changed files with 63 additions and 10 deletions
@@ -102,10 +102,34 @@ class StwParser {
* TODO this formatting sucks
*/
var openingHours = ""
doc.getElementsByClass("details-wrapper")[0].getElementsByTag("p").forEach { p ->
openingHours += "${p.text()}\n"
// Iterate through all wrappers that could contain opening hours
doc.getElementsByClass("details-wrapper").forEach {
// Element is not for providing contact details
if (it.getElementsByClass("contact-person-name").size == 0) {
/*
* Retrieve all opening hours.
* TODO this slows down the fetch SIGNIFICANTLY, but why?
*/
it.children().forEach { element ->
if (element.tag().toString() == "p") {
openingHours += element.textWithBreaks().trim() + "\n" // Uni-Mensa is not parsed properly
} else {
element.children().forEach { subElement ->
openingHours += subElement.textWithBreaks() + '\n'
}
}
}
}
// Add an extra line break to separate elements
openingHours += "\n"
}
// Trim off excess line breaks
openingHours = openingHours.trim()
// Save the canteen to persistent storage
repo.insert(
OfferCanteen(
@@ -340,6 +364,20 @@ class StwParser {
else -> "00" // shouldn't occur
}
/**
* Retrieves a text and adds <br> tags with line breaks.
*
* @return formatted element text
*/
private fun Element.textWithBreaks(): String =
this.text()//html()
// .replace("<br>", "\n")
// .replace("&nbsp;", " ")
// .replace("<strong>", "")
// .replace("</strong>", "")
// .replace("<p>", "")
// .replace("</p>", "")
// Image links to all dietary preferences used for checking whether a preference is met
private val imageLinkPrefFair = "https://www.stw-bremen.de/sites/default/files/images/pictograms/at_small.png"
private val imageLinkPrefFish = "https://www.stw-bremen.de/sites/default/files/images/pictograms/fisch.png"