Skip to content
Snippets Groups Projects
Commit 3f5a9ec3 authored by Fabio Heyming's avatar Fabio Heyming
Browse files

Added Orders to Supplier

git push
parent 9c3ba25f
Branches
No related tags found
1 merge request!1Mal aufn Master megren
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);
}
}
}
...@@ -9,12 +9,16 @@ import android.os.Bundle; ...@@ -9,12 +9,16 @@ import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
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 com.example.mampfmobil.R; 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 { public class SupplierOrdersFragment extends Fragment {
...@@ -28,6 +32,9 @@ public class SupplierOrdersFragment extends Fragment { ...@@ -28,6 +32,9 @@ public class SupplierOrdersFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @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(); AppCompatActivity activity = (AppCompatActivity) requireActivity();
// Enable the back button in the ActionBar // Enable the back button in the ActionBar
...@@ -36,7 +43,13 @@ public class SupplierOrdersFragment extends Fragment { ...@@ -36,7 +43,13 @@ public class SupplierOrdersFragment extends Fragment {
actionBar.setDisplayHomeAsUpEnabled(true); 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 @Override
......
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout 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_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_width="match_parent"
android:layout_height="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 </androidx.recyclerview.widget.RecyclerView>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello" />
</FrameLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file \ No newline at end of file
<?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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment