Search in sources :

Example 1 with TransitionTargetChild

use of app.insti.fragment.TransitionTargetChild in project IITB-App by wncc.

the class Utils method updateSharedElementFragment.

public static void updateSharedElementFragment(final Fragment fragment, final Fragment currentFragment, Map<View, String> sharedElements) {
    FragmentTransaction ft = currentFragment.getActivity().getSupportFragmentManager().beginTransaction();
    Transition transition = new DetailsTransition();
    /* Set up transitions */
    fragment.setSharedElementEnterTransition(transition);
    fragment.setEnterTransition(new Slide());
    currentFragment.setExitTransition(new Fade());
    fragment.setSharedElementReturnTransition(transition);
    /* Set transition for parent in case it is a child */
    if (currentFragment instanceof TransitionTargetChild) {
        ((TransitionTargetChild) currentFragment).getParent().setExitTransition(new Fade());
    }
    transition.addListener(new Transition.TransitionListener() {

        @Override
        public void onTransitionStart(Transition transition) {
        }

        @Override
        public void onTransitionEnd(Transition transition) {
            if (fragment instanceof TransitionTargetFragment) {
                ((TransitionTargetFragment) fragment).transitionEnd();
            }
            if (currentFragment instanceof TransitionTargetFragment) {
                ((TransitionTargetFragment) currentFragment).transitionEnd();
            }
        }

        @Override
        public void onTransitionCancel(Transition transition) {
        }

        @Override
        public void onTransitionPause(Transition transition) {
        }

        @Override
        public void onTransitionResume(Transition transition) {
        }
    });
    /* Add all shared elements */
    for (Map.Entry<View, String> entry : sharedElements.entrySet()) {
        ft.addSharedElement(entry.getKey(), entry.getValue());
    }
    /* Update the fragment */
    ft.replace(R.id.framelayout_for_fragment, fragment, getTag(fragment)).addToBackStack(getTag(fragment)).commit();
}
Also used : NavigationView(com.google.android.material.navigation.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) FragmentTransaction(androidx.fragment.app.FragmentTransaction) TransitionTargetChild(app.insti.fragment.TransitionTargetChild) TransitionTargetFragment(app.insti.fragment.TransitionTargetFragment) Slide(androidx.transition.Slide) Transition(androidx.transition.Transition) Fade(androidx.transition.Fade) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

View (android.view.View)1 ImageView (android.widget.ImageView)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 Fade (androidx.transition.Fade)1 Slide (androidx.transition.Slide)1 Transition (androidx.transition.Transition)1 TransitionTargetChild (app.insti.fragment.TransitionTargetChild)1 TransitionTargetFragment (app.insti.fragment.TransitionTargetFragment)1 NavigationView (com.google.android.material.navigation.NavigationView)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1