Archived
Adjusted layout of AllergenSheet.kt to display allergens and additives separately
This commit is contained in:
@@ -85,7 +85,20 @@ class AllergenSheet : AppSheet(R.layout.sheet_allergen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allergen and additive notice
|
// Allergen and additive notice
|
||||||
textContent.text = offer.allergens.compileAllergenString()
|
// textContent.text = offer.allergens.compileAllergenString()
|
||||||
|
val (a, b) = offer.allergens.compileStrings()
|
||||||
|
|
||||||
|
if (a.isBlank() && b.isBlank()) {
|
||||||
|
textAllergensTitle.text = getString(R.string.allergens_none)
|
||||||
|
textAllergensContent.visibility = View.GONE
|
||||||
|
textAdditivesTitle.visibility = View.GONE
|
||||||
|
textAdditivesContent.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
textAllergensTitle.text = getString(R.string.allergens_allergens_title)
|
||||||
|
textAllergensContent.text = getString(R.string.allergens_content_template, a)
|
||||||
|
textAdditivesTitle.text = getString(R.string.allergens_additives_title)
|
||||||
|
textAdditivesContent.text = getString(R.string.allergens_content_template, b)
|
||||||
|
}
|
||||||
|
|
||||||
// Show a price, if one is available
|
// Show a price, if one is available
|
||||||
if (offer.price.isBlank()) {
|
if (offer.price.isBlank()) {
|
||||||
@@ -116,33 +129,50 @@ class AllergenSheet : AppSheet(R.layout.sheet_allergen) {
|
|||||||
*
|
*
|
||||||
* @return a string of all allergens
|
* @return a string of all allergens
|
||||||
*/
|
*/
|
||||||
private fun String.compileAllergenString(): String {
|
private fun String.compileStrings(): Pair<String, String> {
|
||||||
|
|
||||||
// Let the user know if no allergens are present
|
// Let the user know if no allergens are present
|
||||||
if (this.isBlank()) return getString(R.string.allergens_none)
|
if (this.isBlank()) return Pair("", "")
|
||||||
|
|
||||||
|
// Stores all localised additives
|
||||||
|
val additiveList = mutableListOf<String>()
|
||||||
|
|
||||||
// Stores all localised allergens
|
// Stores all localised allergens
|
||||||
var allergenString = ""
|
val allergenList = mutableListOf<String>()
|
||||||
|
|
||||||
// Used to insert a delimiter if more than one allergen is found
|
|
||||||
var isFirst = true
|
|
||||||
|
|
||||||
// Split all allergens to iterate through them
|
// Split all allergens to iterate through them
|
||||||
val allergens = this.replace(" ", "").split(",")
|
val allergens = this.replace(" ", "").split(",")
|
||||||
|
|
||||||
// Iterate through all allergens
|
// Iterate through all items
|
||||||
allergens.forEach { allergen ->
|
allergens.forEach { allergen ->
|
||||||
// Insert a delimiter if more than one allergen is found
|
|
||||||
if (!isFirst) allergenString += ", "
|
|
||||||
|
|
||||||
// Add a localised string for the allergen
|
// Check if the item is an allergen or an additive
|
||||||
allergenString += getString(Allergens.getStringRes(allergen))
|
if (allergen.toIntOrNull() == null) {
|
||||||
|
// If the item is not numeric, it is an allergen. Add this to the allergens.
|
||||||
// Set when the first allergen has been processed
|
allergenList.add(getString(Allergens.getStringRes(allergen)))
|
||||||
isFirst = false
|
} else {
|
||||||
|
// If the item is numeric, it is an additive. Add this to the additives.
|
||||||
|
additiveList.add(getString(Allergens.getStringRes(allergen)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the allergens into a template string
|
// Insert the items into a template string
|
||||||
return getString(R.string.allergens_contains, allergenString)
|
// return getString(
|
||||||
|
// R.string.allergens_contains,
|
||||||
|
// allergenList.joinToString(", ").ifBlank {
|
||||||
|
// getString(R.string.allergens_single_none)
|
||||||
|
// },
|
||||||
|
// additiveList.joinToString(", ").ifBlank {
|
||||||
|
// getString(R.string.allergens_single_none)
|
||||||
|
// },
|
||||||
|
// )
|
||||||
|
return Pair(
|
||||||
|
allergenList.joinToString(", ").ifBlank {
|
||||||
|
getString(R.string.allergens_single_none)
|
||||||
|
},
|
||||||
|
additiveList.joinToString(", ").ifBlank {
|
||||||
|
getString(R.string.allergens_single_none)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,12 +70,53 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_marginBottom="8dp"/>
|
android:layout_marginBottom="8dp"/>
|
||||||
|
|
||||||
<TextView
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
android:id="@+id/text_content"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="8dp"/>
|
android:layout_marginBottom="8dp"
|
||||||
<!-- android:textSize="16sp"-->
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<GridLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:rowCount="2"
|
||||||
|
android:columnCount="2">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_allergens_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_allergens_content"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="fill_horizontal"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_additives_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="1dp"
|
||||||
|
android:layout_gravity="top"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_additives_content"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="1dp"
|
||||||
|
android:layout_gravity="fill_horizontal"/>
|
||||||
|
|
||||||
|
</GridLayout>
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
||||||
|
<!-- <TextView-->
|
||||||
|
<!-- android:id="@+id/text_content"-->
|
||||||
|
<!-- android:layout_width="match_parent"-->
|
||||||
|
<!-- android:layout_height="wrap_content"-->
|
||||||
|
<!-- android:layout_marginBottom="8dp"/>-->
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_price"
|
android:id="@+id/text_price"
|
||||||
|
|||||||
@@ -156,13 +156,16 @@
|
|||||||
<string name="allergen_macadamia">Macadamianüsse</string>
|
<string name="allergen_macadamia">Macadamianüsse</string>
|
||||||
<string name="allergen_celery">Sellerie</string>
|
<string name="allergen_celery">Sellerie</string>
|
||||||
<string name="allergen_mustard">Senf</string>
|
<string name="allergen_mustard">Senf</string>
|
||||||
<string name="allergen_sulphides">Schwefeldioxide & Sulfide von mehr als 10mg/kg or 10mg/l</string>
|
<string name="allergen_sulphides">Schwefeldioxide & Sulfide von mehr als 10mg/kg bzw. 10mg/l</string>
|
||||||
<string name="allergen_lupins">Lupinen</string>
|
<string name="allergen_lupins">Lupinen</string>
|
||||||
<string name="allergen_sesame">Sesam</string>
|
<string name="allergen_sesame">Sesam</string>
|
||||||
<string name="allergen_molluscs">Weichtiere</string>
|
<string name="allergen_molluscs">Weichtiere</string>
|
||||||
|
|
||||||
<string name="allergens_none">Enthält weder Allergene noch Zusatzstoffe.</string>
|
<string name="allergens_none">Enthält weder Allergene noch Zusatzstoffe.</string>
|
||||||
<string name="allergens_contains">Enthält: %s.</string>
|
<string name="allergens_single_none">keine</string>
|
||||||
|
<string name="allergens_allergens_title">"Allergene: "</string>
|
||||||
|
<string name="allergens_additives_title">"Zusatzstoffe: "</string>
|
||||||
|
<string name="allergens_content_template">%s.</string>
|
||||||
<string name="canteen_page_allergen_sheet_error">Beim Laden dieses Angebots ist ein Fehler aufgetreten.</string>
|
<string name="canteen_page_allergen_sheet_error">Beim Laden dieses Angebots ist ein Fehler aufgetreten.</string>
|
||||||
|
|
||||||
<string name="nav_schedule">Stundenplan</string>
|
<string name="nav_schedule">Stundenplan</string>
|
||||||
|
|||||||
@@ -166,7 +166,10 @@
|
|||||||
<string name="allergen_molluscs">molluscs</string>
|
<string name="allergen_molluscs">molluscs</string>
|
||||||
|
|
||||||
<string name="allergens_none">Contains no allergens or additives.</string>
|
<string name="allergens_none">Contains no allergens or additives.</string>
|
||||||
<string name="allergens_contains">Contains: %s.</string>
|
<string name="allergens_single_none">none</string>
|
||||||
|
<string name="allergens_allergens_title">"Allergens: "</string>
|
||||||
|
<string name="allergens_additives_title">"Additives: "</string>
|
||||||
|
<string name="allergens_content_template" translatable="false">%s.</string>
|
||||||
<string name="canteen_page_allergen_sheet_error">An error occurred while trying to retrieve this offer.</string>
|
<string name="canteen_page_allergen_sheet_error">An error occurred while trying to retrieve this offer.</string>
|
||||||
|
|
||||||
<string name="nav_schedule">Schedule</string>
|
<string name="nav_schedule">Schedule</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user