Skip to content
Snippets Groups Projects
Commit 496dba19 authored by fheyming's avatar fheyming
Browse files

Added Add Item

parent 917e0f9e
No related branches found
No related tags found
1 merge request!1Mal aufn Master megren
package com.example.mampfmobil.ui.Classes;
import androidx.recyclerview.widget.RecyclerView;
public class Recyclerviewadapter_editItem extends RecyclerView.ViewHolder<MyViewHolder> {
}
...@@ -38,11 +38,8 @@ public class CustomerLogonFragment extends Fragment { ...@@ -38,11 +38,8 @@ public class CustomerLogonFragment extends Fragment {
EditText firstname = rootView.findViewById(R.id.editTextFirstName); EditText firstname = rootView.findViewById(R.id.editTextFirstName);
EditText lastname = rootView.findViewById(R.id.editTextLastName); EditText lastname = rootView.findViewById(R.id.editTextLastName);
Button button = rootView.findViewById(R.id.buttonRegister); Button button = rootView.findViewById(R.id.buttonRegister);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
private Toast toast; // private Toast toast; //
@Override @Override
......
...@@ -11,12 +11,19 @@ import androidx.fragment.app.Fragment; ...@@ -11,12 +11,19 @@ import androidx.fragment.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.R;
import com.example.mampfmobil.ui.Classes.ShopItem;
import com.example.mampfmobil.ui.MampfMobil;
public class SupplierAddItemFragment extends Fragment { public class SupplierAddItemFragment extends Fragment {
private SupplierAddItemViewModel mViewModel; private SupplierAddItemViewModel mViewModel;
private Toast toast;
private boolean exists = false;
public static SupplierAddItemFragment newInstance() { public static SupplierAddItemFragment newInstance() {
return new SupplierAddItemFragment(); return new SupplierAddItemFragment();
...@@ -25,7 +32,51 @@ public class SupplierAddItemFragment extends Fragment { ...@@ -25,7 +32,51 @@ public class SupplierAddItemFragment extends Fragment {
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @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 @Override
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
</selector>
\ No newline at end of file
...@@ -38,8 +38,9 @@ ...@@ -38,8 +38,9 @@
android:id="@+id/searchButton" android:id="@+id/searchButton"
android:layout_width="105dp" android:layout_width="105dp"
android:layout_height="38dp" android:layout_height="38dp"
android:layout_marginTop="4dp"
android:text="@android:string/search_go" android:text="@android:string/search_go"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/editTextSearch" app:layout_constraintStart_toEndOf="@+id/editTextSearch"
tools:layout_editor_absoluteY="4dp" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.supplier.SupplierAddItemFragment"> 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 <TextView
android:layout_width="match_parent" android:id="@+id/textView13"
android:layout_height="match_parent" android:layout_width="wrap_content"
android:text="THIS IS THE ADD ITEM FRAGMENT" /> 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> <Button
\ No newline at end of file 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment