Kore/app/src/main/java/org/xbmc/kore/utils/SharedElementTransition.java

120 lines
4.7 KiB
Java
Raw Normal View History

Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
/*
* Copyright 2017 Martijn Brekhof. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.xbmc.kore.utils;
import android.annotation.TargetApi;
import android.content.Context;
import androidx.core.app.SharedElementCallback;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.view.View;
import org.xbmc.kore.R;
import java.util.List;
import java.util.Map;
public class SharedElementTransition {
private static final String TAG = LogUtils.makeLogTag(SharedElementTransition.class);
public interface SharedElement {
/**
* Returns if the shared element if visible
* @return true if visible, false otherwise
*/
boolean isSharedElementVisible();
}
private boolean clearSharedElements;
/**
* Sets up the transition for the exiting fragment
* @param fragment
*/
@TargetApi(21)
public void setupExitTransition(Context context, Fragment fragment) {
Transition fade = TransitionInflater
.from(context)
.inflateTransition(android.R.transition.fade);
fragment.setExitTransition(fade);
fragment.setReenterTransition(fade);
fragment.setExitSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
// Clearing must be done in the reentering fragment
// as this is called last. Otherwise, the app will crash during transition setup. Not sure, but might
// be a v4 support package bug.
if (clearSharedElements) {
names.clear();
sharedElements.clear();
clearSharedElements = false;
}
}
});
}
/**
* Sets up the transition for the entering fragment
* @param fragmentTransaction
* @param fragment entering fragment
* @param sharedElement must have the transition name set
*/
@TargetApi(21)
public void setupEnterTransition(Context context,
FragmentTransaction fragmentTransaction,
final Fragment fragment,
View sharedElement) {
if (!(fragment instanceof SharedElement)) {
LogUtils.LOGD(TAG, "Enter transition fragment must implement SharedElement interface");
return;
}
androidx.core.app.SharedElementCallback seCallback = new androidx.core.app.SharedElementCallback() {
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
// On returning, onMapSharedElements for the exiting fragment is called before the onMapSharedElements
// for the reentering fragment. We use this to determine if we are returning and if
// we should clear the shared element lists. Note that, clearing must be done in the reentering fragment
// as this is called last. Otherwise, the app will crash during transition setup. Not sure, but might
// be a v4 support package bug.
if (fragment.isVisible() && (!((SharedElement) fragment).isSharedElementVisible())) {
// shared element not visible
clearSharedElements = true;
}
}
};
fragment.setEnterSharedElementCallback(seCallback);
fragment.setEnterTransition(TransitionInflater
.from(context)
.inflateTransition(R.transition.media_details));
fragment.setReturnTransition(null);
Transition changeImageTransition = TransitionInflater.from(
context).inflateTransition(R.transition.change_image);
fragment.setSharedElementReturnTransition(changeImageTransition);
fragment.setSharedElementEnterTransition(changeImageTransition);
fragmentTransaction.addSharedElement(sharedElement, sharedElement.getTransitionName());
}
}