Create recipe fragment
This commit is contained in:
parent
c423a9e19d
commit
4772c0ef26
@ -0,0 +1,54 @@
|
||||
package tech.mercantec.easyeat.ui.dishes
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.text.Html.FROM_HTML_MODE_LEGACY
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import kotlinx.serialization.json.Json
|
||||
import tech.mercantec.easyeat.R
|
||||
import tech.mercantec.easyeat.models.Recipe
|
||||
|
||||
class RecipeFragment : Fragment() {
|
||||
private var recipe: Recipe? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
arguments?.let { args ->
|
||||
recipe = args.getString("RECIPE")?.let { Json.decodeFromString<Recipe>(it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
val binding = inflater.inflate(R.layout.fragment_recipe, container, false)
|
||||
|
||||
recipe?.let { recipe ->
|
||||
binding.findViewById<TextView>(R.id.title).text = recipe.name
|
||||
|
||||
binding.findViewById<TextView>(R.id.ingredients).text =
|
||||
Html.fromHtml(
|
||||
"<ul>" +
|
||||
recipe.ingredients.map { "<li>${it.amount} ${it.unit} ${it.name}</li>" } +
|
||||
"</ul>",
|
||||
FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
|
||||
binding.findViewById<TextView>(R.id.directions).text =
|
||||
Html.fromHtml(
|
||||
"<ul>" +
|
||||
recipe.directions.map { "<li>${it}</li>" } +
|
||||
"</ul>",
|
||||
FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
|
||||
return binding
|
||||
}
|
||||
}
|
48
app/app/src/main/res/layout/fragment_recipe.xml
Normal file
48
app/app/src/main/res/layout/fragment_recipe.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:padding="30dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:textSize="24sp"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/ingredients_label"
|
||||
style="@style/HighContrastText"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ingredients"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/directions_label"
|
||||
style="@style/HighContrastText"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/directions"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
6
app/app/src/main/res/values-night/styles.xml
Normal file
6
app/app/src/main/res/values-night/styles.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="HighContrastText" parent="TextAppearance.AppCompat">
|
||||
<item name="android:textColor">@color/white</item>
|
||||
</style>
|
||||
</resources>
|
@ -47,6 +47,8 @@
|
||||
<string name="ai_generate_recipe_title">Generate recipe with AI</string>
|
||||
<string name="dish_title_label">Name of dish</string>
|
||||
<string name="generate_recipe_label">Generate</string>
|
||||
<string name="ingredients_label">Ingredients</string>
|
||||
<string name="directions_label">Directions</string>
|
||||
<string-array name="units">
|
||||
<item></item>
|
||||
<item>g</item>
|
||||
|
6
app/app/src/main/res/values/styles.xml
Normal file
6
app/app/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="HighContrastText" parent="TextAppearance.AppCompat">
|
||||
<item name="android:textColor">@color/black</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user