Skip to main content
se añadieron 1335 caracteres en el cuerpo
Origen Enlace
johnnnn
  • 197
  • 8

Actualizado

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
            mDrawer.closeDrawer(GravityCompat.START);
        }
        super.onBackPressed();

        boolean disableBack = (getSupportFragmentManager().getFragments().size() > 1);
        if (disableBack) {
            Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_home_tab_layout);
            if (fragment instanceof HomeTabLayoutFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_home);
            } else if (fragment instanceof SearchFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_search);
            } else if (fragment instanceof AttendingEventFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_save);
            } else if (fragment instanceof NotificationsFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_notifications);
            } else if (fragment instanceof ProfileFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_profile);
            }
        } else {
            super.onBackPressed();
        }
    }

Actualizado

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
            mDrawer.closeDrawer(GravityCompat.START);
        }
        super.onBackPressed();

        boolean disableBack = (getSupportFragmentManager().getFragments().size() > 1);
        if (disableBack) {
            Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_home_tab_layout);
            if (fragment instanceof HomeTabLayoutFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_home);
            } else if (fragment instanceof SearchFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_search);
            } else if (fragment instanceof AttendingEventFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_save);
            } else if (fragment instanceof NotificationsFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_notifications);
            } else if (fragment instanceof ProfileFragment) {
                mBottomNavigationView.setSelectedItemId(R.id.nav_profile);
            }
        } else {
            super.onBackPressed();
        }
    }
se añadieron 817 caracteres en el cuerpo
Origen Enlace
johnnnn
  • 197
  • 8

Podria hacerlo asi?

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
            mDrawer.closeDrawer(GravityCompat.START);
        }

        super.onBackPressed();

        if (mSelectedFragment.equals(new HomeTabLayoutFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_home);
        } else if (mSelectedFragment.equals(new SearchFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_search);
        } else if (mSelectedFragment.equals(new AttendingEventFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_save);
        } else if (mSelectedFragment.equals(new NotificationsFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_notifications);
        } else if (mSelectedFragment.equals(new ProfileFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_profile);
        } else {
            super.onBackPressed();
        }

Podria hacerlo asi?

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
            mDrawer.closeDrawer(GravityCompat.START);
        }

        super.onBackPressed();

        if (mSelectedFragment.equals(new HomeTabLayoutFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_home);
        } else if (mSelectedFragment.equals(new SearchFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_search);
        } else if (mSelectedFragment.equals(new AttendingEventFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_save);
        } else if (mSelectedFragment.equals(new NotificationsFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_notifications);
        } else if (mSelectedFragment.equals(new ProfileFragment())) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_profile);
        } else {
            super.onBackPressed();
        }
se añadieron 817 caracteres en el cuerpo
Origen Enlace
johnnnn
  • 197
  • 8
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener = menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.nav_home:
                mSelectedFragment = new HomeBNVFragment();
                break;
            case R.id.nav_search:
                mSelectedFragment = new SearchFragment();
                break;
            case R.id.nav_notifications:
                seenNotification();
                mSelectedFragment = new NotificationsFragment();
                break;
            case R.id.nav_profile:
                SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();
                editor.putString("profileid", Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid());
                editor.apply();
                mSelectedFragment = new ProfileFragment();
                break;
            case R.id.nav_save:
                mSelectedFragment = new AttendingEventFragment();
                break;
        }

        if (mSelectedFragment != null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mSelectedFragment, null).addToBackStack(null).commit();
        }

        return true;
    };

@Override
public void onBackPressed() {
        if (mDrawer.isDrawerOpen(GravityCompat.START)) {
            mDrawer.closeDrawer(GravityCompat.START);
        }
        super.onBackPressed();

        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_home_tab_layout);
        if (fragment instanceof HomeTabLayoutFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_home);
        } else if (fragment instanceof SearchFragment) {
            mDrawermBottomNavigationView.closeDrawersetSelectedItemId(GravityCompatR.STARTid.nav_search);
        } else if (fragment instanceof AttendingEventFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_save);
        } else if (fragment instanceof NotificationsFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_notifications);
        } else if (fragment instanceof ProfileFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_profile);
        } else {
            super.onBackPressed();
        }
    }
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener = menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.nav_home:
                mSelectedFragment = new HomeBNVFragment();
                break;
            case R.id.nav_search:
                mSelectedFragment = new SearchFragment();
                break;
            case R.id.nav_notifications:
                seenNotification();
                mSelectedFragment = new NotificationsFragment();
                break;
            case R.id.nav_profile:
                SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();
                editor.putString("profileid", Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid());
                editor.apply();
                mSelectedFragment = new ProfileFragment();
                break;
            case R.id.nav_save:
                mSelectedFragment = new AttendingEventFragment();
                break;
        }

        if (mSelectedFragment != null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mSelectedFragment, null).addToBackStack(null).commit();
        }

        return true;
    };

@Override
public void onBackPressed() {
        if (mDrawer.isDrawerOpen(GravityCompat.START)) {
            mDrawer.closeDrawer(GravityCompat.START);
        } else {
            mDrawer.closeDrawer(GravityCompat.START);
        }
        super.onBackPressed();
    }
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener = menuItem -> {
        switch (menuItem.getItemId()) {
            case R.id.nav_home:
                mSelectedFragment = new HomeBNVFragment();
                break;
            case R.id.nav_search:
                mSelectedFragment = new SearchFragment();
                break;
            case R.id.nav_notifications:
                seenNotification();
                mSelectedFragment = new NotificationsFragment();
                break;
            case R.id.nav_profile:
                SharedPreferences.Editor editor = getSharedPreferences("PREFS", MODE_PRIVATE).edit();
                editor.putString("profileid", Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid());
                editor.apply();
                mSelectedFragment = new ProfileFragment();
                break;
            case R.id.nav_save:
                mSelectedFragment = new AttendingEventFragment();
                break;
        }

        if (mSelectedFragment != null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mSelectedFragment, null).addToBackStack(null).commit();
        }

        return true;
    };

@Override
public void onBackPressed() {
        if (mDrawer.isDrawerOpen(GravityCompat.START)) {
            mDrawer.closeDrawer(GravityCompat.START);
        }
        super.onBackPressed();

        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_home_tab_layout);
        if (fragment instanceof HomeTabLayoutFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_home);
        } else if (fragment instanceof SearchFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_search);
        } else if (fragment instanceof AttendingEventFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_save);
        } else if (fragment instanceof NotificationsFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_notifications);
        } else if (fragment instanceof ProfileFragment) {
            mBottomNavigationView.setSelectedItemId(R.id.nav_profile);
        } else {
            super.onBackPressed();
        }
    }
se añadieron 18 caracteres en el cuerpo
Origen Enlace
johnnnn
  • 197
  • 8
Loading
Origen Enlace
johnnnn
  • 197
  • 8
Loading