From 2088de994f6bf12bb7d6f4bba091ec83fa47937e Mon Sep 17 00:00:00 2001 From: LilleBRG Date: Thu, 15 May 2025 11:47:59 +0200 Subject: [PATCH] editrecipe works --- app/app/build.gradle.kts | 1 + app/app/gradle.properties | 1 + app/app/src/main/AndroidManifest.xml | 1 + .../tech/mercantec/easyeat/helpers/api.kt | 2 +- .../tech/mercantec/easyeat/helpers/dishes.kt | 3 - .../easyeat/ui/dishes/DishDetailsActivity.kt | 167 +++++++++--------- .../main/res/xml/network_security_config.xml | 2 +- backend/API/BusinessLogic/RecipeLogic.cs | 1 + 8 files changed, 90 insertions(+), 88 deletions(-) diff --git a/app/app/build.gradle.kts b/app/app/build.gradle.kts index eda15cf..27fa4b8 100644 --- a/app/app/build.gradle.kts +++ b/app/app/build.gradle.kts @@ -21,6 +21,7 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" buildConfigField("String", "API_BASE_URL", project.property("API_BASE_URL").toString()) + buildConfigField("String", "API_LOCALHOST_URL", project.property("API_LOCALHOST_URL").toString()) } diff --git a/app/app/gradle.properties b/app/app/gradle.properties index 7cf66d1..d9471b1 100644 --- a/app/app/gradle.properties +++ b/app/app/gradle.properties @@ -1 +1,2 @@ API_BASE_URL="https://easyeat.mercantec.tech" +API_LOCALHOST_URL="http://10.0.2.2:5000" diff --git a/app/app/src/main/AndroidManifest.xml b/app/app/src/main/AndroidManifest.xml index 2611327..44664e1 100644 --- a/app/app/src/main/AndroidManifest.xml +++ b/app/app/src/main/AndroidManifest.xml @@ -13,6 +13,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.EasyEat" + android:networkSecurityConfig="@xml/network_security_config" tools:targetApi="31"> { return requestJson>(ctx, "GET", "/api/Recipe/getall", null) } -@Serializable -data class RecipeDetailsResponse(val recipe: Recipe) - fun getRecipeDetails(ctx: Context, id: Int): Recipe { return requestJson(ctx, "GET", "/api/Recipe/get/$id", null) } diff --git a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishDetailsActivity.kt b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishDetailsActivity.kt index 0b80e7b..4d79f73 100644 --- a/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishDetailsActivity.kt +++ b/app/app/src/main/java/tech/mercantec/easyeat/ui/dishes/DishDetailsActivity.kt @@ -18,20 +18,21 @@ import kotlin.concurrent.thread import android.widget.EditText import android.widget.ImageButton import android.widget.TextView +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.widget.doAfterTextChanged import tech.mercantec.easyeat.helpers.AddRecipeToShoppingList import tech.mercantec.easyeat.models.Ingredient import tech.mercantec.easyeat.models.Recipe +private lateinit var editRecipeLauncher: ActivityResultLauncher + class DishDetailsActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_dish_details) - val ingredientsContainer = findViewById(R.id.ingredients) - val multiplierEditText = findViewById(R.id.ingredient_multiplier) - val dishId = intent.getIntExtra("dish_id", -1) if (dishId == -1) { Toast.makeText(this, "No dish ID provided", Toast.LENGTH_SHORT).show() @@ -39,6 +40,50 @@ class DishDetailsActivity : AppCompatActivity() { return } + editRecipeLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + loadRecipe(dishId) + } + } + + findViewById