Further error handling. Also given the user the option to colour dietary preference icons. Colours have partially been derived from those used on stw-bremen.de but have all been processed through the theme builder on m3.material.io

This commit is contained in:
denizk0461
2023-04-29 22:26:26 +02:00
parent 2bf340bdff
commit 7243df0f06
21 changed files with 449 additions and 114 deletions
@@ -1,10 +1,12 @@
package com.denizk0461.studip.sheet
import android.content.res.ColorStateList
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import com.denizk0461.studip.R
import com.denizk0461.studip.data.getThemedColor
import com.denizk0461.studip.data.viewBinding
import com.denizk0461.studip.databinding.ItemSheetPreferenceBinding
import com.denizk0461.studip.databinding.SheetAllergenBinding
@@ -18,10 +20,12 @@ import com.denizk0461.studip.model.DietaryPreferences
*
* @param offer item to display further information on
* @param category category the offer belongs to
* @param displayColours whether the user wants dietary preferences to be marked with colours
*/
class AllergenSheet(
private val offer: CanteenOfferGroupElement,
private val category: String,
private val displayColours: Boolean,
) : AppSheet(R.layout.sheet_allergen) {
// View binding
@@ -45,7 +49,7 @@ class AllergenSheet(
// Inflate the view
val prefLine = ItemSheetPreferenceBinding.inflate(LayoutInflater.from(context))
val (stringId, drawableId) = DietaryPreferences.getData(index)
val (stringId, drawableId, colourId) = DietaryPreferences.getData(index)
// Add the localised text for the preference
prefLine.preferenceText.text = getString(stringId)
@@ -58,6 +62,17 @@ class AllergenSheet(
)
)
// Set tint of the icon; themed to the preference, if the user has the option enabled
prefLine.preferenceImage.imageTintList = ColorStateList.valueOf(
context.theme.getThemedColor(
if (displayColours) {
colourId
} else {
R.attr.colorText
}
)
)
// Add the view to the sheet's view container
containerPreferences.addView(prefLine.root)
}
@@ -62,6 +62,7 @@ class DevCodeSheet(
"SU5TQU5F".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS90NE9kYTlUZFYwbw==".d64)
"X0RSV05f".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9SUVpUUy1CWjhtcw==".d64)
"TUFSR0Uh".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS8tbHFxRHZXRjQ1dw==".d64)
"UE9XRUxM".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9XUGMtVkVxQlBISQ==".d64)
"NEVENT" -> { // nuke events
nukeEvents()
showToast(context, "Nuked all events")
@@ -86,7 +87,8 @@ class DevCodeSheet(
nukeEverything()
showToast(context, "Nuked everything")
}
else -> showToast(context, "code is invalid")
"HACK()" -> showToast(context, "Hack attempt unsuccessful")
else -> showToast(context, "Code is invalid")
}
dismiss()
}