help reimar

This commit is contained in:
LilleBRG 2025-05-14 12:47:20 +02:00
parent 4a935514cf
commit f9e006539c
3 changed files with 4 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package tech.mercantec.easyeat.helpers package tech.mercantec.easyeat.helpers
import android.content.Context import android.content.Context
import android.util.Log
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import tech.mercantec.easyeat.models.Ingredient import tech.mercantec.easyeat.models.Ingredient
import tech.mercantec.easyeat.models.Recipe import tech.mercantec.easyeat.models.Recipe

View File

@ -154,12 +154,11 @@ class DishDetailsActivity : AppCompatActivity() {
val editRecipeBtn: Button = findViewById(R.id.editRecipeBtn) val editRecipeBtn: Button = findViewById(R.id.editRecipeBtn)
editRecipeBtn.setOnClickListener { editRecipeBtn.setOnClickListener {
val jsonRecipe = Json.encodeToString(recipe) // convert Recipe to JSON string val jsonRecipe = Json.encodeToString(recipe) // convert Recipe to JSON string
Log.i("jsonrecipe", jsonRecipe)
val intent = Intent(this, EditDishActivity::class.java) val intent = Intent(this, EditDishActivity::class.java)
intent.putExtra("recipe_json", jsonRecipe) // put as string intent.putExtra("recipe_json", jsonRecipe) // put as string
startActivity(intent) startActivity(intent)
} }
} }
} }
} }

View File

@ -2,7 +2,6 @@ package tech.mercantec.easyeat.ui.dishes
import android.app.Activity import android.app.Activity
import android.app.ProgressDialog import android.app.ProgressDialog
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -57,7 +56,6 @@ class EditDishActivity : AppCompatActivity() {
addIngredientRow() addIngredientRow()
} }
saveButton.setOnClickListener {
saveButton.setOnClickListener { saveButton.setOnClickListener {
val ingredientList = collectIngredients() val ingredientList = collectIngredients()
val instructions = findViewById<EditText>(R.id.instructions).text.toString().trim() val instructions = findViewById<EditText>(R.id.instructions).text.toString().trim()
@ -67,6 +65,7 @@ class EditDishActivity : AppCompatActivity() {
.filter { it.isNotEmpty() } .filter { it.isNotEmpty() }
val updatedRecipe = Recipe( val updatedRecipe = Recipe(
id = null,
name = findViewById<EditText>(R.id.dishName).text.toString().trim(), name = findViewById<EditText>(R.id.dishName).text.toString().trim(),
description = findViewById<EditText>(R.id.dishDescription).text.toString().trim(), description = findViewById<EditText>(R.id.dishDescription).text.toString().trim(),
directions = directions, directions = directions,
@ -78,6 +77,7 @@ class EditDishActivity : AppCompatActivity() {
progressDialog.show() progressDialog.show()
thread { thread {
try { try {
updateRecipe(this, recipe.id!!, updatedRecipe) updateRecipe(this, recipe.id!!, updatedRecipe)
} catch (e: ApiRequestException) { } catch (e: ApiRequestException) {
runOnUiThread { runOnUiThread {
@ -99,7 +99,6 @@ class EditDishActivity : AppCompatActivity() {
finish() finish()
} }
} }
}
} }
private fun addIngredientRow(ingredient: Ingredient? = null) { private fun addIngredientRow(ingredient: Ingredient? = null) {