Reload dish list after generating, fix ingredient list when no amount

This commit is contained in:
Reimar 2025-05-14 09:30:52 +02:00
parent ba00a6e35e
commit 37757cbf46
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268
2 changed files with 5 additions and 5 deletions

View File

@ -72,10 +72,10 @@ class DishDetailsActivity : AppCompatActivity() {
for (ingredient in ingredients) { for (ingredient in ingredients) {
val row = TextView(this) val row = TextView(this)
val amount = (ingredient.amount ?: 0.0) * multiplier val amount = ingredient.amount?.times(multiplier)?.toBigDecimal()?.stripTrailingZeros()?.toPlainString()
val amountStr = amount.toBigDecimal().stripTrailingZeros().toPlainString() val amountStr = if (amount != null) ": $amount" else ""
row.text = Html.fromHtml("• ${ingredient.name}: $amountStr ${ingredient.unit ?: ""}", Html.FROM_HTML_MODE_LEGACY) row.text = Html.fromHtml("• ${ingredient.name}$amountStr ${ingredient.unit ?: ""}", Html.FROM_HTML_MODE_LEGACY)
row.textSize = 18f row.textSize = 18f
row.setPadding(0, 8, 0, 8) row.setPadding(0, 8, 0, 8)
container.addView(row) container.addView(row)

View File

@ -1,5 +1,6 @@
package tech.mercantec.easyeat.ui.dishes package tech.mercantec.easyeat.ui.dishes
import android.app.Activity
import android.app.ProgressDialog import android.app.ProgressDialog
import android.os.Bundle import android.os.Bundle
import android.widget.Button import android.widget.Button
@ -10,7 +11,6 @@ import tech.mercantec.easyeat.R
import tech.mercantec.easyeat.helpers.ApiRequestException import tech.mercantec.easyeat.helpers.ApiRequestException
import tech.mercantec.easyeat.helpers.createRecipe import tech.mercantec.easyeat.helpers.createRecipe
import tech.mercantec.easyeat.helpers.generateRecipeWithAI import tech.mercantec.easyeat.helpers.generateRecipeWithAI
import tech.mercantec.easyeat.models.Recipe
import java.util.Locale import java.util.Locale
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -27,7 +27,6 @@ class GenerateRecipeActivity : AppCompatActivity() {
progressDialog.show() progressDialog.show()
thread { thread {
// val response: GenerateRecipeResponse
try { try {
val recipe = generateRecipeWithAI(this, name, Locale.getDefault().displayLanguage) val recipe = generateRecipeWithAI(this, name, Locale.getDefault().displayLanguage)
@ -37,6 +36,7 @@ class GenerateRecipeActivity : AppCompatActivity() {
createRecipe(this, recipe) createRecipe(this, recipe)
setResult(Activity.RESULT_OK)
finish() finish()
} catch (e: ApiRequestException) { } catch (e: ApiRequestException) {
runOnUiThread { runOnUiThread {