made modal for ai and manual creation of dish
This commit is contained in:
parent
dc7e94b37b
commit
799ddb76e5
@ -44,6 +44,10 @@
|
||||
android:name=".ui.dishes.CreateDishActivity"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.dishes.CreateDishAIActivity"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.profile.ChangePasswordActivity"
|
||||
android:exported="false" />
|
||||
|
@ -87,6 +87,14 @@ inline fun <reified Req, reified Res> requestJson(ctx: Context, method: String,
|
||||
}
|
||||
}
|
||||
|
||||
if (response.body.isBlank()) {
|
||||
// Return Unit or an empty default value depending on Res
|
||||
return when (Res::class) {
|
||||
Unit::class -> Unit as Res
|
||||
else -> throw ApiRequestException("Expected JSON but got empty response", null)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return Json.decodeFromString<Res>(response.body)
|
||||
} catch (e: SerializationException) {
|
||||
|
@ -114,7 +114,15 @@ data class CreateRecipeRequest(val recipe: Recipe)
|
||||
|
||||
fun createRecipe(ctx: Context, recipe: Recipe) {
|
||||
val request = CreateRecipeRequest(recipe)
|
||||
|
||||
return requestJson<CreateRecipeRequest, Unit>(ctx, "POST", "/api/recipe/create", request)
|
||||
|
||||
Log.i("recipe name:", recipe.name)
|
||||
Log.i("recipe name:", recipe.description)
|
||||
for (x in recipe.directions) {
|
||||
Log.i("recipe name:", x.instructions)
|
||||
}
|
||||
for(x in recipe.ingredients){
|
||||
Log.i("recipe name:", x.name)
|
||||
Log.i("recipe name:", x.amount.toString())
|
||||
Log.i("recipe name:", x.unit.toString())
|
||||
}
|
||||
requestJson<CreateRecipeRequest, Boolean>(ctx, "POST", "/api/recipe/create", request)
|
||||
}
|
||||
|
@ -34,10 +34,5 @@ class MainActivity : AppCompatActivity() {
|
||||
)
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
navView.setupWithNavController(navController)
|
||||
|
||||
findViewById<FloatingActionButton>(tech.mercantec.easyeat.R.id.add_dish).setOnClickListener {
|
||||
val intent = Intent(this, CreateDishActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package tech.mercantec.easyeat.ui.dishes
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import tech.mercantec.easyeat.R
|
||||
|
||||
class CreateDishAIActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.create_dish_ai_form)
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -60,16 +60,7 @@ class CreateDishActivity : AppCompatActivity() {
|
||||
ingredients = ingredientList
|
||||
)
|
||||
|
||||
Log.i("recipe name:", recipe.name)
|
||||
Log.i("recipe name:", recipe.description)
|
||||
for (x in recipe.directions) {
|
||||
Log.i("recipe name:", x.instructions)
|
||||
}
|
||||
for(x in recipe.ingredients){
|
||||
Log.i("recipe name:", x.name)
|
||||
Log.i("recipe name:", x.amount.toString())
|
||||
Log.i("recipe name:", x.unit.toString())
|
||||
}
|
||||
|
||||
val progressDialog = ProgressDialog(this)
|
||||
progressDialog.setMessage("Loading...")
|
||||
progressDialog.show()
|
||||
|
@ -5,8 +5,10 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import tech.mercantec.easyeat.R
|
||||
import tech.mercantec.easyeat.databinding.FragmentDishesBinding
|
||||
import tech.mercantec.easyeat.models.Dish
|
||||
|
||||
@ -27,10 +29,31 @@ class DishesFragment : Fragment() {
|
||||
val root: View = binding.root
|
||||
|
||||
binding.addDish.setOnClickListener {
|
||||
val intent = Intent(requireContext(), CreateDishActivity::class.java)
|
||||
startActivity(intent)
|
||||
val dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.create_dish_modal_dialog, null)
|
||||
|
||||
val dialog = android.app.AlertDialog.Builder(requireContext())
|
||||
.setView(dialogView)
|
||||
.setCancelable(true) // tap outside to dismiss
|
||||
.create()
|
||||
|
||||
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
|
||||
|
||||
dialogView.findViewById<Button>(R.id.createManualBtn).setOnClickListener {
|
||||
val intent = Intent(requireContext(), CreateDishActivity::class.java)
|
||||
startActivity(intent)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
dialogView.findViewById<Button>(R.id.createAIBtn).setOnClickListener {
|
||||
val intent = Intent(requireContext(), CreateDishAIActivity::class.java)
|
||||
startActivity(intent)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
|
||||
context?.let { context ->
|
||||
binding.dishesList.setOnItemClickListener { parent, view, position, id ->
|
||||
val selectedItem = parent.getItemAtPosition(position) as Dish
|
||||
|
4
app/app/src/main/res/drawable/rounded_background.xml
Normal file
4
app/app/src/main/res/drawable/rounded_background.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<solid android:color="@android:color/white" />
|
||||
<corners android:radius="16dp" />
|
||||
</shape>
|
14
app/app/src/main/res/layout/create_dish_ai_form.xml
Normal file
14
app/app/src/main/res/layout/create_dish_ai_form.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/formforai"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="FormForAI"
|
||||
tools:layout_editor_absoluteX="126dp"
|
||||
tools:layout_editor_absoluteY="287dp" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
29
app/app/src/main/res/layout/create_dish_modal_dialog.xml
Normal file
29
app/app/src/main/res/layout/create_dish_modal_dialog.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_root"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="400dp"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/rounded_background"
|
||||
android:padding="0dp"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/createManualBtn"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:text="Top Button" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="#CCCCCC" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/createAIBtn"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:text="Bottom Button" />
|
||||
</LinearLayout>
|
@ -20,4 +20,5 @@
|
||||
android:id="@+id/expense"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
6
app/app/src/main/res/xml/network_security_config.xml
Normal file
6
app/app/src/main/res/xml/network_security_config.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">localhost</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
Loading…
Reference in New Issue
Block a user