Search in sources :

Example 1 with HomeFragment

use of com.example.flashgig.fragments.HomeFragment in project FIREBASE_TEST_JAVA by essantos8.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    replaceFragment(new HomeFragment(), "home", "LtoR");
    ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    binding.bottomNavigationView.setOnItemSelectedListener(item -> {
        Fragment curFragment = getSupportFragmentManager().findFragmentById(R.id.frameLayout);
        assert curFragment != null;
        String curFragmentTag = curFragment.getTag();
        assert curFragmentTag != null : "Set a fragment tag!";
        switch(item.getItemId()) {
            case R.id.home:
                if (!curFragmentTag.equals("home")) {
                    replaceFragment(new HomeFragment(), "home", "LtoR");
                }
                break;
            case R.id.messages:
                if (!curFragmentTag.equals("messages")) {
                    if (!curFragmentTag.equals("home")) {
                        replaceFragment(new MessagesFragment(), "messages", "LtoR");
                    } else {
                        replaceFragment(new MessagesFragment(), "messages", "RtoL");
                    }
                }
                break;
            case R.id.myJobs:
                if (!curFragmentTag.equals("myJobs")) {
                    if (!curFragmentTag.equals("profile")) {
                        replaceFragment(new MyJobsFragment(), "myJobs", "RtoL");
                    } else {
                        replaceFragment(new MyJobsFragment(), "myJobs", "LtoR");
                    }
                }
                break;
            case R.id.profile:
                if (!curFragmentTag.equals("profile")) {
                    replaceFragment(new ProfileFragment(), "profile", "RtoL");
                }
                break;
        }
        return true;
    });
}
Also used : MessagesFragment(com.example.flashgig.fragments.MessagesFragment) ProfileFragment(com.example.flashgig.fragments.ProfileFragment) HomeFragment(com.example.flashgig.fragments.HomeFragment) ActivityMainBinding(com.example.flashgig.databinding.ActivityMainBinding) DetailFragment(com.example.flashgig.fragments.DetailFragment) MessagesFragment(com.example.flashgig.fragments.MessagesFragment) ProfileFragment(com.example.flashgig.fragments.ProfileFragment) HomeFragment(com.example.flashgig.fragments.HomeFragment) MyJobsFragment(com.example.flashgig.fragments.MyJobsFragment) Fragment(androidx.fragment.app.Fragment) ProfileEditFragment(com.example.flashgig.fragments.ProfileEditFragment) JobAdderFragment(com.example.flashgig.JobAdderFragment) MyJobsFragment(com.example.flashgig.fragments.MyJobsFragment)

Aggregations

Fragment (androidx.fragment.app.Fragment)1 JobAdderFragment (com.example.flashgig.JobAdderFragment)1 ActivityMainBinding (com.example.flashgig.databinding.ActivityMainBinding)1 DetailFragment (com.example.flashgig.fragments.DetailFragment)1 HomeFragment (com.example.flashgig.fragments.HomeFragment)1 MessagesFragment (com.example.flashgig.fragments.MessagesFragment)1 MyJobsFragment (com.example.flashgig.fragments.MyJobsFragment)1 ProfileEditFragment (com.example.flashgig.fragments.ProfileEditFragment)1 ProfileFragment (com.example.flashgig.fragments.ProfileFragment)1