diff --git a/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_Supplier_Orders.java b/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_Supplier_Orders.java new file mode 100644 index 0000000000000000000000000000000000000000..835037ead1219dd2abb018a8fd6ccfe6c5ed79c8 --- /dev/null +++ b/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_Supplier_Orders.java @@ -0,0 +1,115 @@ +package com.example.mampfmobil.ui.Classes; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.mampfmobil.R; +import com.example.mampfmobil.ui.MampfMobil; + +import java.util.Vector; + +public class Recyclerviewadapter_Supplier_Orders extends RecyclerView.Adapter<Recyclerviewadapter_Supplier_Orders.MyViewHolder>{ + + + Context context; + Vector<Bestellung> bestellungen = new Vector<>(); + + public Recyclerviewadapter_Supplier_Orders(Context context){ + this.context =context; + for(Customer c:MampfMobil.customers){ + for(Bestellung b:c.bestellungen){ + if(b.supplier==MampfMobil.currentSupplier){ + bestellungen.add(b); + } + } + } + } + @NonNull + @Override + public Recyclerviewadapter_Supplier_Orders.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + LayoutInflater inflator = LayoutInflater.from(context); + View view = inflator.inflate(R.layout.recyclerview_supplierordersrow,parent,false); + + return new Recyclerviewadapter_Supplier_Orders.MyViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull Recyclerviewadapter_Supplier_Orders.MyViewHolder holder, int position) { + holder.tvID.setText(String.valueOf("# " + bestellungen.get(position).id)); + holder.tvState.setText(bestellungen.get(position).state); + if(bestellungen.get(position).state.equals("ordered")){ + holder.readyButton.setText("ready"); + } + else if(bestellungen.get(position).state.equals("ready")){ + holder.readyButton.setText("picked"); + } + else{ + holder.readyButton.setVisibility(View.INVISIBLE); + } + + double temp = 0; + for(BestellungsTeil bt:bestellungen.get(position).bestellungsTeile){ + temp = temp + bt.item.price * bt.quantity; + } + holder.tvTotalCost.setText(String.valueOf(temp)); + + if(bestellungen.get(position).delivery){ + holder.tvDelivery.setText("DELIVERY"); + } + else{ + holder.tvDelivery.setText("PICKUP"); + } + + // Initialisiere und konfiguriere den Recyclerviewadapter_Orders_Parts + Recyclerviewadapter_Orders_Parts ordersPartsAdapter = new Recyclerviewadapter_Orders_Parts(context, bestellungen.get(position).bestellungsTeile); + LinearLayoutManager layoutManager = new LinearLayoutManager(context); + holder.recyclerViewOrders.setLayoutManager(layoutManager); + holder.recyclerViewOrders.setAdapter(ordersPartsAdapter); + + + holder.readyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (bestellungen.get(position).state.equals("ready")) { + bestellungen.get(position).state = "picked"; + notifyItemRangeChanged(position, getItemCount()); + } + if (bestellungen.get(position).state.equals("ordered")) { + bestellungen.get(position).state = "ready"; + notifyItemRangeChanged(position, getItemCount()); + } + } + }); + + } + + @Override + public int getItemCount() { + return bestellungen.size(); + } + + public static class MyViewHolder extends RecyclerView.ViewHolder { + + TextView tvID, tvDelivery,tvState,tvTotalCost; + RecyclerView recyclerViewOrders; + Button readyButton; + public MyViewHolder(@NonNull View itemView) { + super(itemView); + + tvID = itemView.findViewById(R.id.textViewID);; + tvState = itemView.findViewById(R.id.textViewState); + tvDelivery = itemView.findViewById(R.id.textViewDelivery); + recyclerViewOrders =itemView.findViewById(R.id.recyclerViewOrders); + tvTotalCost =itemView.findViewById(R.id.textViewTotalCost); + readyButton = itemView.findViewById(R.id.buttonReady); + } + } +} diff --git a/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierOrdersFragment.java b/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierOrdersFragment.java index 2cb391af8cb2b0b8c2aebb9e9d7c137e7249899d..3493a1a90ac9580c5fbe5faa7c462bf06d900fad 100644 --- a/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierOrdersFragment.java +++ b/app/src/main/java/com/example/mampfmobil/ui/supplier/SupplierOrdersFragment.java @@ -9,12 +9,16 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.mampfmobil.R; +import com.example.mampfmobil.ui.Classes.Recyclerviewadapter_Orders; +import com.example.mampfmobil.ui.Classes.Recyclerviewadapter_Supplier_Orders; public class SupplierOrdersFragment extends Fragment { @@ -28,6 +32,9 @@ public class SupplierOrdersFragment extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_supplier_orders, container, false); + + RecyclerView recyclerView = rootView.findViewById(R.id.mySupplierOrdersRecycler); AppCompatActivity activity = (AppCompatActivity) requireActivity(); // Enable the back button in the ActionBar @@ -36,7 +43,13 @@ public class SupplierOrdersFragment extends Fragment { actionBar.setDisplayHomeAsUpEnabled(true); } - return inflater.inflate(R.layout.fragment_supplier_orders, container, false); + LinearLayoutManager layoutManager = new LinearLayoutManager(requireActivity()); + recyclerView.setLayoutManager(layoutManager); + Recyclerviewadapter_Supplier_Orders adapter = new Recyclerviewadapter_Supplier_Orders(requireContext()); + recyclerView.setAdapter(adapter); + adapter.notifyDataSetChanged(); + + return rootView; } @Override diff --git a/app/src/main/res/layout/fragment_supplier_orders.xml b/app/src/main/res/layout/fragment_supplier_orders.xml index 12308370717fcd1ead1cfe4455c9b12308849c76..681772b37077878c8a854f3e70813916ece40402 100644 --- a/app/src/main/res/layout/fragment_supplier_orders.xml +++ b/app/src/main/res/layout/fragment_supplier_orders.xml @@ -1,13 +1,23 @@ -<?xml version="1.0" encoding="utf-8"?> -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" +<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" +android:paddingBottom="?attr/actionBarSize" +tools:context=".ui.supplier.SupplierOrdersFragment"> + + +<androidx.recyclerview.widget.RecyclerView + android:id="@+id/mySupplierOrdersRecycler" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.supplier.SupplierOrdersFragment"> + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.0"> - <TextView - android:layout_width="match_parent" - android:layout_height="match_parent" - android:text="Hello" /> +</androidx.recyclerview.widget.RecyclerView> -</FrameLayout> \ No newline at end of file +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/recyclerview_supplierordersrow.xml b/app/src/main/res/layout/recyclerview_supplierordersrow.xml new file mode 100644 index 0000000000000000000000000000000000000000..d74ae321bc470390da1fd4ca6019eaaaa31b8f31 --- /dev/null +++ b/app/src/main/res/layout/recyclerview_supplierordersrow.xml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="utf-8"?> +<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="wrap_content"> + + <androidx.cardview.widget.CardView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="5dp" + android:layout_marginTop="5dp" + android:layout_marginStart="5dp" + android:layout_marginEnd="5dp" + app:cardBackgroundColor="@color/cardview_light_background" + app:cardCornerRadius="20dp" + app:cardElevation="5dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" > + + <androidx.constraintlayout.widget.ConstraintLayout + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + android:id="@+id/textViewID" + android:layout_width="107dp" + android:layout_height="27dp" + android:layout_marginStart="10dp" + android:text="1" + android:textSize="20sp" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/textViewDelivery" + android:layout_width="wrap_content" + android:layout_height="25dp" + android:layout_marginStart="16dp" + android:text="delivery/pickup" + app:layout_constraintStart_toEndOf="@+id/textViewID" /> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/recyclerViewOrders" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:layout_constraintTop_toBottomOf="@+id/textView7" /> + + <TextView + android:id="@+id/textView7" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/state_dp" + app:layout_constraintStart_toStartOf="@+id/textViewID" + app:layout_constraintTop_toBottomOf="@+id/textViewID" /> + + <TextView + android:id="@+id/textViewState" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:text="Der aktuelle Status oder so" + app:layout_constraintStart_toEndOf="@+id/textView7" + app:layout_constraintTop_toBottomOf="@+id/textViewID" /> + + <TextView + android:id="@+id/textViewTotalCost" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="16dp" + android:text="13" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@+id/recyclerViewOrders" + app:layout_constraintVertical_bias="0.0" /> + + <TextView + android:id="@+id/textView11" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="24dp" + android:text="Total" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/textViewTotalCost" /> + + <Button + android:id="@+id/buttonReady" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:text="Ready" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + + </androidx.constraintlayout.widget.ConstraintLayout> + </androidx.cardview.widget.CardView> + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file