Skip to content
Snippets Groups Projects
DecideFragment.java 6.42 KiB
Newer Older
  • Learn to ignore specific revisions
  • Fabio Heyming's avatar
    Fabio Heyming committed
    package com.example.mampfmobil.ui;
    
    
    fheyming's avatar
    fheyming committed
    import androidx.appcompat.app.AppCompatDelegate;
    
    fheyming's avatar
    fheyming committed
    import androidx.fragment.app.FragmentManager;
    import androidx.fragment.app.FragmentTransaction;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import androidx.lifecycle.ViewModelProvider;
    
    import android.content.Intent;
    
    fheyming's avatar
    fheyming committed
    import android.content.res.Configuration;
    import android.content.res.Resources;
    
    fheyming's avatar
    fheyming committed
    import android.os.Build;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import android.os.Bundle;
    
    import androidx.annotation.Nullable;
    import androidx.fragment.app.Fragment;
    
    
    fheyming's avatar
    fheyming committed
    import android.util.Log;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;
    
    fheyming's avatar
    fheyming committed
    import android.widget.ImageButton;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
    import com.example.mampfmobil.R;
    
    fheyming's avatar
    fheyming committed
    import com.example.mampfmobil.ui.customer.CustomerLogonFragment;
    
    fheyming's avatar
    fheyming committed
    import com.example.mampfmobil.ui.customer.CustomerRegisterFragment;
    
    import com.example.mampfmobil.ui.deliverer.DelivererLogonFragment;
    import com.example.mampfmobil.ui.deliverer.DelivererRegisterFragment;
    import com.example.mampfmobil.ui.supplier.SupplierLogonFragment;
    import com.example.mampfmobil.ui.supplier.SupplierRegisterFragment;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
    
    fheyming's avatar
    fheyming committed
    import java.util.Locale;
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    public class DecideFragment extends Fragment {
    
        private DecideViewModel mViewModel;
    
        public static DecideFragment newInstance() {
            return new DecideFragment();
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_decide, container, false);
    
    
    fheyming's avatar
    fheyming committed
            ImageButton deButton = rootView.findViewById(R.id.imageView);
            ImageButton enButton = rootView.findViewById(R.id.imageView2);
    
    fheyming's avatar
    fheyming committed
            ImageButton darkMode = rootView.findViewById(R.id.imageButton);
    
            darkMode.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Den Dark Mode programmgesteuert aktivieren
                    setDarkMode(true);
                }
            });
    
            ImageButton lightMode = rootView.findViewById(R.id.imageButton2);
    
            lightMode.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Den Dark Mode programmgesteuert aktivieren
                    setDarkMode(false);
                }
            });
    
    
    fheyming's avatar
    fheyming committed
    
            deButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setLocale("de"); // Aufruf der Funktion zum Ändern der Sprache auf Deutsch
                }
            });
    
            enButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setLocale("en"); // Aufruf der Funktion zum Ändern der Sprache auf Englisch
                }
            });
    
    
    fheyming's avatar
    fheyming committed
            Button button = rootView.findViewById(R.id.CustomerButton);
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
    fheyming's avatar
    fheyming committed
                    FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    
    fheyming's avatar
    fheyming committed
                    fragmentTransaction.replace(R.id.container, new CustomerLogonFragment());
    
    fheyming's avatar
    fheyming committed
                    fragmentTransaction.addToBackStack(null); // Fügt den Fragment-Wechsel zur Back-Stack hinzu
                    fragmentTransaction.commit();
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                }
            });
    
    
    fheyming's avatar
    fheyming committed
            Button button2 = rootView.findViewById(R.id.SupplierButton);
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            button2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    
    fheyming's avatar
    fheyming committed
                    fragmentTransaction.replace(R.id.container, new SupplierLogonFragment());
    
                    fragmentTransaction.addToBackStack(null); // Fügt den Fragment-Wechsel zur Back-Stack hinzu
                    fragmentTransaction.commit();
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                }
            });
    
    
    fheyming's avatar
    fheyming committed
    
            Button button3 = rootView.findViewById(R.id.DelivererButton);
    
            button3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    
    fheyming's avatar
    fheyming committed
                    fragmentTransaction.replace(R.id.container, new DelivererLogonFragment());
    
                    fragmentTransaction.addToBackStack(null); // Fügt den Fragment-Wechsel zur Back-Stack hinzu
                    fragmentTransaction.commit();
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            return rootView;
        }
    
    
    fheyming's avatar
    fheyming committed
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        @Override
        public void onActivityCreated(@Nullable Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            mViewModel = new ViewModelProvider(this).get(DecideViewModel.class);
            // TODO: Use the ViewModel
        }
    
    
    fheyming's avatar
    fheyming committed
        private void setLocale(String languageCode) {
            Locale locale = new Locale(languageCode);
            Resources resources = getResources();
            Configuration configuration = resources.getConfiguration();
            configuration.setLocale(locale);
            resources.updateConfiguration(configuration, resources.getDisplayMetrics());
    
    
    fheyming's avatar
    fheyming committed
            recreateActivity(); // Aktivität neu starten, um die Änderungen anzuwenden
        }
    
        private void setDarkMode(boolean enabled) {
    
            if (enabled) {
    
                Log.d("myTag", "YES");
                // Dark Mode aktivieren
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
            } else {
                Log.d("myTag", "NO ");
                // Dark Mode deaktivieren
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
            }
    
            recreateActivity(); // Aktivität neu starten, um den Dark Mode anzuwenden
    
        }
    
        private void recreateActivity() {
            // Aktivität neu starten
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                requireActivity().recreate();
            } else {
                Intent intent = requireActivity().getIntent();
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                requireActivity().finish();
                requireActivity().overridePendingTransition(0, 0);
                startActivity(intent);
                requireActivity().overridePendingTransition(0, 0);
            }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    }