Fix animations
This commit is contained in:
parent
9c7f249756
commit
affd23b14e
8 changed files with 261 additions and 259 deletions
|
|
@ -1,7 +1,5 @@
|
|||
package org.schabi.newpipe.fragments;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Rect;
|
||||
|
|
@ -28,6 +26,8 @@ import org.schabi.newpipe.R;
|
|||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
protected final String TAG = "BaseFragment@" + Integer.toHexString(hashCode());
|
||||
protected static final boolean DEBUG = MainActivity.DEBUG;
|
||||
|
|
@ -130,70 +130,6 @@ public abstract class BaseFragment extends Fragment {
|
|||
// Utils
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public void animateView(final View view, final boolean enterOrExit, long duration) {
|
||||
animateView(view, enterOrExit, duration, 0, null);
|
||||
}
|
||||
|
||||
public void animateView(final View view, final boolean enterOrExit, long duration, final Runnable execOnEnd) {
|
||||
animateView(view, enterOrExit, duration, 0, execOnEnd);
|
||||
}
|
||||
|
||||
public void animateView(final View view, final boolean enterOrExit, long duration, long delay) {
|
||||
animateView(view, enterOrExit, duration, delay, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate the view
|
||||
*
|
||||
* @param view view that will be animated
|
||||
* @param enterOrExit true to enter, false to exit
|
||||
* @param duration how long the animation will take, in milliseconds
|
||||
* @param delay how long the animation will take to start, in milliseconds
|
||||
* @param execOnEnd runnable that will be executed when the animation ends
|
||||
*/
|
||||
public void animateView(final View view, final boolean enterOrExit, long duration, long delay, final Runnable execOnEnd) {
|
||||
if (DEBUG) Log.d(TAG, "animateView() called with: view = [" + view + "], enterOrExit = [" + enterOrExit + "], duration = [" + duration + "], execOnEnd = [" + execOnEnd + "]");
|
||||
if (view == null) return;
|
||||
|
||||
if (view.getVisibility() == View.VISIBLE && enterOrExit) {
|
||||
view.animate().setListener(null).cancel();
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.setAlpha(1f);
|
||||
if (execOnEnd != null) execOnEnd.run();
|
||||
return;
|
||||
} else if ((view.getVisibility() == View.GONE || view.getVisibility() == View.INVISIBLE) && !enterOrExit) {
|
||||
view.animate().setListener(null).cancel();
|
||||
view.setVisibility(View.GONE);
|
||||
view.setAlpha(0f);
|
||||
if (execOnEnd != null) execOnEnd.run();
|
||||
return;
|
||||
}
|
||||
|
||||
view.animate().setListener(null).cancel();
|
||||
view.setVisibility(View.VISIBLE);
|
||||
|
||||
if (enterOrExit) {
|
||||
view.animate().alpha(1f).setDuration(duration).setStartDelay(delay)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (execOnEnd != null) execOnEnd.run();
|
||||
}
|
||||
}).start();
|
||||
} else {
|
||||
view.animate().alpha(0f)
|
||||
.setDuration(duration).setStartDelay(delay)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
view.setVisibility(View.GONE);
|
||||
if (execOnEnd != null) execOnEnd.run();
|
||||
}
|
||||
})
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
||||
protected void setErrorMessage(String message, boolean showRetryButton) {
|
||||
if (errorTextView == null || activity == null) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ import java.io.Serializable;
|
|||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||
|
||||
public class ChannelFragment extends BaseFragment implements ChannelExtractorWorker.OnChannelInfoReceive {
|
||||
private final String TAG = "ChannelFragment@" + Integer.toHexString(hashCode());
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import com.nostra13.universalimageloader.core.assist.FailReason;
|
|||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||
|
||||
import org.schabi.newpipe.ImageErrorLoadingListener;
|
||||
import org.schabi.newpipe.Localization;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.ReCaptchaActivity;
|
||||
import org.schabi.newpipe.download.DownloadDialog;
|
||||
|
|
@ -56,6 +55,8 @@ import org.schabi.newpipe.player.MainVideoPlayer;
|
|||
import org.schabi.newpipe.player.PlayVideoActivity;
|
||||
import org.schabi.newpipe.player.PopupVideoPlayer;
|
||||
import org.schabi.newpipe.report.ErrorActivity;
|
||||
import org.schabi.newpipe.util.Constants;
|
||||
import org.schabi.newpipe.util.Localization;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.util.PermissionHelper;
|
||||
import org.schabi.newpipe.util.Utils;
|
||||
|
|
@ -65,6 +66,8 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||
|
||||
public class VideoDetailFragment extends BaseFragment implements StreamExtractorWorker.OnStreamInfoReceivedListener, SharedPreferences.OnSharedPreferenceChangeListener, View.OnClickListener {
|
||||
private final String TAG = "VideoDetailFragment@" + Integer.toHexString(hashCode());
|
||||
|
||||
|
|
@ -72,9 +75,6 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
|
|||
private static final int INITIAL_RELATED_VIDEOS = 8;
|
||||
|
||||
private static final String KORE_PACKET = "org.xbmc.kore";
|
||||
private static final String SERVICE_ID_KEY = "service_id_key";
|
||||
private static final String VIDEO_URL_KEY = "video_url_key";
|
||||
private static final String VIDEO_TITLE_KEY = "video_title_key";
|
||||
private static final String STACK_KEY = "stack_key";
|
||||
private static final String INFO_KEY = "info_key";
|
||||
private static final String WAS_RELATED_EXPANDED_KEY = "was_related_expanded_key";
|
||||
|
|
@ -171,9 +171,9 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
|
|||
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
videoTitle = savedInstanceState.getString(VIDEO_TITLE_KEY);
|
||||
videoUrl = savedInstanceState.getString(VIDEO_URL_KEY);
|
||||
serviceId = savedInstanceState.getInt(SERVICE_ID_KEY, 0);
|
||||
videoTitle = savedInstanceState.getString(Constants.KEY_TITLE);
|
||||
videoUrl = savedInstanceState.getString(Constants.KEY_URL);
|
||||
serviceId = savedInstanceState.getInt(Constants.KEY_SERVICE_ID, 0);
|
||||
wasRelatedStreamsExpanded = savedInstanceState.getBoolean(WAS_RELATED_EXPANDED_KEY, false);
|
||||
Serializable serializable = savedInstanceState.getSerializable(STACK_KEY);
|
||||
if (serializable instanceof Stack) {
|
||||
|
|
@ -290,9 +290,9 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
|
|||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (DEBUG) Log.d(TAG, "onSaveInstanceState() called with: outState = [" + outState + "]");
|
||||
outState.putString(VIDEO_URL_KEY, videoUrl);
|
||||
outState.putString(VIDEO_TITLE_KEY, videoTitle);
|
||||
outState.putInt(SERVICE_ID_KEY, serviceId);
|
||||
outState.putString(Constants.KEY_URL, videoUrl);
|
||||
outState.putString(Constants.KEY_TITLE, videoTitle);
|
||||
outState.putInt(Constants.KEY_SERVICE_ID, serviceId);
|
||||
outState.putSerializable(STACK_KEY, stack);
|
||||
|
||||
int nextCount = currentStreamInfo != null && currentStreamInfo.next_video != null ? 2 : 0;
|
||||
|
|
@ -804,7 +804,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
|
|||
* If it is, check if the cache contains the info already.</br>
|
||||
* If the cache doesn't have the info, load from the network.
|
||||
*
|
||||
* @param info info to prepare and load, can be null
|
||||
* @param info info to prepare and load, can be null
|
||||
* @param scrollToTop whether or not scroll the scrollView to y = 0
|
||||
*/
|
||||
public void prepareAndLoad(StreamInfo info, boolean scrollToTop) {
|
||||
|
|
@ -848,7 +848,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
|
|||
else parallaxScrollRootView.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
animateView(contentRootLayoutHiding, false, greaterThanThreshold ? 250 : 0, new Runnable() {
|
||||
animateView(contentRootLayoutHiding, false, greaterThanThreshold ? 250 : 0, 0, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleStreamInfo(infoFinal, false);
|
||||
|
|
@ -1056,7 +1056,7 @@ public class VideoDetailFragment extends BaseFragment implements StreamExtractor
|
|||
private void setErrorImage(final int imageResource) {
|
||||
if (thumbnailImageView == null || activity == null) return;
|
||||
thumbnailImageView.setImageDrawable(ContextCompat.getDrawable(activity, imageResource));
|
||||
animateView(thumbnailImageView, false, 0, new Runnable() {
|
||||
animateView(thumbnailImageView, false, 0, 0, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
animateView(thumbnailImageView, true, 500);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import org.schabi.newpipe.extractor.search.SearchResult;
|
|||
import org.schabi.newpipe.fragments.BaseFragment;
|
||||
import org.schabi.newpipe.info_list.InfoItemBuilder;
|
||||
import org.schabi.newpipe.info_list.InfoListAdapter;
|
||||
import org.schabi.newpipe.util.Constants;
|
||||
import org.schabi.newpipe.util.NavigationHelper;
|
||||
import org.schabi.newpipe.workers.SearchWorker;
|
||||
import org.schabi.newpipe.workers.SuggestionWorker;
|
||||
|
|
@ -45,12 +46,13 @@ import java.util.ArrayList;
|
|||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||
|
||||
public class SearchFragment extends BaseFragment implements SuggestionWorker.OnSuggestionResult, SearchWorker.OnSearchResult {
|
||||
private final String TAG = "SearchFragment@" + Integer.toHexString(hashCode());
|
||||
// savedInstanceBundle arguments
|
||||
private static final String QUERY_KEY = "query_key";
|
||||
private static final String PAGE_NUMBER_KEY = "page_number_key";
|
||||
private static final String SERVICE_KEY = "service_key";
|
||||
private static final String INFO_LIST_KEY = "info_list_key";
|
||||
private static final String WAS_LOADING_KEY = "was_loading_key";
|
||||
private static final String ERROR_KEY = "error_key";
|
||||
|
|
@ -101,7 +103,7 @@ public class SearchFragment extends BaseFragment implements SuggestionWorker.OnS
|
|||
setHasOptionsMenu(true);
|
||||
if (savedInstanceState != null) {
|
||||
searchQuery = savedInstanceState.getString(QUERY_KEY);
|
||||
serviceId = savedInstanceState.getInt(SERVICE_KEY, 0);
|
||||
serviceId = savedInstanceState.getInt(Constants.KEY_SERVICE_ID, 0);
|
||||
pageNumber = savedInstanceState.getInt(PAGE_NUMBER_KEY, 0);
|
||||
wasLoading.set(savedInstanceState.getBoolean(WAS_LOADING_KEY, false));
|
||||
filterItemCheckedId = savedInstanceState.getInt(FILTER_CHECKED_ID_KEY, 0);
|
||||
|
|
@ -171,7 +173,7 @@ public class SearchFragment extends BaseFragment implements SuggestionWorker.OnS
|
|||
String query = searchEditText != null && !TextUtils.isEmpty(searchEditText.getText().toString())
|
||||
? searchEditText.getText().toString() : searchQuery;
|
||||
outState.putString(QUERY_KEY, query);
|
||||
outState.putInt(SERVICE_KEY, serviceId);
|
||||
outState.putInt(Constants.KEY_SERVICE_ID, serviceId);
|
||||
outState.putInt(PAGE_NUMBER_KEY, pageNumber);
|
||||
outState.putSerializable(INFO_LIST_KEY, ((ArrayList<InfoItem>) infoListAdapter.getItemsList()));
|
||||
outState.putBoolean(WAS_LOADING_KEY, curSearchWorker != null && curSearchWorker.isRunning());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue