multiple ingredient rows can now be added
This commit is contained in:
parent
3cbf52f8b2
commit
6743e9c7aa
@ -1,25 +1,42 @@
|
|||||||
package tech.mercantec.easyeat
|
package tech.mercantec.easyeat
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.LinearLayout
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.widget.Toolbar
|
|
||||||
|
|
||||||
class CreateDishActivity : AppCompatActivity() {
|
class CreateDishActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var ingredientContainer: LinearLayout
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_create_dish_form)
|
setContentView(R.layout.activity_create_dish_form)
|
||||||
|
|
||||||
// Setup the Toolbar as ActionBar
|
ingredientContainer = findViewById(R.id.ingredientContainer)
|
||||||
val toolbar: Toolbar = findViewById(R.id.toolbar)
|
val addButton: Button = findViewById(R.id.addIngredientButton)
|
||||||
setSupportActionBar(toolbar)
|
|
||||||
|
|
||||||
// Enable the Up button
|
// Add the first ingredient row manually at startup
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
addIngredientRow()
|
||||||
|
|
||||||
|
// Set up button to add new rows
|
||||||
|
addButton.setOnClickListener {
|
||||||
|
addIngredientRow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the Up button click
|
private fun addIngredientRow() {
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
val inflater = LayoutInflater.from(this)
|
||||||
onBackPressedDispatcher.onBackPressed()
|
val ingredientRow = inflater.inflate(R.layout.activity_create_dish_ingredient_row, null)
|
||||||
return true
|
|
||||||
|
// Handle remove button in each row
|
||||||
|
val removeButton: Button = ingredientRow.findViewById(R.id.removeButton)
|
||||||
|
removeButton.setOnClickListener {
|
||||||
|
ingredientContainer.removeView(ingredientRow)
|
||||||
|
}
|
||||||
|
|
||||||
|
ingredientContainer.addView(ingredientRow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,6 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:title="Create Dish"
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -21,8 +13,12 @@
|
|||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp" />
|
||||||
|
|
||||||
<include
|
<!-- Container for all ingredient rows -->
|
||||||
layout="@layout/activity_create_dish_ingredient_row" />
|
<LinearLayout
|
||||||
|
android:id="@+id/ingredientContainer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/addIngredientButton"
|
android:id="@+id/addIngredientButton"
|
||||||
@ -32,3 +28,4 @@
|
|||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginTop="16dp"/>
|
android:layout_marginTop="16dp"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user