Archived
Fixed allergen duplicates being stored in the database and shown to the user multiple times
This commit is contained in:
@@ -209,24 +209,18 @@ class StwParser {
|
|||||||
.replace(">", ">")
|
.replace(">", ">")
|
||||||
.replace("<", "<")
|
.replace("<", "<")
|
||||||
|
|
||||||
// All allergens will be collected here
|
|
||||||
var allergens: String = ""
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Used to determine whether any allergens have already been found in the item. Should this
|
|
||||||
* be the case, a delimiter is added.
|
|
||||||
*/
|
|
||||||
var hasAllergens: Boolean = false
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allergens are stored in super tags. Example:
|
* Allergens are stored in super tags. Example:
|
||||||
* <sup>4, a1, a4, c, g</sup>
|
* <sup>4, a1, a4, c, g</sup>
|
||||||
* This is the start index of the opening tag (inclusive).
|
* This is the start index of the opening tag (inclusive).
|
||||||
*/
|
*/
|
||||||
var indexSupOpen = 0
|
var indexSupOpen: Int
|
||||||
|
|
||||||
// This is the end index of the closing tag (exclusive)
|
// This is the end index of the closing tag (exclusive)
|
||||||
var indexSupClose = 0
|
var indexSupClose: Int
|
||||||
|
|
||||||
|
// This list collects the individual items without the <sup> tags and commas
|
||||||
|
val allergens = mutableListOf<String>()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The Studierendenwerk's website lists allergens, but they are invisible, rendering them
|
* The Studierendenwerk's website lists allergens, but they are invisible, rendering them
|
||||||
@@ -234,29 +228,33 @@ class StwParser {
|
|||||||
* TODO implement allergen functionality
|
* TODO implement allergen functionality
|
||||||
*/
|
*/
|
||||||
while (text.contains("<sup>")) {
|
while (text.contains("<sup>")) {
|
||||||
// Add a delimiter if allergens have already been added
|
|
||||||
if (hasAllergens) allergens += ","
|
|
||||||
|
|
||||||
// Set indices for the <sup> tags
|
// Set indices for the <sup> tags
|
||||||
indexSupOpen = text.indexOf("<sup>")
|
indexSupOpen = text.indexOf("<sup>")
|
||||||
indexSupClose = text.indexOf("</sup>")
|
indexSupClose = text.indexOf("</sup>")
|
||||||
|
|
||||||
// Add allergens
|
// Add allergens
|
||||||
allergens += text.substring(indexSupOpen + 5 until indexSupClose)
|
allergens.addAll(
|
||||||
|
text.substring(indexSupOpen + 5 until indexSupClose)
|
||||||
|
// Remove redundant whitespace
|
||||||
|
.replace(" ", "")
|
||||||
|
/*
|
||||||
|
* Split individual strings with multiple allergens so that duplicates can be
|
||||||
|
* filtered out later.
|
||||||
|
*/
|
||||||
|
.split(",")
|
||||||
|
)
|
||||||
|
|
||||||
// Remove allergens from the title of the offer
|
// Remove allergens from the title of the offer
|
||||||
text = text.substring(0 until indexSupOpen) +
|
text = text.substring(0 until indexSupOpen) +
|
||||||
text.substring((indexSupClose + 6) until text.length)
|
text.substring((indexSupClose + 6) until text.length)
|
||||||
|
|
||||||
/*
|
|
||||||
* Make sure that the delimiter will be added if more than one instance of allergens is
|
|
||||||
* found.
|
|
||||||
*/
|
|
||||||
hasAllergens = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the stripped and updated HTML string
|
/*
|
||||||
return Pair(text, allergens)
|
* Return the stripped and updated HTML string and join the allergen list to a cohesive
|
||||||
|
* string without duplication.
|
||||||
|
*/
|
||||||
|
return Pair(text, allergens.distinct().joinToString(","))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,12 +50,12 @@
|
|||||||
<string name="allergen_rennet">tierisches Lab</string>
|
<string name="allergen_rennet">tierisches Lab</string>
|
||||||
|
|
||||||
<!-- Allergene -->
|
<!-- Allergene -->
|
||||||
<string name="allergen_wheat">Weizen</string>
|
<string name="allergen_wheat">Gluten (Weizen)</string>
|
||||||
<string name="allergen_rye">Roggen</string>
|
<string name="allergen_rye">Gluten (Roggen)</string>
|
||||||
<string name="allergen_barley">Gerste</string>
|
<string name="allergen_barley">Gluten (Gerste)</string>
|
||||||
<string name="allergen_oat">Hafer</string>
|
<string name="allergen_oat">Gluten (Hafer)</string>
|
||||||
<string name="allergen_spelt">Dinkel</string>
|
<string name="allergen_spelt">Gluten (Dinkel)</string>
|
||||||
<string name="allergen_kamut">Kamut</string>
|
<string name="allergen_kamut">Gluten (Kamut)</string>
|
||||||
<string name="allergen_crustaceans">Krebstiere</string>
|
<string name="allergen_crustaceans">Krebstiere</string>
|
||||||
<string name="allergen_eggs">Eier</string>
|
<string name="allergen_eggs">Eier</string>
|
||||||
<string name="allergen_fish">Fisch</string>
|
<string name="allergen_fish">Fisch</string>
|
||||||
|
|||||||
@@ -50,12 +50,12 @@
|
|||||||
<string name="allergen_rennet">animal rennet</string>
|
<string name="allergen_rennet">animal rennet</string>
|
||||||
|
|
||||||
<!-- allergens -->
|
<!-- allergens -->
|
||||||
<string name="allergen_wheat">wheat</string>
|
<string name="allergen_wheat">gluten (wheat)</string>
|
||||||
<string name="allergen_rye">rye</string>
|
<string name="allergen_rye">gluten (rye)</string>
|
||||||
<string name="allergen_barley">barley</string>
|
<string name="allergen_barley">gluten (barley)</string>
|
||||||
<string name="allergen_oat">oats</string>
|
<string name="allergen_oat">gluten (oats)</string>
|
||||||
<string name="allergen_spelt">spelt</string>
|
<string name="allergen_spelt">gluten (spelt)</string>
|
||||||
<string name="allergen_kamut">kamut</string>
|
<string name="allergen_kamut">gluten (kamut)</string>
|
||||||
<string name="allergen_crustaceans">crustaceans</string>
|
<string name="allergen_crustaceans">crustaceans</string>
|
||||||
<string name="allergen_eggs">eggs</string>
|
<string name="allergen_eggs">eggs</string>
|
||||||
<string name="allergen_fish">fish</string>
|
<string name="allergen_fish">fish</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user