Java Code Examples for androidx.fragment.app.FragmentTransaction#setReorderingAllowed()

The following examples show how to use androidx.fragment.app.FragmentTransaction#setReorderingAllowed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentHelper.java    From AndroidNavigation with MIT License 6 votes vote down vote up
public static void addFragmentToBackStack(@NonNull FragmentManager fragmentManager, int containerId, @NonNull AwesomeFragment fragment, @NonNull PresentAnimation animation) {
    if (fragmentManager.isDestroyed()) {
        return;
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.setReorderingAllowed(true);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    AwesomeFragment topFragment = (AwesomeFragment) fragmentManager.findFragmentById(containerId);
    if (topFragment != null && topFragment.isAdded()) {
        topFragment.setAnimation(animation);
        transaction.setMaxLifecycle(topFragment, Lifecycle.State.STARTED);
        transaction.hide(topFragment);
    }
    fragment.setAnimation(animation);

    transaction.add(containerId, fragment, fragment.getSceneId());
    transaction.addToBackStack(fragment.getSceneId());
    transaction.commit();
    executePendingTransactionsSafe(fragmentManager);
}
 
Example 2
Source File: NavigationFragment.java    From AndroidNavigation with MIT License 5 votes vote down vote up
private void redirectToFragmentInternal(AwesomeFragment fragment, AwesomeFragment target, boolean animated) {
    FragmentManager fragmentManager = getChildFragmentManager();

    AwesomeFragment topFragment = getTopFragment();
    if (topFragment == null) {
        return;
    }

    if (target == null) {
        target = topFragment;
    }

    AwesomeFragment aheadFragment = FragmentHelper.getAheadFragment(fragmentManager, target);

    topFragment.setAnimation(animated ? PresentAnimation.Redirect : PresentAnimation.Fade);
    if (aheadFragment != null && aheadFragment.isAdded()) {
        aheadFragment.setAnimation(animated ? PresentAnimation.Redirect : PresentAnimation.Fade);
    }

    fragmentManager.beginTransaction().setMaxLifecycle(topFragment, Lifecycle.State.STARTED).commit();

    fragmentManager.popBackStack(target.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.setReorderingAllowed(true);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    if (aheadFragment != null && aheadFragment.isAdded()) {
        transaction.hide(aheadFragment);
        transaction.setMaxLifecycle(aheadFragment, Lifecycle.State.STARTED);
    }
    fragment.setAnimation(animated ? PresentAnimation.Push : PresentAnimation.None);
    transaction.add(R.id.navigation_content, fragment, fragment.getSceneId());
    transaction.addToBackStack(fragment.getSceneId());
    transaction.commit();
    FragmentHelper.executePendingTransactionsSafe(fragmentManager);
}
 
Example 3
Source File: AwesomeActivity.java    From AndroidNavigation with MIT License 5 votes vote down vote up
protected void setRootFragmentInternal(AwesomeFragment fragment) {
    clearFragmentsInternal();
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.setReorderingAllowed(true);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    fragment.setAnimation(PresentAnimation.None);
    transaction.add(android.R.id.content, fragment, fragment.getSceneId());
    transaction.addToBackStack(fragment.getSceneId());
    transaction.commit();
    FragmentHelper.executePendingTransactionsSafe(fragmentManager);
}
 
Example 4
Source File: OverviewBaseFragment.java    From Easy_xkcd with Apache License 2.0 4 votes vote down vote up
public void goToComic(final int number, final int position) {
    //TODO add shared elements, maybe?
    databaseManager.setRead(number, true);
    Timber.d("number: %d", number);
    ((MainActivity) getActivity()).lastComicNumber = number;
    FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
    transaction.setReorderingAllowed(true);
    TextView title = getCurrentTitleTextView(position);
    if (title != null) {
        transaction.addSharedElement(title, title.getTransitionName());
        Timber.d("selected title %s", title.getText());
    }
    ImageView thumbnail = getCurrentThumbnail(position);
    if (thumbnail != null) {
        transaction.addSharedElement(thumbnail, thumbnail.getTransitionName());
    }

    ComicFragment comicFragment;
    if (prefHelper.overviewFav()) {
        comicFragment = new FavoritesFragment();
    } else if (prefHelper.fullOfflineEnabled()) {
        comicFragment = new OfflineFragment();
    } else {
        comicFragment = new ComicBrowserFragment();
    }
    comicFragment.lastComicNumber = number;
    comicFragment.transitionPending = true;
    transaction.replace(R.id.flContent, comicFragment, MainActivity.FRAGMENT_TAG)
            .commitAllowingStateLoss();
    ((MainActivity) getActivity()).setCurrentFragment(prefHelper.overviewFav() ? MainActivity.CurrentFragment.Favorites : MainActivity.CurrentFragment.Browser);
    /*android.support.v4.app.FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    ComicFragment fragment;
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    int subtitle;
    if (!prefHelper.overviewFav()) {
        FavoritesFragment favorites = (FavoritesFragment) fragmentManager.findFragmentByTag(FAV_TAG);
        if (favorites != null)
            transaction.hide(favorites);
        fragment = (ComicFragment) fragmentManager.findFragmentByTag(BROWSER_TAG);
        fragment.scrollTo(number, false);
        transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left)
                .hide(fragmentManager.findFragmentByTag(OVERVIEW_TAG))
                .show(fragment)
                .commit();
        subtitle = fragment.lastComicNumber;
    } else {
        transaction
                .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left)
                .hide(fragmentManager.findFragmentByTag(BROWSER_TAG))
                .hide(fragmentManager.findFragmentByTag(OVERVIEW_TAG));
        fragment = (FavoritesFragment) fragmentManager.findFragmentByTag(FAV_TAG);
        //int index = Arrays.binarySearch(databaseManager.getFavComicsLegacy(), number + 1);
        RealmResults<RealmComic> favorites = databaseManager.getFavComics();
        int index = 0;
        for (int i = 0; i < favorites.size(); i++) {
            if (favorites.get(i).getComicNumber() == number + 1) {
                index = i;
            }
        }
        if (fragment == null || index < 0) {
            if (index < 0) { // If the comic for some reason is in realm, but not in shared prefs, add it now
                index = -index - 1;
                databaseManager.setFavorite(number + 1, true);
            }
            fragment = new FavoritesFragment();
            transaction.add(R.id.flContent, fragment, FAV_TAG);
        } else {
            transaction.show(fragment);
            fragment.scrollTo(index, false);
        }
        fragment.favoriteIndex = index;
        subtitle = number + 1;
        transaction.commit();

        ((MainActivity) getActivity()).setCurrentFragment(MainActivity.CurrentFragment.Favorites);
        ((MainActivity) getActivity()).getSupportActionBar().setTitle(getActivity().getResources().getString(R.string.nv_favorites));
        ((MainActivity) getActivity()).getNavView().getMenu().findItem(R.id.nav_favorites).setChecked(true);
    }


    if (prefHelper.subtitleEnabled())
        ((MainActivity) getActivity()).getToolbar().setSubtitle(String.valueOf(subtitle)); */
}