Skip to content
Snippets Groups Projects
DecideFragment.java 5.04 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.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;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import android.os.Bundle;
    
    import androidx.annotation.Nullable;
    import androidx.fragment.app.Fragment;
    
    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);
    
            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());
    
            // Hier müssen Sie den Fragments-Wechsel aktualisieren, um sicherzustellen,
            // dass die Ansichten und Texte entsprechend der geänderten Sprache aktualisiert werden
            FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container, new DecideFragment());
            fragmentTransaction.commit();
        }
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    }