From 277aff65ef1b0a4dc28c72544df185fe93a849b4 Mon Sep 17 00:00:00 2001 From: Fabio Heyming <fabio.heyming@web.de> Date: Thu, 22 Jun 2023 23:25:52 +0200 Subject: [PATCH] BUGFIXING LIKE HELL --- .../ui/Classes/Recyclerviewadapter_Shop.java | 4 ++ .../mampfmobil/ui/CustomerActivity.java | 55 +++++++++++++++++++ .../ui/customer/CustomerShopFragment.java | 2 + .../res/layout/recyclerview_edititemrow.xml | 2 +- app/src/main/res/values-de-rDE/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 6 files changed, 64 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_Shop.java b/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_Shop.java index 6c23b77..2892b4d 100644 --- a/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_Shop.java +++ b/app/src/main/java/com/example/mampfmobil/ui/Classes/Recyclerviewadapter_Shop.java @@ -32,7 +32,11 @@ public class Recyclerviewadapter_Shop extends RecyclerView.Adapter<Recyclerviewa public Recyclerviewadapter_Shop(Context context, ArrayList<ShopItem> shopItemList){ this.context = context; + CustomerActivity.setupShop(); this.shopItemList = shopItemList; + for(ShopItem sI:shopItemList){ + Log.d("myTag", sI.item.name); + } } diff --git a/app/src/main/java/com/example/mampfmobil/ui/CustomerActivity.java b/app/src/main/java/com/example/mampfmobil/ui/CustomerActivity.java index 9ede233..08f6318 100644 --- a/app/src/main/java/com/example/mampfmobil/ui/CustomerActivity.java +++ b/app/src/main/java/com/example/mampfmobil/ui/CustomerActivity.java @@ -132,6 +132,24 @@ private ActivityCustomerBinding binding; return Double.compare(item1.item.price, item2.item.price); } }); + ArrayList<ShopItem> rearrangedList = new ArrayList<>(); + for(ShopItem sI : shopItemList){ + boolean fav = false; + for (ShopItem favorit : MampfMobil.currentCustomer.favoriten) { + if (sI == favorit) { + fav = true; + break; // Exit the inner loop since a match is found + } + } + + if (fav) { + rearrangedList.add(0, sI); // Add the item to the beginning of the rearrangedList + } else { + rearrangedList.add(sI); // Add the item to the end of the rearrangedList + } + } + shopItemList.clear(); + shopItemList.addAll(rearrangedList); } if (inputString.equals(context.getString(R.string.restamount))) { Collections.sort(shopItemList, new Comparator<ShopItem>() { @@ -140,14 +158,51 @@ private ActivityCustomerBinding binding; return Double.compare( item2.quantity,item1.quantity); } }); + ArrayList<ShopItem> rearrangedList = new ArrayList<>(); + for(ShopItem sI : shopItemList){ + boolean fav = false; + for (ShopItem favorit : MampfMobil.currentCustomer.favoriten) { + if (sI == favorit) { + fav = true; + break; // Exit the inner loop since a match is found + } + } + + if (fav) { + rearrangedList.add(0, sI); // Add the item to the beginning of the rearrangedList + } else { + rearrangedList.add(sI); // Add the item to the end of the rearrangedList + } + } + shopItemList.clear(); + shopItemList.addAll(rearrangedList); } if (inputString.equals(context.getString(R.string.name))) { + Collections.sort(shopItemList, new Comparator<ShopItem>() { @Override public int compare(ShopItem item1, ShopItem item2) { return item1.item.name.compareTo(item2.item.name); } }); + ArrayList<ShopItem> rearrangedList = new ArrayList<>(); + for(ShopItem sI : shopItemList){ + boolean fav = false; + for (ShopItem favorit : MampfMobil.currentCustomer.favoriten) { + if (sI == favorit) { + fav = true; + break; // Exit the inner loop since a match is found + } + } + + if (fav) { + rearrangedList.add(0, sI); // Add the item to the beginning of the rearrangedList + } else { + rearrangedList.add(sI); // Add the item to the end of the rearrangedList + } + } + shopItemList.clear(); + shopItemList.addAll(rearrangedList); } } diff --git a/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerShopFragment.java b/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerShopFragment.java index 9e6e4c2..51bd6f4 100644 --- a/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerShopFragment.java +++ b/app/src/main/java/com/example/mampfmobil/ui/customer/CustomerShopFragment.java @@ -100,6 +100,8 @@ public class CustomerShopFragment extends Fragment { actionBar.setDisplayHomeAsUpEnabled(true); } + CustomerActivity.setupShop(); + adapter.notifyDataSetChanged(); // Return the inflated rootView return rootView; } diff --git a/app/src/main/res/layout/recyclerview_edititemrow.xml b/app/src/main/res/layout/recyclerview_edititemrow.xml index 12a8112..30d4131 100644 --- a/app/src/main/res/layout/recyclerview_edititemrow.xml +++ b/app/src/main/res/layout/recyclerview_edititemrow.xml @@ -54,7 +54,7 @@ android:id="@+id/buttonEdit" android:layout_width="93dp" android:layout_height="41dp" - android:layout_marginEnd="16dp" + android:layout_marginEnd="4dp" android:text="@string/edit" android:textSize="14sp" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 332ffe8..a8afed9 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -61,7 +61,7 @@ <string name="supplieraddress_dp">Lieferantenadresse:</string> <string name="edit">edit</string> <string name="total">Gesamt</string> - <string name="sold_units_dp">Verkaufte Items:</string> + <string name="sold_units_dp">Verkäufe:</string> <string name="noemptyinput">Keine leere eingaben</string> <string name="item_already_exists">Item existiert bereits</string> <string name="added_to_shopping_cart">Zum Einkaufswagen hinzugefügt</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 90f7c42..cbef021 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,7 +58,7 @@ <string name="edit">EDIT</string> <string name="sum_dp">Sum:</string> <string name="total">Total</string> - <string name="sold_units_dp">Sold Units:</string> + <string name="sold_units_dp">Sales:</string> <string name="reserve">reserve</string> <string name="ordered">ordered</string> <string name="noemptyinput">noEmptyInput</string> -- GitLab