Skip to content

Commit

Permalink
Convert AnimationUtils functions to extension functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jan 16, 2021
1 parent 0d33f8b commit 920e560
Show file tree
Hide file tree
Showing 25 changed files with 568 additions and 687 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.Disposable;

import static org.schabi.newpipe.util.AnimationUtils.animateView;
import static org.schabi.newpipe.ktx.ViewUtils.animate;

public abstract class BaseStateFragment<I> extends BaseFragment implements ViewContract<I> {
@State
Expand Down Expand Up @@ -131,35 +131,35 @@ protected void startLoading(final boolean forceLoad) {
@Override
public void showLoading() {
if (emptyStateView != null) {
animateView(emptyStateView, false, 150);
animate(emptyStateView, false, 150);
}
if (loadingProgressBar != null) {
animateView(loadingProgressBar, true, 400);
animate(loadingProgressBar, true, 400);
}
animateView(errorPanelRoot, false, 150);
animate(errorPanelRoot, false, 150);
}

@Override
public void hideLoading() {
if (emptyStateView != null) {
animateView(emptyStateView, false, 150);
animate(emptyStateView, false, 150);
}
if (loadingProgressBar != null) {
animateView(loadingProgressBar, false, 0);
animate(loadingProgressBar, false, 0);
}
animateView(errorPanelRoot, false, 150);
animate(errorPanelRoot, false, 150);
}

@Override
public void showEmptyState() {
isLoading.set(false);
if (emptyStateView != null) {
animateView(emptyStateView, true, 200);
animate(emptyStateView, true, 200);
}
if (loadingProgressBar != null) {
animateView(loadingProgressBar, false, 0);
animate(loadingProgressBar, false, 0);
}
animateView(errorPanelRoot, false, 150);
animate(errorPanelRoot, false, 150);
}

@Override
Expand All @@ -174,11 +174,11 @@ public void showError(final String message, final boolean showRetryButton) {

errorTextView.setText(message);
if (showRetryButton) {
animateView(errorButtonRetry, true, 600);
animate(errorButtonRetry, true, 600);
} else {
animateView(errorButtonRetry, false, 0);
animate(errorButtonRetry, false, 0);
}
animateView(errorPanelRoot, true, 300);
animate(errorPanelRoot, true, 300);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@
import org.schabi.newpipe.fragments.EmptyFragment;
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
import org.schabi.newpipe.ktx.AnimationType;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.player.Player;
import org.schabi.newpipe.player.MainPlayer;
import org.schabi.newpipe.player.Player;
import org.schabi.newpipe.player.event.OnKeyDownListener;
import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener;
import org.schabi.newpipe.player.helper.PlayerHelper;
Expand Down Expand Up @@ -125,7 +126,7 @@
import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked;
import static org.schabi.newpipe.player.helper.PlayerHelper.isClearingQueueConfirmationRequired;
import static org.schabi.newpipe.player.playqueue.PlayQueueItem.RECOVERY_UNSET;
import static org.schabi.newpipe.util.AnimationUtils.animateView;
import static org.schabi.newpipe.ktx.ViewUtils.animate;
import static org.schabi.newpipe.util.ExtractorHelper.showMetaInfoInTextView;

public final class VideoDetailFragment
Expand Down Expand Up @@ -745,8 +746,10 @@ private View.OnTouchListener getOnControlsTouchListener() {
}

if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
animateView(appendControlsDetail, true, 250, 0, () ->
animateView(appendControlsDetail, false, 1500, 1000));
animate(appendControlsDetail, true, 250, AnimationType.ALPHA,
0, () ->
animate(appendControlsDetail, false, 1500,
AnimationType.ALPHA, 1000));
}
return false;
};
Expand Down Expand Up @@ -1334,8 +1337,8 @@ private void setErrorImage(final int imageResource) {

thumbnailImageView.setImageDrawable(
AppCompatResources.getDrawable(requireContext(), imageResource));
animateView(thumbnailImageView, false, 0, 0,
() -> animateView(thumbnailImageView, true, 500));
animate(thumbnailImageView, false, 0, AnimationType.ALPHA, 0,
() -> animate(thumbnailImageView, true, 500));
}

@Override
Expand Down Expand Up @@ -1417,14 +1420,14 @@ public void showLoading() {
contentRootLayoutHiding.setVisibility(View.INVISIBLE);
}

animateView(thumbnailPlayButton, false, 50);
animateView(detailDurationView, false, 100);
animateView(detailPositionView, false, 100);
animateView(positionView, false, 50);
animate(thumbnailPlayButton, false, 50);
animate(detailDurationView, false, 100);
animate(detailPositionView, false, 100);
animate(positionView, false, 50);

videoTitleTextView.setText(title);
videoTitleTextView.setMaxLines(1);
animateView(videoTitleTextView, true, 0);
animate(videoTitleTextView, true, 0);

videoDescriptionRootLayout.setVisibility(View.GONE);
videoTitleToggleArrow.setVisibility(View.GONE);
Expand Down Expand Up @@ -1466,7 +1469,7 @@ public void handleResult(@NonNull final StreamInfo info) {
player != null && player.isFullscreen() ? View.GONE : View.VISIBLE);
}
}
animateView(thumbnailPlayButton, true, 200);
animate(thumbnailPlayButton, true, 200);
videoTitleTextView.setText(title);

