diff --git a/app/src/main/java/com/denizk0461/studip/data/StwParser.kt b/app/src/main/java/com/denizk0461/studip/data/StwParser.kt
index fd8a5f9..5d4bb5d 100644
--- a/app/src/main/java/com/denizk0461/studip/data/StwParser.kt
+++ b/app/src/main/java/com/denizk0461/studip/data/StwParser.kt
@@ -209,24 +209,18 @@ class StwParser {
.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:
* 4, a1, a4, c, g
* 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)
- var indexSupClose = 0
+ var indexSupClose: Int
+
+ // This list collects the individual items without the tags and commas
+ val allergens = mutableListOf()
/*
* The Studierendenwerk's website lists allergens, but they are invisible, rendering them
@@ -234,29 +228,33 @@ class StwParser {
* TODO implement allergen functionality
*/
while (text.contains("")) {
- // Add a delimiter if allergens have already been added
- if (hasAllergens) allergens += ","
// Set indices for the tags
indexSupOpen = text.indexOf("")
indexSupClose = text.indexOf("")
// 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
text = text.substring(0 until indexSupOpen) +
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(","))
}
/**
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index c3d5e2c..49c7d03 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -50,12 +50,12 @@
tierisches Lab
- Weizen
- Roggen
- Gerste
- Hafer
- Dinkel
- Kamut
+ Gluten (Weizen)
+ Gluten (Roggen)
+ Gluten (Gerste)
+ Gluten (Hafer)
+ Gluten (Dinkel)
+ Gluten (Kamut)
Krebstiere
Eier
Fisch
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1cab1af..1f1783d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -50,12 +50,12 @@
animal rennet
- wheat
- rye
- barley
- oats
- spelt
- kamut
+ gluten (wheat)
+ gluten (rye)
+ gluten (barley)
+ gluten (oats)
+ gluten (spelt)
+ gluten (kamut)
crustaceans
eggs
fish