Skip to content

Commit 920e560

Browse files
Convert AnimationUtils functions to extension functions.
1 parent 0d33f8b commit 920e560

25 files changed

Lines changed: 568 additions & 687 deletions

app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
3838
import io.reactivex.rxjava3.disposables.Disposable;
3939

40-
import static org.schabi.newpipe.util.AnimationUtils.animateView;
40+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
4141

4242
public abstract class BaseStateFragment<I> extends BaseFragment implements ViewContract<I> {
4343
@State
@@ -131,35 +131,35 @@ protected void startLoading(final boolean forceLoad) {
131131
@Override
132132
public void showLoading() {
133133
if (emptyStateView != null) {
134-
animateView(emptyStateView, false, 150);
134+
animate(emptyStateView, false, 150);
135135
}
136136
if (loadingProgressBar != null) {
137-
animateView(loadingProgressBar, true, 400);
137+
animate(loadingProgressBar, true, 400);
138138
}
139-
animateView(errorPanelRoot, false, 150);
139+
animate(errorPanelRoot, false, 150);
140140
}
141141

142142
@Override
143143
public void hideLoading() {
144144
if (emptyStateView != null) {
145-
animateView(emptyStateView, false, 150);
145+
animate(emptyStateView, false, 150);
146146
}
147147
if (loadingProgressBar != null) {
148-
animateView(loadingProgressBar, false, 0);
148+
animate(loadingProgressBar, false, 0);
149149
}
150-
animateView(errorPanelRoot, false, 150);
150+
animate(errorPanelRoot, false, 150);
151151
}
152152

153153
@Override
154154
public void showEmptyState() {
155155
isLoading.set(false);
156156
if (emptyStateView != null) {
157-
animateView(emptyStateView, true, 200);
157+
animate(emptyStateView, true, 200);
158158
}
159159
if (loadingProgressBar != null) {
160-
animateView(loadingProgressBar, false, 0);
160+
animate(loadingProgressBar, false, 0);
161161
}
162-
animateView(errorPanelRoot, false, 150);
162+
animate(errorPanelRoot, false, 150);
163163
}
164164

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

175175
errorTextView.setText(message);
176176
if (showRetryButton) {
177-
animateView(errorButtonRetry, true, 600);
177+
animate(errorButtonRetry, true, 600);
178178
} else {
179-
animateView(errorButtonRetry, false, 0);
179+
animate(errorButtonRetry, false, 0);
180180
}
181-
animateView(errorPanelRoot, true, 300);
181+
animate(errorPanelRoot, true, 300);
182182
}
183183

184184
@Override

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@
7676
import org.schabi.newpipe.fragments.EmptyFragment;
7777
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
7878
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
79+
import org.schabi.newpipe.ktx.AnimationType;
7980
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
8081
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
8182
import org.schabi.newpipe.local.history.HistoryRecordManager;
82-
import org.schabi.newpipe.player.Player;
8383
import org.schabi.newpipe.player.MainPlayer;
84+
import org.schabi.newpipe.player.Player;
8485
import org.schabi.newpipe.player.event.OnKeyDownListener;
8586
import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener;
8687
import org.schabi.newpipe.player.helper.PlayerHelper;
@@ -125,7 +126,7 @@
125126
import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked;
126127
import static org.schabi.newpipe.player.helper.PlayerHelper.isClearingQueueConfirmationRequired;
127128
import static org.schabi.newpipe.player.playqueue.PlayQueueItem.RECOVERY_UNSET;
128-
import static org.schabi.newpipe.util.AnimationUtils.animateView;
129+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
129130
import static org.schabi.newpipe.util.ExtractorHelper.showMetaInfoInTextView;
130131

131132
public final class VideoDetailFragment
@@ -745,8 +746,10 @@ private View.OnTouchListener getOnControlsTouchListener() {
745746
}
746747

747748
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
748-
animateView(appendControlsDetail, true, 250, 0, () ->
749-
animateView(appendControlsDetail, false, 1500, 1000));
749+
animate(appendControlsDetail, true, 250, AnimationType.ALPHA,
750+
0, () ->
751+
animate(appendControlsDetail, false, 1500,
752+
AnimationType.ALPHA, 1000));
750753
}
751754
return false;
752755
};
@@ -1334,8 +1337,8 @@ private void setErrorImage(final int imageResource) {
13341337

13351338
thumbnailImageView.setImageDrawable(
13361339
AppCompatResources.getDrawable(requireContext(), imageResource));
1337-
animateView(thumbnailImageView, false, 0, 0,
1338-
() -> animateView(thumbnailImageView, true, 500));
1340+
animate(thumbnailImageView, false, 0, AnimationType.ALPHA, 0,
1341+
() -> animate(thumbnailImageView, true, 500));
13391342
}
13401343

