From 496dba1940d285c44c41b64b31a335eb471260b4 Mon Sep 17 00:00:00 2001
From: fheyming <fabio-andre.heyming@sva.de>
Date: Wed, 31 May 2023 13:59:28 +0200
Subject: [PATCH] Added Add Item

---
 .../Classes/Recyclerviewadapter_editItem.java |  6 ++
 .../ui/customer/CustomerLogonFragment.java    |  3 -
 .../ui/supplier/SupplierAddItemFragment.java  | 53 +++++++++++-
 .../res/drawable/recyclerview_edititemrow.xml |  4 +
 .../res/layout/fragment_customer_shop.xml     |  3 +-
 .../res/layout/fragment_supplier_add_item.xml | 82 +++++++++++++++++--
 6 files changed, 141 insertions(+), 10 deletions(-)
 create mode 100644 app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_editItem.java
 create mode 100644 app/src/main/res/drawable/recyclerview_edititemrow.xml

diff --git a/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_editItem.java b/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_editItem.java
new file mode 100644
index 0000000..260fec0
--- /dev/null
+++ b/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_editItem.java
@@ -0,0 +1,6 @@
+package com.example.mampfmobil.ui.Classes;
+
+import androidx.recyclerview.widget.RecyclerView;
+
+public class Recyclerviewadapter_editItem extends RecyclerView.ViewHolder<MyViewHolder> {
+}
diff --git a/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerLogonFragment.java b/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerLogonFragment.java
index 7466cb2..1208ef0 100644
--- a/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerLogonFragment.java
+++ b/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerLogonFragment.java
@@ -38,11 +38,8 @@ public class CustomerLogonFragment extends Fragment {
 
         EditText firstname = rootView.findViewById(R.id.editTextFirstName);
         EditText lastname = rootView.findViewById(R.id.editTextLastName);
-
-
         Button button = rootView.findViewById(R.id.buttonRegister);
 
-
         button.setOnClickListener(new View.OnClickListener() {
             private Toast toast; //
             @Override
diff --git a/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierAddItemFragment.java b/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierAddItemFragment.java
index 492c0a4..71c57d8 100644
--- a/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierAddItemFragment.java
+++ b/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierAddItemFragment.java
@@ -11,12 +11,19 @@ import androidx.fragment.app.Fragment;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
 
 import com.example.mampfmobil.R;
+import com.example.mampfmobil.ui.Classes.ShopItem;
+import com.example.mampfmobil.ui.MampfMobil;
 
 public class SupplierAddItemFragment extends Fragment {
 
     private SupplierAddItemViewModel mViewModel;
+    private Toast toast;
+    private boolean exists = false;
 
     public static SupplierAddItemFragment newInstance() {
         return new SupplierAddItemFragment();
@@ -25,7 +32,51 @@ public class SupplierAddItemFragment extends Fragment {
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                              @Nullable Bundle savedInstanceState) {
-        return inflater.inflate(R.layout.fragment_supplier_add_item, container, false);
+        View rootView = inflater.inflate(R.layout.fragment_supplier_add_item, container, false);
+
+        Button button = rootView.findViewById(R.id.buttonAddnewitem);
+        EditText etName = rootView.findViewById(R.id.editTextItemName);
+        EditText etAmount = rootView.findViewById(R.id.editTextItemAmount);
+        EditText etPrice = rootView.findViewById(R.id.editTextTextItemPrice);
+
+
+        button.setOnClickListener(new View.OnClickListener() {
+
+            @Override
+            public void onClick(View view) {
+
+                if(etName.getText().toString().equals("") || etPrice.getText().toString().equals("") || etAmount.getText().toString().equals("")){
+                    if (toast != null) {
+                        toast.cancel(); // Vorhandene Toast-Nachricht abbrechen
+                    }
+                    toast = Toast.makeText(rootView.getContext(), "noEmptyInput", Toast.LENGTH_SHORT);
+                    toast.show();
+                    return;
+                }
+                exists = false;
+                for(ShopItem sI: MampfMobil.currentSupplier.shopItems){
+
+                    if(sI.item.name.equals(etName.getText().toString())){
+                        exists = true;
+                    }
+                }
+                if(exists){
+                    if (toast != null) {
+                        toast.cancel(); // Vorhandene Toast-Nachricht abbrechen
+                    }
+                    toast = Toast.makeText(rootView.getContext(), "Item already exists", Toast.LENGTH_SHORT);
+                    toast.show();
+                }
+                else{
+                    MampfMobil.currentSupplier.itemAdd(etName.getText().toString(), Integer.parseInt(etAmount.getText().toString()),Double.parseDouble(etPrice.getText().toString()));
+                }
+
+            }
+        });
+
+
+
+        return rootView;
     }
 
     @Override
diff --git a/app/src/main/res/drawable/recyclerview_edititemrow.xml b/app/src/main/res/drawable/recyclerview_edititemrow.xml
new file mode 100644
index 0000000..a8b409b
--- /dev/null
+++ b/app/src/main/res/drawable/recyclerview_edititemrow.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+</selector>
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_customer_shop.xml b/app/src/main/res/layout/fragment_customer_shop.xml
index 35d6997..215568c 100644
--- a/app/src/main/res/layout/fragment_customer_shop.xml
+++ b/app/src/main/res/layout/fragment_customer_shop.xml
@@ -38,8 +38,9 @@
         android:id="@+id/searchButton"
         android:layout_width="105dp"
         android:layout_height="38dp"
+        android:layout_marginTop="4dp"
         android:text="@android:string/search_go"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toEndOf="@+id/editTextSearch"
-        tools:layout_editor_absoluteY="4dp" />
+        app:layout_constraintTop_toTopOf="parent" />
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_supplier_add_item.xml b/app/src/main/res/layout/fragment_supplier_add_item.xml
index 55ec04a..d0a4281 100644
--- a/app/src/main/res/layout/fragment_supplier_add_item.xml
+++ b/app/src/main/res/layout/fragment_supplier_add_item.xml
@@ -1,13 +1,85 @@
 <?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".ui.supplier.SupplierAddItemFragment">
 
+    <EditText
+        android:id="@+id/editTextItemName"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="30dp"
+        android:ems="10"
+        android:inputType="text"
+        android:hint="Name"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/textView9" />
+
+    <EditText
+        android:id="@+id/editTextTextItemPrice"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="30dp"
+        android:ems="10"
+        android:inputType="numberDecimal"
+        android:hint="Price"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintHorizontal_bias="0.497"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/textView12" />
+
+    <EditText
+        android:id="@+id/editTextItemAmount"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="30dp"
+        android:ems="10"
+        android:inputType="number"
+        android:hint="Amount"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/textView13" />
+
+    <TextView
+        android:id="@+id/textView9"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="64dp"
+        android:text="Itemname:"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <TextView
+        android:id="@+id/textView12"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="60dp"
+        android:text="@string/price_dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/editTextItemName" />
+
     <TextView
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:text="THIS IS THE ADD ITEM FRAGMENT" />
+        android:id="@+id/textView13"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="60dp"
+        android:text="Amount:"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/editTextTextItemPrice" />
 
-</FrameLayout>
\ No newline at end of file
+    <Button
+        android:id="@+id/buttonAddnewitem"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="50dp"
+        android:text="@string/add"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/editTextItemAmount" />
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
-- 
GitLab