Compare commits

..

2 Commits

Author SHA1 Message Date
LilleBRG
9870689068 merged 2025-04-28 13:57:43 +02:00
LilleBRG
92e8e2289b try to add create dish 2025-04-28 13:54:31 +02:00
8 changed files with 213 additions and 4 deletions

View File

@ -38,6 +38,10 @@
<activity <activity
android:name=".RegisterActivity" android:name=".RegisterActivity"
android:exported="false" /> android:exported="false" />
<activity
android:name=".CreateDishActivity" />
</application> </application>
</manifest> </manifest>

View File

@ -0,0 +1,25 @@
package tech.mercantec.easyeat
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
class CreateDishActivity : AppCompatActivity() {
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)
// Enable the Up button
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
// Handle the Up button click
override fun onSupportNavigateUp(): Boolean {
onBackPressedDispatcher.onBackPressed()
return true
}
}

View File

@ -1,5 +1,6 @@
package tech.mercantec.easyeat package tech.mercantec.easyeat
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@ -7,6 +8,7 @@ import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController import androidx.navigation.ui.setupWithNavController
import com.google.android.material.floatingactionbutton.FloatingActionButton
import tech.mercantec.easyeat.databinding.ActivityMainBinding import tech.mercantec.easyeat.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@ -29,5 +31,33 @@ class MainActivity : AppCompatActivity() {
) )
setupActionBarWithNavController(navController, appBarConfiguration) setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController) navView.setupWithNavController(navController)
val listView: ListView = findViewById(R.id.dishesList)
val listItems = arrayOf(
Dish("Spaghetti Bolognese", "Beef", 70.5),
Dish("Margherita Pizza", "Cheese", 60.0),
Dish("Chicken Curry", "Chicken", 80.2),
Dish("Vegetable Stir Fry", "Mixed Vegetables", 50.5),
Dish("Sushi", "Fish", 100.0),
Dish("Beef Tacos", "Beef", 60.8),
Dish("Lentil Soup", "Lentils", 40.5),
Dish("Pasta Alfredo", "Cream", 60.9),
Dish("Caesar Salad", "Chicken", 50.8),
Dish("Falafel Wrap", "Chickpeas", 50.2)
)
val listAdapter = DishAdapter(this, listItems)
listView.adapter = listAdapter
listView.setOnItemClickListener { parent, view, position, id ->
val selectedItem = parent.getItemAtPosition(position) as Dish
Toast.makeText(this, "you selected $selectedItem.name that costs ${selectedItem.expense} kr.", Toast.LENGTH_LONG).show()
}
findViewById<FloatingActionButton>(R.id.add_dish).setOnClickListener {
val intent = Intent(this, CreateDishActivity::class.java)
startActivity(intent)
}
} }
} }

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
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"
android:text="@string/create_dish_heading"
android:textAlignment="center"
android:textSize="24sp" />
<include
layout="@layout/activity_create_dish_ingredient_row" />
<Button
android:id="@+id/addIngredientButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Ingredient"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"/>
</LinearLayout>

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
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">
<!-- Amount field (fixed width) -->
<LinearLayout
android:layout_width="174dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/amount_label" />
<EditText
android:layout_width="173dp"
android:layout_height="48dp"
android:hint="0" />
</LinearLayout>
<!-- 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">
<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 (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>

View File

@ -2,9 +2,38 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container" android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> 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" />
<!-- Navigation Fragment -->
<ListView
android:id="@+id/dishesList"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
</ListView>
<!-- Navigation Fragment --> <!-- Navigation Fragment -->
<fragment <fragment
@ -13,10 +42,10 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:defaultNavHost="true" app:defaultNavHost="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/nav_view" app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" /> app:navGraph="@navigation/mobile_navigation" />
<!-- Bottom Navigation --> <!-- Bottom Navigation -->
@ -26,8 +55,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/windowBackground" android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" /> app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -6,4 +6,5 @@
<color name="dark_gray">#FF757575</color> <color name="dark_gray">#FF757575</color>
<color name="black">#FF242424</color> <color name="black">#FF242424</color>
<color name="white">#FFF9F9F9</color> <color name="white">#FFF9F9F9</color>
<color name="red">#D62D2D </color>
</resources> </resources>

View File

@ -17,4 +17,10 @@
<string name="confirm_password_label">Confirm password</string> <string name="confirm_password_label">Confirm password</string>
<string name="password_hint">&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;</string> <string name="password_hint">&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;&#8226;</string>
<string name="back_label">Back</string> <string name="back_label">Back</string>
<string name="create_dish_heading">Create Dish</string>
<string name="ingredient_label">Ingredient</string>
<string name="measurement_label">Measurement</string>
<string name="amount_label">Amount</string>
<string name="add_label">Add</string>
</resources> </resources>