13411344
@Override
@@ -1417,14 +1420,14 @@ public void showLoading() {
14171420
contentRootLayoutHiding.setVisibility(View.INVISIBLE);
14181421
}
14191422

1420-
animateView(thumbnailPlayButton, false, 50);
1421-
animateView(detailDurationView, false, 100);
1422-
animateView(detailPositionView, false, 100);
1423-
animateView(positionView, false, 50);
1423+
animate(thumbnailPlayButton, false, 50);
1424+
animate(detailDurationView, false, 100);
1425+
animate(detailPositionView, false, 100);
1426+
animate(positionView, false, 50);
14241427

14251428
videoTitleTextView.setText(title);
14261429
videoTitleTextView.setMaxLines(1);
1427-
animateView(videoTitleTextView, true, 0);
1430+
animate(videoTitleTextView, true, 0);
14281431

14291432
videoDescriptionRootLayout.setVisibility(View.GONE);
14301433
videoTitleToggleArrow.setVisibility(View.GONE);
@@ -1466,7 +1469,7 @@ public void handleResult(@NonNull final StreamInfo info) {
14661469
player != null && player.isFullscreen() ? View.GONE : View.VISIBLE);
14671470
}
14681471
}
1469-
animateView(thumbnailPlayButton, true, 200);
1472+
animate(thumbnailPlayButton, true, 200);
14701473
videoTitleTextView.setText(title);
14711474

