Redesign dish details page

This commit is contained in:
Reimar 2025-05-13 22:09:50 +02:00
parent 7a25b0708b
commit 48b3622542
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268
3 changed files with 53 additions and 59 deletions

View File

@ -3,8 +3,10 @@ package tech.mercantec.easyeat.ui.dishes
import android.app.Activity
import android.app.ProgressDialog
import android.os.Bundle
import android.text.Html
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Toast
@ -25,7 +27,7 @@ class DishDetailsActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dish_details)
val ingredientsContainer = findViewById<LinearLayout>(R.id.dishDetailIngredients)
val ingredientsContainer = findViewById<LinearLayout>(R.id.ingredients)
val multiplierEditText = findViewById<EditText>(R.id.ingredientMultiplier)
val dishId = intent.getIntExtra("dish_id", -1)
@ -48,30 +50,20 @@ class DishDetailsActivity : AppCompatActivity() {
return@thread
}
Log.i("DISH", recipe.ingredients.toString())
val ingredientsLayout = findViewById<LinearLayout>(R.id.dishDetailIngredients)
val instructionsLayout = findViewById<LinearLayout>(R.id.dishDetailInstructions)
val instructionsLayout = findViewById<LinearLayout>(R.id.instructions)
// Example data: recipe.ingredients and recipe.directions
runOnUiThread {
findViewById<TextView>(R.id.dishDetailName).text = recipe.name
findViewById<TextView>(R.id.dishDetailDescription).text = recipe.description
// Populate Ingredients
recipe.ingredients.forEach { ingredient ->
val textView = TextView(this).apply {
text = "${ingredient.name} ${ingredient.amount ?: ""} ${ingredient.unit ?: ""}"
textSize = 18f
}
textView.textAlignment = View.TEXT_ALIGNMENT_CENTER
ingredientsLayout.addView(textView)
}
// Populate Instructions (if directions are strings)
recipe.directions.forEachIndexed { index, direction ->
val textView = TextView(this).apply {
text = "${index + 1}. $direction"
textSize = 18f
setPadding(0, 8, 0, 8)
}
textView.textAlignment = View.TEXT_ALIGNMENT_CENTER
instructionsLayout.addView(textView)
}
}
@ -82,10 +74,9 @@ class DishDetailsActivity : AppCompatActivity() {
for (ingredient in ingredients) {
val row = TextView(this)
val amount = (ingredient.amount ?: 0.0) * multiplier
row.text = "${ingredient.name}: ${"%.2f".format(amount)} ${ingredient.unit ?: ""}"
row.text = Html.fromHtml("&#8226; ${ingredient.name}: ${"%.2f".format(amount)} ${ingredient.unit ?: ""}", Html.FROM_HTML_MODE_LEGACY)
row.textSize = 18f
row.setPadding(0, 8, 0, 8)
row.textAlignment = View.TEXT_ALIGNMENT_CENTER
container.addView(row)
}
}

View File

@ -1,89 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
android:padding="30sp"
android:orientation="vertical">
<TextView
android:id="@+id/dishDetailName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textAlignment="center"
android:layout_marginBottom="10dp"
android:textStyle="bold"
android:layout_marginHorizontal="10sp"/>
style="@style/HighContrastText"
/>
<TextView
android:id="@+id/dishDetailDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textAlignment="center"
android:layout_marginHorizontal="10sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="20dp"
android:textSize="25sp"
android:textAlignment="center"
android:textStyle="bold"
android:text="Ingredients"/>
/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginHorizontal="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:layout_marginLeft="10sp"
android:text="Food for how many people?"
android:layout_weight="0.7"/>
android:textSize="16sp"
android:paddingTop="8dp"
android:text="@string/portions_label"
/>
<EditText
android:id="@+id/ingredientMultiplier"
android:layout_width="match_parent"
android:layout_marginStart="20dp"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:layout_weight="1"
android:layout_marginRight="10sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/dishDetailIngredients"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginHorizontal="10sp">
/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="20dp"
android:textSize="25sp"
android:textAlignment="center"
android:textStyle="bold"
android:text="Instructions"/>
android:textSize="18sp"
android:text="@string/ingredients_label"
style="@style/HighContrastText"
/>
<LinearLayout
android:id="@+id/dishDetailInstructions"
android:id="@+id/ingredients"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="20dp"
android:textStyle="bold"
android:textSize="18sp"
android:text="@string/instructions_label"
style="@style/HighContrastText"
/>
<LinearLayout
android:id="@+id/instructions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginHorizontal="10sp"/>
/>
<Button
android:id="@+id/addDishToShoppingList"
@ -93,6 +93,7 @@
android:layout_margin="16dp"
android:backgroundTint="@color/cyan"
android:text="@string/add_ingredients_to_shopping_list"
android:tint="@android:color/white"/>
android:tint="@android:color/white"
/>
</LinearLayout>
</ScrollView>

View File

@ -52,6 +52,8 @@
<string name="directions_label">Directions</string>
<string name="create_manually_label">Create manually</string>
<string name="create_ai_label">Generate recipe using AI</string>
<string name="portions_label">Portions</string>
<string name="instructions_label">Instructions</string>
<string-array name="units">
<item></item>
<item>g</item>