create dish button moved to dishesfragment
This commit is contained in:
parent
a63b98e180
commit
9d9a2975f5
@ -1,11 +1,15 @@
|
||||
package tech.mercantec.easyeat
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Spinner
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import tech.mercantec.easyeat.models.Ingredient
|
||||
|
||||
class CreateDishActivity : AppCompatActivity() {
|
||||
|
||||
@ -25,6 +29,19 @@ class CreateDishActivity : AppCompatActivity() {
|
||||
addButton.setOnClickListener {
|
||||
addIngredientRow()
|
||||
}
|
||||
|
||||
val saveButton: Button = findViewById(R.id.saveDishButton)
|
||||
saveButton.setOnClickListener {
|
||||
val ingredientList = collectIngredients()
|
||||
|
||||
// Debug/log example
|
||||
for (ingredient in ingredientList) {
|
||||
Log.d("INGREDIENT", "Name: ${ingredient.Element}, Amount: ${ingredient.Amount}, Unit: ${ingredient.Unit}")
|
||||
}
|
||||
|
||||
// You can now save to DB, send to backend, etc.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun addIngredientRow() {
|
||||
@ -39,4 +56,29 @@ class CreateDishActivity : AppCompatActivity() {
|
||||
|
||||
ingredientContainer.addView(ingredientRow)
|
||||
}
|
||||
|
||||
private fun collectIngredients(): List<Ingredient> {
|
||||
val ingredients = mutableListOf<Ingredient>()
|
||||
|
||||
for (i in 0 until ingredientContainer.childCount) {
|
||||
val ingredientView = ingredientContainer.getChildAt(i)
|
||||
|
||||
// Find views inside this ingredient row
|
||||
val nameEditText = ingredientView.findViewById<EditText>(R.id.ingredientNameEditText)
|
||||
val amountEditText = ingredientView.findViewById<EditText>(R.id.ingredientAmountEditText)
|
||||
val spinner = ingredientView.findViewById<Spinner>(R.id.spinner)
|
||||
|
||||
val element = nameEditText.text.toString().trim()
|
||||
val amount = amountEditText.text.toString().trim()
|
||||
val unit = spinner.selectedItem.toString()
|
||||
|
||||
// Optional: Only add non-empty rows
|
||||
if (element.isNotEmpty() && amount.isNotEmpty()) {
|
||||
ingredients.add(Ingredient(Element = element, Amount = amount.toInt(), Unit = unit))
|
||||
}
|
||||
}
|
||||
|
||||
return ingredients
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,11 +36,5 @@ class MainActivity : AppCompatActivity() {
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
navView.setupWithNavController(navController)
|
||||
|
||||
|
||||
findViewById<FloatingActionButton>(R.id.add_dish).setOnClickListener {
|
||||
val intent = Intent(this, CreateDishActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package tech.mercantec.easyeat.models
|
||||
|
||||
data class Ingredient(
|
||||
val Amount: Int,
|
||||
val Unit: String,
|
||||
val Element: String
|
||||
)
|
@ -1,11 +1,13 @@
|
||||
package tech.mercantec.easyeat.ui.dishes
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import tech.mercantec.easyeat.CreateDishActivity
|
||||
import tech.mercantec.easyeat.databinding.FragmentDishesBinding
|
||||
import tech.mercantec.easyeat.models.Dish
|
||||
|
||||
@ -25,6 +27,11 @@ class DishesFragment : Fragment() {
|
||||
_binding = FragmentDishesBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
binding.addDish.setOnClickListener {
|
||||
val intent = Intent(requireContext(), CreateDishActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
context?.let { context ->
|
||||
binding.dishesList.setOnItemClickListener { parent, view, position, id ->
|
||||
val selectedItem = parent.getItemAtPosition(position) as Dish
|
||||
@ -47,9 +54,13 @@ class DishesFragment : Fragment() {
|
||||
binding.dishesList.adapter = DishAdapter(context, listItems)
|
||||
}
|
||||
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
|
@ -27,5 +27,13 @@
|
||||
android:text="Add Ingredient"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/saveDishButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Save"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginTop="16dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -1,80 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="8dp">
|
||||
|
||||
<!-- Ingredient Field -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:text="@string/ingredient_label" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="58dp"
|
||||
android:hint="Ingredient name" />
|
||||
|
||||
<!-- Row: Amount + Measurement -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginTop="8dp">
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Amount field (fixed width) -->
|
||||
<!-- Ingredient Field -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:text="@string/ingredient_label" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ingredientNameEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="58dp"
|
||||
android:hint="Ingredient name" />
|
||||
|
||||
<!-- Row: Amount + Measurement -->
|
||||
<LinearLayout
|
||||
android:layout_width="174dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginTop="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
<!-- Amount field -->
|
||||
<LinearLayout
|
||||
android:layout_width="174dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/amount_label" />
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText
|
||||
android:layout_width="173dp"
|
||||
android:layout_height="48dp"
|
||||
android:hint="0" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/amount_label" />
|
||||
|
||||
<!-- Measurement field (fill rest) -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginStart="8dp">
|
||||
<EditText
|
||||
android:id="@+id/ingredientAmountEditText"
|
||||
android:layout_width="173dp"
|
||||
android:layout_height="48dp"
|
||||
android:hint="0" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
<!-- Measurement field -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/measurement_label" />
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginStart="8dp">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/measurement_label" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Remove Button -->
|
||||
<Button
|
||||
android:id="@+id/removeButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="-"
|
||||
android:textSize="20dp"
|
||||
android:backgroundTint="@color/red" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Remove Button (fixed width) -->
|
||||
<Button
|
||||
android:id="@+id/removeButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="-"
|
||||
android:textSize="20dp"
|
||||
android:backgroundTint="@color/red"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</ScrollView>
|
||||
|
@ -8,19 +8,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="?attr/actionBarSize">
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/add_dish"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:contentDescription="@string/add_label"
|
||||
app:srcCompat="@android:drawable/ic_input_add"
|
||||
app:backgroundTint="@color/cyan"
|
||||
app:tint="@android:color/white"
|
||||
app:layout_constraintBottom_toTopOf="@id/nav_view"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment_activity_main"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
|
@ -1,12 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/dishes_fragment_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- Your list view -->
|
||||
<ListView
|
||||
android:id="@+id/dishes_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="8dp"
|
||||
/>
|
||||
android:divider="@android:color/darker_gray"
|
||||
android:dividerHeight="1dp" />
|
||||
|
||||
<!-- FloatingActionButton -->
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/add_dish"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:backgroundTint="@color/cyan"
|
||||
app:srcCompat="@android:drawable/ic_input_add"
|
||||
app:tint="@android:color/white"/>
|
||||
</FrameLayout>
|
||||
|
20
backend/API/appsettings.example.json
Normal file
20
backend/API/appsettings.example.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"ConnectionStrings": {
|
||||
"Database": "Data Source=database.sqlite3"
|
||||
},
|
||||
|
||||
"JwtSettings": {
|
||||
"Issuer": "TemperatureAlarmApi",
|
||||
"Audience": "Customers",
|
||||
"Key": ""
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user