Archived
Added further information to be shown in AllergenSheet.kt
This commit is contained in:
@@ -2,13 +2,14 @@ package com.denizk0461.studip.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.denizk0461.studip.R
|
||||
import com.denizk0461.studip.databinding.ItemCanteenBinding
|
||||
import com.denizk0461.studip.databinding.ItemCanteenLineBinding
|
||||
import com.denizk0461.studip.databinding.ItemIconBinding
|
||||
import com.denizk0461.studip.model.CanteenOfferGroup
|
||||
import com.denizk0461.studip.model.CanteenOfferGroupElement
|
||||
import com.denizk0461.studip.model.DietaryPreferences
|
||||
|
||||
/**
|
||||
* Custom RecyclerView adapter that lays out the offers of a given canteen on a given day.
|
||||
@@ -23,24 +24,6 @@ class CanteenOfferItemAdapter(
|
||||
private val displayAllergens: Boolean,
|
||||
) : RecyclerView.Adapter<CanteenOfferItemAdapter.OfferViewHolder>() {
|
||||
|
||||
/**
|
||||
* Provides a converting function between the index of a dietary preference and its according
|
||||
* icon.
|
||||
*/
|
||||
private val indexToDrawable: Map<Int, Int> = mapOf(
|
||||
0 to R.drawable.handshake,
|
||||
1 to R.drawable.fish,
|
||||
2 to R.drawable.chicken,
|
||||
3 to R.drawable.sheep,
|
||||
4 to R.drawable.yoga,
|
||||
5 to R.drawable.cow,
|
||||
6 to R.drawable.pig,
|
||||
7 to R.drawable.leaf,
|
||||
8 to R.drawable.carrot,
|
||||
9 to R.drawable.deer,
|
||||
10 to R.drawable.circle,
|
||||
)
|
||||
|
||||
/**
|
||||
* View holder class for parent class
|
||||
*
|
||||
@@ -102,7 +85,10 @@ class CanteenOfferItemAdapter(
|
||||
|
||||
// Set the appropriate icon
|
||||
img.imageView.setImageDrawable(
|
||||
holder.binding.root.context.getDrawable(indexToDrawable[index]!!)
|
||||
AppCompatResources.getDrawable(
|
||||
holder.binding.root.context,
|
||||
DietaryPreferences.indexToDrawable[index]!!,
|
||||
)
|
||||
)
|
||||
|
||||
// Bind the new icon to the line view
|
||||
@@ -111,7 +97,7 @@ class CanteenOfferItemAdapter(
|
||||
|
||||
// Set up single click listener
|
||||
line.root.setOnClickListener {
|
||||
onClickListener.onClick(offer)
|
||||
onClickListener.onClick(offer, currentItem.category)
|
||||
}
|
||||
|
||||
// Set up long press listener
|
||||
@@ -153,7 +139,7 @@ class CanteenOfferItemAdapter(
|
||||
*
|
||||
* @param offer item that has been clicked
|
||||
*/
|
||||
fun onClick(offer: CanteenOfferGroupElement)
|
||||
fun onClick(offer: CanteenOfferGroupElement, category: String)
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -279,8 +279,8 @@ class CanteenFragment : AppFragment(), CanteenOfferItemAdapter.OnClickListener {
|
||||
*
|
||||
* @param offer item that has been clicked
|
||||
*/
|
||||
override fun onClick(offer: CanteenOfferGroupElement) {
|
||||
openBottomSheet(AllergenSheet(offer))
|
||||
override fun onClick(offer: CanteenOfferGroupElement, category: String) {
|
||||
openBottomSheet(AllergenSheet(offer, category))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.denizk0461.studip.model
|
||||
|
||||
import com.denizk0461.studip.R
|
||||
|
||||
/**
|
||||
* Enumeration that can be used in conjunction with DietaryPrefObject.kt to more concisely look up,
|
||||
* specify, and iterate through dietary preferences. Order of these elements matches the order used
|
||||
@@ -19,4 +21,45 @@ enum class DietaryPreferences(val value: String) {
|
||||
VEGAN("isVegan"),
|
||||
VEGETARIAN("isVegetarian"),
|
||||
GAME("isGame"),
|
||||
;
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Provides a converting function between the index of a dietary preference and its according
|
||||
* icon.
|
||||
* TODO this seems inefficient
|
||||
*/
|
||||
val indexToDrawable: Map<Int, Int> = mapOf(
|
||||
0 to R.drawable.handshake,
|
||||
1 to R.drawable.fish,
|
||||
2 to R.drawable.chicken,
|
||||
3 to R.drawable.sheep,
|
||||
4 to R.drawable.yoga,
|
||||
5 to R.drawable.cow,
|
||||
6 to R.drawable.pig,
|
||||
7 to R.drawable.leaf,
|
||||
8 to R.drawable.carrot,
|
||||
9 to R.drawable.deer,
|
||||
10 to R.drawable.circle,
|
||||
)
|
||||
|
||||
/**
|
||||
* Provides a converting function between the index of a dietary preference and its
|
||||
* according localised text string.
|
||||
* TODO this seems inefficient
|
||||
*/
|
||||
val indexToString: Map<Int, Int> = mapOf(
|
||||
0 to R.string.pref_fair,
|
||||
1 to R.string.pref_fish,
|
||||
2 to R.string.pref_poultry,
|
||||
3 to R.string.pref_lamb,
|
||||
4 to R.string.pref_vital,
|
||||
5 to R.string.pref_beef,
|
||||
6 to R.string.pref_pork,
|
||||
7 to R.string.pref_vegan,
|
||||
8 to R.string.pref_vegetarian,
|
||||
9 to R.string.pref_game,
|
||||
10 to 0, // shouldn't occur
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,25 @@
|
||||
package com.denizk0461.studip.sheet
|
||||
|
||||
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.viewBinding
|
||||
import com.denizk0461.studip.databinding.ItemSheetPreferenceBinding
|
||||
import com.denizk0461.studip.databinding.SheetAllergenBinding
|
||||
import com.denizk0461.studip.model.Allergens
|
||||
import com.denizk0461.studip.model.CanteenOfferGroupElement
|
||||
import com.denizk0461.studip.model.DietaryPreferences
|
||||
|
||||
class AllergenSheet(private val offer: CanteenOfferGroupElement) : AppSheet(R.layout.sheet_allergen) {
|
||||
/**
|
||||
* This class is used to display further information on a canteen offer to the user. Unlike the name
|
||||
* implies, it displays more than just allergens.
|
||||
*/
|
||||
class AllergenSheet(
|
||||
private val offer: CanteenOfferGroupElement,
|
||||
private val category: String,
|
||||
) : AppSheet(R.layout.sheet_allergen) {
|
||||
|
||||
private val binding: SheetAllergenBinding by viewBinding(SheetAllergenBinding::bind)
|
||||
|
||||
@@ -16,8 +27,46 @@ class AllergenSheet(private val offer: CanteenOfferGroupElement) : AppSheet(R.la
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.apply {
|
||||
title.text = offer.title
|
||||
|
||||
// Category header
|
||||
textCategory.text = getString(R.string.sheet_category, category)
|
||||
|
||||
// Offer text
|
||||
textTitle.text = offer.title
|
||||
|
||||
// Iterate through all dietary preferences
|
||||
offer.dietaryPreferences.toList().forEachIndexed { index, c ->
|
||||
// If a preference is met, inflate a view to display it
|
||||
if (c == 't') {
|
||||
// Inflate the view
|
||||
val prefLine = ItemSheetPreferenceBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
// Add the localised text for the preference
|
||||
prefLine.preferenceText.text = getString(DietaryPreferences.indexToString[index]!!)
|
||||
|
||||
// Set the appropriate icon
|
||||
prefLine.preferenceImage.setImageDrawable(
|
||||
getDrawable(
|
||||
context,
|
||||
DietaryPreferences.indexToDrawable[index]!!,
|
||||
)
|
||||
)
|
||||
|
||||
// Add the view to the sheet's view container
|
||||
containerPreferences.addView(prefLine.root)
|
||||
}
|
||||
}
|
||||
|
||||
// Allergen and additive notice
|
||||
textContent.text = offer.allergens.compileAllergenString()
|
||||
|
||||
// Show a price, if one is available
|
||||
if (offer.price.isBlank()) {
|
||||
textPrice.visibility = View.GONE
|
||||
} else {
|
||||
textPrice.visibility = View.VISIBLE
|
||||
textPrice.text = offer.price
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/preference_image"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:scaleType="centerInside"
|
||||
app:tint="?attr/colorOnSurfaceVariant"
|
||||
android:layout_marginEnd="8dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/preference_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
@@ -5,30 +5,53 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingHorizontal="24dp"
|
||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:id="@+id/text_category"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="22sp"
|
||||
android:fontFamily="@font/lato_blackitalic"
|
||||
android:layout_marginBottom="2dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="22sp"
|
||||
android:fontFamily="@font/lato_bolditalic"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginHorizontal="24dp"/>
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<!-- <androidx.core.widget.NestedScrollView-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:scrollbars="vertical">-->
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:id="@+id/container_preferences"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="vertical">
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:paddingBottom="16dp"/>
|
||||
<TextView
|
||||
android:id="@+id/text_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
<!-- android:textSize="16sp"-->
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
<TextView
|
||||
android:id="@+id/text_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:fontFamily="@font/lato_bolditalic"
|
||||
android:layout_marginTop="4dp"/>
|
||||
|
||||
<!-- </androidx.core.widget.NestedScrollView>-->
|
||||
|
||||
</LinearLayout>
|
||||
@@ -104,6 +104,4 @@
|
||||
<string name="settings_app_version">App-Verison</string>
|
||||
|
||||
<string name="with_love">mit ♡️ aus Bremen-Osterholz\von denizk0461 \\__*</string>
|
||||
|
||||
<string name="de4thSpirit">In our hearts, she lives forevermore</string>
|
||||
</resources>
|
||||
@@ -22,6 +22,8 @@
|
||||
<string name="cafeteria_bhv">Cafeteria Bremerhaven</string>
|
||||
<string name="mensa_hfk">Interimsmensa HfK</string>
|
||||
|
||||
<string name="sheet_category" translatable="false">[ %s ]</string>
|
||||
|
||||
<!-- dietary preferences -->
|
||||
<string name="pref_fair">Fair</string> <!-- is this really the best name? what about 'animal welfare'? -->
|
||||
<string name="pref_fish">Fish</string>
|
||||
@@ -105,5 +107,5 @@
|
||||
|
||||
<string name="with_love">with ♡️ from Bremen-Osterholz\nmade by denizk0461 \\__*</string>
|
||||
|
||||
<string name="de4thSpirit">In our hearts, she lives forevermore</string>
|
||||
<string name="de4thSpirit" translatable="false">In our hearts, she lives forevermore</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user