if (!isEmpty(info.getSubChannelName())) {
Expand Down Expand Up @@ -1530,12 +1533,12 @@ public void handleResult(@NonNull final StreamInfo info) {
detailDurationView.setText(Localization.getDurationString(info.getDuration()));
detailDurationView.setBackgroundColor(
ContextCompat.getColor(activity, R.color.duration_background_color));
animateView(detailDurationView, true, 100);
animate(detailDurationView, true, 100);
} else if (info.getStreamType() == StreamType.LIVE_STREAM) {
detailDurationView.setText(R.string.duration_live);
detailDurationView.setBackgroundColor(
ContextCompat.getColor(activity, R.color.live_duration_background_color));
animateView(detailDurationView, true, 100);
animate(detailDurationView, true, 100);
} else {
detailDurationView.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -1703,8 +1706,8 @@ private void updateProgressInfo(@NonNull final StreamInfo info) {
// Show saved position from backStack if user allows it
showPlaybackProgress(playQueue.getItem().getRecoveryPosition(),
playQueue.getItem().getDuration() * 1000);
animateView(positionView, true, 500);
animateView(detailPositionView, true, 500);
animate(positionView, true, 500);
animate(detailPositionView, true, 500);
}
return;
}
Expand All @@ -1718,8 +1721,8 @@ private void updateProgressInfo(@NonNull final StreamInfo info) {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(state -> {
showPlaybackProgress(state.getProgressTime(), info.getDuration() * 1000);
animateView(positionView, true, 500);
animateView(detailPositionView, true, 500);
animate(positionView, true, 500);
animate(detailPositionView, true, 500);
}, e -> {
if (DEBUG) {
e.printStackTrace();
Expand Down Expand Up @@ -1747,8 +1750,8 @@ private void showPlaybackProgress(final long progress, final long duration) {
detailPositionView.setText(position);
}
if (positionView.getVisibility() != View.VISIBLE) {
animateView(positionView, true, 100);
animateView(detailPositionView, true, 100);
animate(positionView, true, 100);
animate(detailPositionView, true, 100);
}
}

Expand Down Expand Up @@ -1802,8 +1805,8 @@ public void onPlaybackUpdate(final int state,
&& player.getPlayQueue() != null
&& player.getPlayQueue().getItem() != null
&& player.getPlayQueue().getItem().getUrl().equals(url)) {
animateView(positionView, true, 100);
animateView(detailPositionView, true, 100);
animate(positionView, true, 100);
animate(detailPositionView, true, 100);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import java.util.List;
import java.util.Queue;

import static org.schabi.newpipe.util.AnimationUtils.animateView;
import static org.schabi.newpipe.ktx.ViewUtils.animate;

public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
implements ListViewContract<I, N>, StateSaver.WriteRead,
Expand Down Expand Up @@ -406,23 +406,17 @@ public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
// Contract
//////////////////////////////////////////////////////////////////////////*/

@Override
public void showLoading() {
super.showLoading();
// animateView(itemsList, false, 400);
}

@Override
public void hideLoading() {
super.hideLoading();
animateView(itemsList, true, 300);
animate(itemsList, true, 300);
}

@Override
public void showError(final String message, final boolean showRetryButton) {
super.showError(message, showRetryButton);
showListFooter(false);
animateView(itemsList, false, 200);
animate(itemsList, false, 200);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.ktx.AnimationType;
import org.schabi.newpipe.local.subscription.SubscriptionManager;
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
Expand All @@ -64,9 +64,9 @@
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.schedulers.Schedulers;

import static org.schabi.newpipe.util.AnimationUtils.animateBackgroundColor;
import static org.schabi.newpipe.util.AnimationUtils.animateTextColor;
import static org.schabi.newpipe.util.AnimationUtils.animateView;
import static org.schabi.newpipe.ktx.TextViewUtils.animateTextColor;
import static org.schabi.newpipe.ktx.ViewUtils.animate;
import static org.schabi.newpipe.ktx.ViewUtils.animateBackgroundColor;

public class ChannelFragment extends BaseListInfoFragment<ChannelInfo>
implements View.OnClickListener {
Expand Down Expand Up @@ -224,7 +224,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {

private void monitorSubscription(final ChannelInfo info) {
final Consumer<Throwable> onError = (Throwable throwable) -> {
animateView(headerBinding.channelSubscribeButton, false, 100);
animate(headerBinding.channelSubscribeButton, false, 100);
showSnackBarError(throwable, UserAction.SUBSCRIPTION,
NewPipe.getNameOfService(currentInfo.getServiceId()),
"Get subscription status", 0);
Expand Down Expand Up @@ -379,8 +379,8 @@ private void updateSubscribeButton(final boolean isSubscribed) {
subscribedText);
}

animateView(headerBinding.channelSubscribeButton, AnimationUtils.Type.LIGHT_SCALE_AND_ALPHA,
true, 100);
animate(headerBinding.channelSubscribeButton, true, 100,
AnimationType.LIGHT_SCALE_AND_ALPHA);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -436,7 +436,7 @@ public void showLoading() {
IMAGE_LOADER.cancelDisplayTask(headerBinding.channelBannerImage);
IMAGE_LOADER.cancelDisplayTask(headerBinding.channelAvatarView);
IMAGE_LOADER.cancelDisplayTask(headerBinding.subChannelAvatarView);
animateView(headerBinding.channelSubscribeButton, false, 100);
animate(headerBinding.channelSubscribeButton, false, 100);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.ktx.ViewUtils;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.ExtractorHelper;

import io.reactivex.rxjava3.core.Single;
Expand Down Expand Up @@ -84,16 +84,14 @@ public void showLoading() {
public void handleResult(@NonNull final CommentsInfo result) {
super.handleResult(result);

AnimationUtils.slideUp(requireView(), 120, 150, 0.06f);
ViewUtils.slideUp(requireView(), 120, 150, 0.06f);

if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.REQUESTED_COMMENTS,
NewPipe.getNameOfService(result.getServiceId()), result.getUrl(), 0);
}

if (disposables != null) {
disposables.clear();
}
disposables.clear();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import icepick.State;
import io.reactivex.rxjava3.core.Single;

import static org.schabi.newpipe.util.AnimationUtils.animateView;
import static org.schabi.newpipe.ktx.ViewUtils.animate;

/**
* Created by Christian Schabesberger on 23.09.17.
Expand Down Expand Up @@ -160,7 +160,7 @@ public Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
@Override
public void showLoading() {
super.showLoading();
animateView(itemsList, false, 100);
animate(itemsList, false, 100);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;

import static org.schabi.newpipe.util.AnimationUtils.animateView;
import static org.schabi.newpipe.ktx.ViewUtils.animate;
import static org.schabi.newpipe.util.ThemeHelper.resolveResourceIdFromAttr;

public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
Expand Down Expand Up @@ -261,19 +261,19 @@ public boolean onOptionsItemSelected(final MenuItem item) {
@Override
public void showLoading() {
super.showLoading();
animateView(headerBinding.getRoot(), false, 200);
animateView(itemsList, false, 100);
animate(headerBinding.getRoot(), false, 200);
animate(itemsList, false, 100);

IMAGE_LOADER.cancelDisplayTask(headerBinding.uploaderAvatarView);
animateView(headerBinding.uploaderLayout, false, 200);
animate(headerBinding.uploaderLayout, false, 200);
}

@Override
public void handleResult(@NonNull final PlaylistInfo result) {
super.handleResult(result);

animateView(headerBinding.getRoot(), true, 100);
animateView(headerBinding.uploaderLayout, true, 300);
animate(headerBinding.getRoot(), true, 100);
animate(headerBinding.uploaderLayout, true, 300);
headerBinding.uploaderLayout.setOnClickListener(null);
// If we have an uploader put them into the UI
if (!TextUtils.isEmpty(result.getUploaderName())) {
Expand Down
Loading

0 comments on commit 920e560

Please sign in to comment.