Newer
Older
import com.example.mampfmobil.MainActivity;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.example.mampfmobil.databinding.ActivityCustomerBinding;
import com.example.mampfmobil.databinding.ActivityDelivererBinding;
import com.example.mampfmobil.ui.Classes.ShopItem;
import com.example.mampfmobil.ui.Classes.Supplier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public static ArrayList<ShopItem> shopItemList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityCustomerBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_shop, R.id.navigation_shopping_cart, R.id.navigation_orders)
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_customer);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(binding.navView1, navController);
// Enable the back button in the ActionBar
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onSupportNavigateUp() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
return true; // true zurückgeben, um anzugeben, dass die Aktion behandelt wurde
}
public static void setupShop(){
shopItemList.clear();
Vector<Supplier> suppliers = MampfMobil.suppliers;
for(ShopItem si:MampfMobil.currentCustomer.favoriten){
shopItemList.add(si);
}
for(Supplier s: suppliers){
for(ShopItem si: s.shopItems){
if(!shopItemList.contains(si)){
shopItemList.add(si);
}
public static void setupShop(String inputString){
shopItemList.clear();
Vector<Supplier> suppliers = MampfMobil.suppliers;
for(ShopItem si:MampfMobil.currentCustomer.favoriten){
if(si.item.name.contains(inputString)){
shopItemList.add(si);
}
}
for(Supplier s: suppliers){
for(ShopItem si: s.shopItems){
if(si.item.name.contains(inputString) && !shopItemList.contains(si)){
public static void setupShop(Supplier supplier){
shopItemList.clear();
Vector<Supplier> suppliers = MampfMobil.suppliers;
for(ShopItem si:MampfMobil.currentCustomer.favoriten){
if(si.item.supplier == supplier){
shopItemList.add(si);
}
}
for(Supplier s: suppliers){
for(ShopItem si: s.shopItems){
if(si.item.supplier == supplier && !shopItemList.contains(si)){
shopItemList.add(si);
}
}
}
public static void sortShop(String inputString, Context context) {
if (inputString.equals(context.getString(R.string.price))) {
Collections.sort(shopItemList, new Comparator<ShopItem>() {
@Override
public int compare(ShopItem item1, ShopItem item2) {
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>() {
@Override
public int compare(ShopItem item1, ShopItem item2) {
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);
protected void onStop() {
Log.d("myTag", "SAVED PERSISTANT");
MampfMobil.savePersistant();
super.onStop();