Skip to content
Snippets Groups Projects
CustomerActivity.java 4.33 KiB
Newer Older
  • Learn to ignore specific revisions
  • Fabio Heyming's avatar
    Fabio Heyming committed
    package com.example.mampfmobil.ui;
    
    
    import android.content.Intent;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import android.os.Bundle;
    
    fheyming's avatar
    fheyming committed
    import android.util.Log;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
    
    import com.example.mampfmobil.MainActivity;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import com.example.mampfmobil.R;
    
    fheyming's avatar
    fheyming committed
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import androidx.appcompat.app.ActionBar;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.navigation.NavController;
    import androidx.navigation.Navigation;
    
    fheyming's avatar
    fheyming committed
    import androidx.navigation.fragment.NavHostFragment;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import androidx.navigation.ui.AppBarConfiguration;
    import androidx.navigation.ui.NavigationUI;
    
    fheyming's avatar
    fheyming committed
    import com.example.mampfmobil.databinding.ActivityCustomerBinding;
    
    import com.example.mampfmobil.databinding.ActivityDelivererBinding;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import com.example.mampfmobil.ui.Classes.ShopItem;
    import com.example.mampfmobil.ui.Classes.Supplier;
    
    import java.util.ArrayList;
    import java.util.Vector;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
    
    fheyming's avatar
    fheyming committed
    public class CustomerActivity extends AppCompatActivity {
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
    
    fheyming's avatar
    fheyming committed
    private ActivityCustomerBinding binding;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        public static ArrayList<ShopItem> shopItemList = new ArrayList<>();
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            Log.d("myTag", "This is my Costumer");
    
    fheyming's avatar
    fheyming committed
            binding = ActivityCustomerBinding.inflate(getLayoutInflater());
            setContentView(binding.getRoot());
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            // Enable the back button in the ActionBar
    
            AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                    R.id.navigation_shop, R.id.navigation_shopping_cart, R.id.navigation_orders)
    
    fheyming's avatar
    fheyming committed
            NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_customer);
    
            NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
            NavigationUI.setupWithNavController(binding.navView1, navController);
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            // Enable the back button in the ActionBar
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.setDisplayHomeAsUpEnabled(true);
            }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        }
    
    
        @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
        }
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        public static void setupShop(){
            shopItemList.clear();
            Vector<Supplier> suppliers = MampfMobil.suppliers;
    
            for(ShopItem si:MampfMobil.currentCustomer.favoriten){
                shopItemList.add(si);
            }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
            for(Supplier s: suppliers){
                for(ShopItem si: s.shopItems){
    
                    if(!shopItemList.contains(si)){
                        shopItemList.add(si);
                    }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                }
            }
    
            Log.d("myTag", "SI no search ");
            for(ShopItem sI: shopItemList){
                Log.d("myTag", "SI no search "+ sI.item.name);
            }
            for(ShopItem si:MampfMobil.currentCustomer.favoriten){
                Log.d("myTag", "FAV "+ si.item.name);
            }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        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);
                }
            }
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            for(Supplier s: suppliers){
                for(ShopItem si: s.shopItems){
    
                    if(si.item.name.contains(inputString) && !shopItemList.contains(si)){
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                        shopItemList.add(si);
                    }
                }
            }
    
            Log.d("myTag", "SI search:  ");
            for(ShopItem sI: shopItemList){
                Log.d("myTag", "SI search:  "+ sI.item.name);
            }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        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);
                    }
                }
            }
            Log.d("myTag", "SI search:  ");
            for(ShopItem sI: shopItemList){
                Log.d("myTag", "SI search:  "+ sI.item.name);
            }
        }
    
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    }