14721475
if (!isEmpty(info.getSubChannelName())) {
@@ -1530,12 +1533,12 @@ public void handleResult(@NonNull final StreamInfo info) {
15301533
detailDurationView.setText(Localization.getDurationString(info.getDuration()));
15311534
detailDurationView.setBackgroundColor(
15321535
ContextCompat.getColor(activity, R.color.duration_background_color));
1533-
animateView(detailDurationView, true, 100);
1536+
animate(detailDurationView, true, 100);
15341537
} else if (info.getStreamType() == StreamType.LIVE_STREAM) {
15351538
detailDurationView.setText(R.string.duration_live);
15361539
detailDurationView.setBackgroundColor(
15371540
ContextCompat.getColor(activity, R.color.live_duration_background_color));
1538-
animateView(detailDurationView, true, 100);
1541+
animate(detailDurationView, true, 100);
15391542
} else {
15401543
detailDurationView.setVisibility(View.GONE);
15411544
}
@@ -1703,8 +1706,8 @@ private void updateProgressInfo(@NonNull final StreamInfo info) {
17031706
// Show saved position from backStack if user allows it
17041707
showPlaybackProgress(playQueue.getItem().getRecoveryPosition(),
17051708
playQueue.getItem().getDuration() * 1000);
1706-
animateView(positionView, true, 500);
1707-
animateView(detailPositionView, true, 500);
1709+
animate(positionView, true, 500);
1710+
animate(detailPositionView, true, 500);
17081711
}
17091712
return;
17101713
}
@@ -1718,8 +1721,8 @@ private void updateProgressInfo(@NonNull final StreamInfo info) {
17181721
.observeOn(AndroidSchedulers.mainThread())
17191722
.subscribe(state -> {
17201723
showPlaybackProgress(state.getProgressTime(), info.getDuration() * 1000);
1721-
animateView(positionView, true, 500);
1722-
animateView(detailPositionView, true, 500);
1724+
animate(positionView, true, 500);
1725+
animate(detailPositionView, true, 500);
17231726
}, e -> {
17241727
if (DEBUG) {
17251728
e.printStackTrace();
@@ -1747,8 +1750,8 @@ private void showPlaybackProgress(final long progress, final long duration) {
17471750
detailPositionView.setText(position);
17481751
}
17491752
if (positionView.getVisibility() != View.VISIBLE) {
1750-
animateView(positionView, true, 100);
1751-
animateView(detailPositionView, true, 100);
1753+
animate(positionView, true, 100);
1754+
animate(detailPositionView, true, 100);
17521755
}
17531756
}
17541757

@@ -1802,8 +1805,8 @@ public void onPlaybackUpdate(final int state,
18021805
&& player.getPlayQueue() != null
18031806
&& player.getPlayQueue().getItem() != null
18041807
&& player.getPlayQueue().getItem().getUrl().equals(url)) {
1805-
animateView(positionView, true, 100);
1806-
animateView(detailPositionView, true, 100);
1808+
animate(positionView, true, 100);
1809+
animate(detailPositionView, true, 100);
18071810
}
18081811
break;
18091812
}

app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import java.util.List;
4747
import java.util.Queue;
4848

49-
import static org.schabi.newpipe.util.AnimationUtils.animateView;
49+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
5050

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

409-
@Override
410-
public void showLoading() {
411-
super.showLoading();
412-
// animateView(itemsList, false, 400);
413-
}
414-
415409
@Override
416410
public void hideLoading() {
417411
super.hideLoading();
418-
animateView(itemsList, true, 300);
412+
animate(itemsList, true, 300);
419413
}
420414

421415
@Override
422416
public void showError(final String message, final boolean showRetryButton) {
423417
super.showError(message, showRetryButton);
424418
showListFooter(false);
425-
animateView(itemsList, false, 200);
419+
animate(itemsList, false, 200);
426420
}
427421

428422
@Override

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
3838
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
3939
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
40+
import org.schabi.newpipe.ktx.AnimationType;
4041
import org.schabi.newpipe.local.subscription.SubscriptionManager;
4142
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
4243
import org.schabi.newpipe.player.playqueue.PlayQueue;
4344
import org.schabi.newpipe.report.ErrorActivity;
4445
import org.schabi.newpipe.report.UserAction;
45-
import org.schabi.newpipe.util.AnimationUtils;
4646
import org.schabi.newpipe.util.ExtractorHelper;
4747
import org.schabi.newpipe.util.ImageDisplayConstants;
4848
import org.schabi.newpipe.util.Localization;
@@ -64,9 +64,9 @@
6464
import io.reactivex.rxjava3.functions.Function;
6565
import io.reactivex.rxjava3.schedulers.Schedulers;
6666

67-
import static org.schabi.newpipe.util.AnimationUtils.animateBackgroundColor;
68-
import static org.schabi.newpipe.util.AnimationUtils.animateTextColor;
69-
import static org.schabi.newpipe.util.AnimationUtils.animateView;
67+
import static org.schabi.newpipe.ktx.TextViewUtils.animateTextColor;
68+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
69+
import static org.schabi.newpipe.ktx.ViewUtils.animateBackgroundColor;
7070

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

225225
private void monitorSubscription(final ChannelInfo info) {
226226
final Consumer<Throwable> onError = (Throwable throwable) -> {
227-
animateView(headerBinding.channelSubscribeButton, false, 100);
227+
animate(headerBinding.channelSubscribeButton, false, 100);
228228
showSnackBarError(throwable, UserAction.SUBSCRIPTION,
229229
NewPipe.getNameOfService(currentInfo.getServiceId()),
230230
"Get subscription status", 0);
@@ -379,8 +379,8 @@ private void updateSubscribeButton(final boolean isSubscribed) {
379379
subscribedText);
380380
}
381381

382-
animateView(headerBinding.channelSubscribeButton, AnimationUtils.Type.LIGHT_SCALE_AND_ALPHA,
383-
true, 100);
382+
animate(headerBinding.channelSubscribeButton, true, 100,
383+
AnimationType.LIGHT_SCALE_AND_ALPHA);
384384
}
385385

386386
/*//////////////////////////////////////////////////////////////////////////
@@ -436,7 +436,7 @@ public void showLoading() {
436436
IMAGE_LOADER.cancelDisplayTask(headerBinding.channelBannerImage);
437437
IMAGE_LOADER.cancelDisplayTask(headerBinding.channelAvatarView);
438438
IMAGE_LOADER.cancelDisplayTask(headerBinding.subChannelAvatarView);
439-
animateView(headerBinding.channelSubscribeButton, false, 100);
439+
animate(headerBinding.channelSubscribeButton, false, 100);
440440
}
441441

442442
@Override

app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import org.schabi.newpipe.extractor.NewPipe;
1717
import org.schabi.newpipe.extractor.comments.CommentsInfo;
1818
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
19+
import org.schabi.newpipe.ktx.ViewUtils;
1920
import org.schabi.newpipe.report.UserAction;
20-
import org.schabi.newpipe.util.AnimationUtils;
2121
import org.schabi.newpipe.util.ExtractorHelper;
2222

2323
import io.reactivex.rxjava3.core.Single;
@@ -84,16 +84,14 @@ public void showLoading() {
8484
public void handleResult(@NonNull final CommentsInfo result) {
8585
super.handleResult(result);
8686

87-
AnimationUtils.slideUp(requireView(), 120, 150, 0.06f);
87+
ViewUtils.slideUp(requireView(), 120, 150, 0.06f);
8888

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

94-
if (disposables != null) {
95-
disposables.clear();
96-
}
94+
disposables.clear();
9795
}
9896

9997
@Override

app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import icepick.State;
2929
import io.reactivex.rxjava3.core.Single;
3030

31-
import static org.schabi.newpipe.util.AnimationUtils.animateView;
31+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
3232

3333
/**
3434
* Created by Christian Schabesberger on 23.09.17.
@@ -160,7 +160,7 @@ public Single<ListExtractor.InfoItemsPage> loadMoreItemsLogic() {
160160
@Override
161161
public void showLoading() {
162162
super.showLoading();
163-
animateView(itemsList, false, 100);
163+
animate(itemsList, false, 100);
164164
}
165165

166166
@Override

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
import io.reactivex.rxjava3.disposables.CompositeDisposable;
6262
import io.reactivex.rxjava3.disposables.Disposable;
6363

64-
import static org.schabi.newpipe.util.AnimationUtils.animateView;
64+
import static org.schabi.newpipe.ktx.ViewUtils.animate;
6565
import static org.schabi.newpipe.util.ThemeHelper.resolveResourceIdFromAttr;
6666

6767
public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
@@ -261,19 +261,19 @@ public boolean onOptionsItemSelected(final MenuItem item) {
261261
@Override
262262
public void showLoading() {
263263
super.showLoading();
264-
animateView(headerBinding.getRoot(), false, 200);
265-
animateView(itemsList, false, 100);
264+
animate(headerBinding.getRoot(), false, 200);
265+
animate(itemsList, false, 100);
266266

267267
IMAGE_LOADER.cancelDisplayTask(headerBinding.uploaderAvatarView);
268-
animateView(headerBinding.uploaderLayout, false, 200);
268+
animate(headerBinding.uploaderLayout, false, 200);
269269
}
270270

271271
@Override
272272
public void handleResult(@NonNull final PlaylistInfo result) {
273273
super.handleResult(result);
274274

275-
animateView(headerBinding.getRoot(), true, 100);
276-
animateView(headerBinding.uploaderLayout, true, 300);
275+
animate(headerBinding.getRoot(), true, 100);
276+
animate(headerBinding.uploaderLayout, true, 300);
277277
headerBinding.uploaderLayout.setOnClickListener(null);
278278
// If we have an uploader put them into the UI
279279
if (!TextUtils.isEmpty(result.getUploaderName())) {

0 commit comments

Comments
 (0)