1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Improved an animation logic

This commit is contained in:
Avently 2020-08-16 22:44:27 +03:00
parent d7574973e9
commit aed1687a45

View File

@ -1769,10 +1769,11 @@ public class VideoDetailFragment
private void showPlaybackProgress(final long progress, final long duration) { private void showPlaybackProgress(final long progress, final long duration) {
final int progressSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(progress); final int progressSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(progress);
final int durationSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(duration); final int durationSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(duration);
// If the old and the new progress values have a big difference then use
// animation. Otherwise don't because it affects CPU
final boolean shouldAnimate = Math.abs(positionView.getProgress() - progressSeconds) > 2;
positionView.setMax(durationSeconds); positionView.setMax(durationSeconds);
// If there is no player inside fragment use animation, otherwise don't because if (shouldAnimate) {
// it affects CPU
if (playerPlaceholder.getChildCount() == 0) {
positionView.setProgressAnimated(progressSeconds); positionView.setProgressAnimated(progressSeconds);
} else { } else {
positionView.setProgress(progressSeconds); positionView.setProgress(progressSeconds);