I am following android tv tutorials from here:
Now I am stuck on DetailsFragment. In these demos is DetailsFragment set like a content of VideoDetailsActivity. When I start this new activity from main activity then I see nice animations(or transitions) belong to DetailsFragment.
But, In my case, I really won't go away from the main activity. I want to stay there. So I created DialogFragment and I set DetailsFragment like its content. However, I can't get work these animations (transitions). Detail is shown, but there are none transitions.
The original example creates Bundle object and sets it like a second parameter for startActivity of activity which holds DetailsFragment. Seems that's the key to getting work transitions. See:
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
getActivity(),
((ImageCardView) itemViewHolder.view).getMainImageView(),
VideoDetailsActivity.SHARED_ELEMENT_NAME).toBundle();
getActivity().startActivity(intent, bundle);
But how to do it for DialofFragment? I tried to create the same Bundle object and then I set it this way for DialogFragment:
fragmentDialog.setArguments(bundle);
fragmentDialog.show(getSupportFragmentManager(),"DetailsDialog");
But it won't work. I debugged DetailsFragment and in this way appropriate callbacks for onEntranceTransitionPrepare, onEntranceTransitionStart, onEntranceTransitionEnd are not called. Then I tried to set the shared element in onCreateView of my FragmentDialog:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.details, parent, false);
detailFragment = new MyDetailsFragment();
((ImageCardView) itemViewHolder.view).getMainImageView().setTransitionName("transitionName");
getChildFragmentManager().beginTransaction()
.add(R.id.container, detailFragment)
//.addToBackStack(createItemFragment.TAG)
.addSharedElement(((ImageCardView) itemViewHolder.view).getMainImageView(), "??? what here")
.addToBackStack("ProfileMenuFragment")
.commit();
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
return view;
}
Now are callbacks called, but I still don't see transitions... Truly, I do not know what should I place like a parameter for setTransitionName of my card view or second parameter for addSharedElement. Maybe that's problematic. ItemViewHolder is shared element between two fragments (item of browsefragment and MyDetailsFragment). If it can't work with DialogFragment then I can switch browsefragment and MyDetailsFragment on the same activity. But I really want these animations and I must stay on the same activity
Can someone help me?
EDIT :
I try to replace browsefragment and MyDetailsFragment with this code, but transitions are still not displayed.
if (detailFragment == null) {
detailFragment = new MyDetailsFragment();
}
ImageView logo = ((ImageCardView) itemViewHolder.view).getMainImageView();
logo.setTransitionName("transitionName");
context.getFragmentManager()
.beginTransaction()
.addSharedElement(logo, logo.getTransitionName())
.replace(android.R.id.content, detailFragment, "MyDetailFragment")
.addToBackStack("MyBrowseFragment")
.commit();
I set manually logo.setTransitionName because else it crashes. I think this is not correct way. DetailsFragment contains all transitions what I want. I must only somehow start them