Merge branch 'master' of git.reim.ar:ReiMerc/easyeat
This commit is contained in:
commit
182ca1655c
@ -1,25 +1,42 @@
|
||||
package tech.mercantec.easyeat
|
||||
|
||||
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.widget.Toolbar
|
||||
|
||||
class CreateDishActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var ingredientContainer: LinearLayout
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_create_dish_form)
|
||||
|
||||
// Setup the Toolbar as ActionBar
|
||||
val toolbar: Toolbar = findViewById(R.id.toolbar)
|
||||
setSupportActionBar(toolbar)
|
||||
ingredientContainer = findViewById(R.id.ingredientContainer)
|
||||
val addButton: Button = findViewById(R.id.addIngredientButton)
|
||||
|
||||
// Enable the Up button
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
// Add the first ingredient row manually at startup
|
||||
addIngredientRow()
|
||||
|
||||
// Set up button to add new rows
|
||||
addButton.setOnClickListener {
|
||||
addIngredientRow()
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the Up button click
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
private fun addIngredientRow() {
|
||||
val inflater = LayoutInflater.from(this)
|
||||
val ingredientRow = inflater.inflate(R.layout.activity_create_dish_ingredient_row, null)
|
||||
|
||||
// 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: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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -21,8 +13,12 @@
|
||||
android:textAlignment="center"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<include
|
||||
layout="@layout/activity_create_dish_ingredient_row" />
|
||||
<!-- Container for all ingredient rows -->
|
||||
<LinearLayout
|
||||
android:id="@+id/ingredientContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/addIngredientButton"
|
||||
@ -32,3 +28,4 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user