From a7fbe05a735b2019e938f1ca60e1196881ea35a4 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Sat, 27 Jun 2020 06:25:50 +0300 Subject: [PATCH] Changes for review --- app/src/main/AndroidManifest.xml | 3 - .../java/org/schabi/newpipe/MainActivity.java | 9 +- .../org/schabi/newpipe/RouterActivity.java | 9 +- .../fragments/detail/VideoDetailFragment.java | 278 +++++------------- .../fragments/list/search/SearchFragment.java | 6 +- .../newpipe/player/BackgroundPlayer.java | 2 +- .../org/schabi/newpipe/player/BasePlayer.java | 33 ++- .../org/schabi/newpipe/player/MainPlayer.java | 4 +- .../schabi/newpipe/player/VideoPlayer.java | 10 +- .../newpipe/player/VideoPlayerImpl.java | 72 ++--- .../player/event/PlayerGestureListener.java | 28 +- .../newpipe/player/helper/AudioReactor.java | 2 +- .../newpipe/player/helper/PlayerHelper.java | 18 +- .../newpipe/streams/OggFromWebMWriter.java | 6 +- .../newpipe/streams/SubtitleConverter.java | 2 +- .../schabi/newpipe/streams/WebMWriter.java | 2 +- .../schabi/newpipe/util/NavigationHelper.java | 23 +- .../newpipe/views/ExpandableSurfaceView.java | 4 +- .../giga/postprocessing/Postprocessing.java | 2 +- .../giga/ui/adapter/MissionAdapter.java | 6 +- .../giga/ui/common/ProgressDrawable.java | 4 +- app/src/main/res/layout/toolbar_layout.xml | 9 - 22 files changed, 182 insertions(+), 350 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 18e424524..3136774e1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,9 +38,6 @@ - - NavigationHelper.installKore(context)) - .setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> { - }); - builder.create().show(); - } - - private void setupActionBarOnError(final String url) { - if (DEBUG) Log.d(TAG, "setupActionBarHandlerOnError() called with: url = [" + url + "]"); - Log.e("-----", "missing code"); - }*/ - - private void setupActionBar(final StreamInfo info) { - if (DEBUG) Log.d(TAG, "setupActionBarHandler() called with: info = [" + info + "]"); - boolean isExternalPlayerEnabled = PreferenceManager.getDefaultSharedPreferences(activity) - .getBoolean(activity.getString(R.string.use_external_video_player_key), false); - - sortedVideoStreams = ListHelper.getSortedStreamVideosList( - activity, - info.getVideoStreams(), - info.getVideoOnlyStreams(), - false); - selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(activity, sortedVideoStreams); - - /*final StreamItemAdapter streamsAdapter = - new StreamItemAdapter<>(activity, - new StreamSizeWrapper<>(sortedVideoStreams, activity), isExternalPlayerEnabled); - - spinnerToolbar.setAdapter(streamsAdapter); - spinnerToolbar.setSelection(selectedVideoStreamIndex); - spinnerToolbar.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - selectedVideoStreamIndex = position; - } - - @Override - public void onNothingSelected(AdapterView parent) { - } - });*/ - } - /*////////////////////////////////////////////////////////////////////////// // OwnStack //////////////////////////////////////////////////////////////////////////*/ @@ -866,7 +730,7 @@ public class VideoDetailFragment if (DEBUG) Log.d(TAG, "onBackPressed() called"); // If we are in fullscreen mode just exit from it via first back press - if (player != null && player.isInFullscreen()) { + if (player != null && player.isFullscreen()) { if (!PlayerHelper.isTablet(activity)) player.onPause(); restoreDefaultOrientation(); setAutoplay(false); @@ -874,11 +738,10 @@ public class VideoDetailFragment } // If we have something in history of played items we replay it here - boolean isPreviousCanBePlayed = player != null + if (player != null && player.getPlayQueue() != null && player.videoPlayerSelected() - && player.getPlayQueue().previous(); - if (isPreviousCanBePlayed) { + && player.getPlayQueue().previous()) { return true; } // That means that we are on the start of the stack, @@ -930,9 +793,8 @@ public class VideoDetailFragment } public void selectAndLoadVideo(int serviceId, String videoUrl, String name, PlayQueue playQueue) { - boolean streamIsTheSame = this.playQueue != null && this.playQueue.equals(playQueue); // Situation when user switches from players to main player. All needed data is here, we can start watching - if (streamIsTheSame) { + if (this.playQueue != null && this.playQueue.equals(playQueue)) { openVideoPlayer(); return; } @@ -1056,7 +918,7 @@ public class VideoDetailFragment .getBoolean(activity.getString(R.string.use_external_audio_player_key), false); // If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode - if (player != null && player.isInFullscreen()) player.toggleFullscreen(); + if (player != null && player.isFullscreen()) player.toggleFullscreen(); if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) { openNormalBackgroundPlayer(append); @@ -1072,18 +934,16 @@ public class VideoDetailFragment } // See UI changes while remote playQueue changes - if (!bounded) startService(false); + if (!bound) startService(false); // If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode - if (player != null && player.isInFullscreen()) player.toggleFullscreen(); + if (player != null && player.isFullscreen()) player.toggleFullscreen(); PlayQueue queue = setupPlayQueueForIntent(append); if (append) { NavigationHelper.enqueueOnPopupPlayer(activity, queue, false); } else { - Runnable onAllow = () -> NavigationHelper.playOnPopupPlayer(activity, queue, true); - if (shouldAskBeforeClearingQueue()) showClearingQueueConfirmation(onAllow); - else onAllow.run(); + replaceQueueIfUserConfirms(() -> NavigationHelper.playOnPopupPlayer(activity, queue, true)); } } @@ -1093,27 +953,23 @@ public class VideoDetailFragment VideoStream selectedVideoStream = getSelectedVideoStream(); startOnExternalPlayer(activity, currentInfo, selectedVideoStream); } else { - Runnable onAllow = this::openNormalPlayer; - if (shouldAskBeforeClearingQueue()) showClearingQueueConfirmation(onAllow); - else onAllow.run(); + replaceQueueIfUserConfirms(this::openMainPlayer); } } private void openNormalBackgroundPlayer(final boolean append) { // See UI changes while remote playQueue changes - if (!bounded) startService(false); + if (!bound) startService(false); PlayQueue queue = setupPlayQueueForIntent(append); if (append) { NavigationHelper.enqueueOnBackgroundPlayer(activity, queue, false); } else { - Runnable onAllow = () -> NavigationHelper.playOnBackgroundPlayer(activity, queue, true); - if (shouldAskBeforeClearingQueue()) showClearingQueueConfirmation(onAllow); - else onAllow.run(); + replaceQueueIfUserConfirms(() -> NavigationHelper.playOnBackgroundPlayer(activity, queue, true)); } } - private void openNormalPlayer() { + private void openMainPlayer() { if (playerService == null) { startService(true); return; @@ -1144,7 +1000,7 @@ public class VideoDetailFragment PlayQueue queue = playQueue; // Size can be 0 because queue removes bad stream automatically when error occurs - if (playQueue == null || playQueue.size() == 0) + if (queue == null || queue.size() == 0) queue = new SinglePlayQueue(currentInfo); return queue; @@ -1284,18 +1140,18 @@ public class VideoDetailFragment boolean isPortrait = metrics.heightPixels > metrics.widthPixels; int height; - if (player != null && player.isInFullscreen()) + if (player != null && player.isFullscreen()) height = isInMultiWindow() ? getView().getHeight() : activity.getWindow().getDecorView().getHeight(); else height = isPortrait ? (int) (metrics.widthPixels / (16.0f / 9.0f)) - : (int) (metrics.heightPixels / 2f); + : (int) (metrics.heightPixels / 2.0f); thumbnailImageView.setLayoutParams(new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height)); thumbnailImageView.setMinimumHeight(height); if (player != null) { int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT); - player.getSurfaceView().setHeights(height, player.isInFullscreen() ? height : maxHeight); + player.getSurfaceView().setHeights(height, player.isFullscreen() ? height : maxHeight); } } @@ -1353,7 +1209,7 @@ public class VideoDetailFragment private void restoreDefaultOrientation() { if (player == null || !player.videoPlayerSelected() || activity == null) return; - if (player != null && player.isInFullscreen()) player.toggleFullscreen(); + if (player != null && player.isFullscreen()) player.toggleFullscreen(); // This will show systemUI and pause the player. // User can tap on Play button and video will be in fullscreen mode again // Note for tablet: trying to avoid orientation changes since it's not easy to physically rotate the tablet every time @@ -1375,7 +1231,6 @@ public class VideoDetailFragment contentRootLayoutHiding.setVisibility(View.INVISIBLE); } - //animateView(spinnerToolbar, false, 200); animateView(thumbnailPlayButton, false, 50); animateView(detailDurationView, false, 100); animateView(detailPositionView, false, 100); @@ -1392,7 +1247,7 @@ public class VideoDetailFragment if(relatedStreamsLayout != null){ if(showRelatedStreams){ - relatedStreamsLayout.setVisibility(player != null && player.isInFullscreen() ? View.GONE : View.INVISIBLE); + relatedStreamsLayout.setVisibility(player != null && player.isFullscreen() ? View.GONE : View.INVISIBLE); }else{ relatedStreamsLayout.setVisibility(View.GONE); } @@ -1419,7 +1274,7 @@ public class VideoDetailFragment getChildFragmentManager().beginTransaction() .replace(R.id.relatedStreamsLayout, RelatedVideosFragment.getInstance(info)) .commitNow(); - relatedStreamsLayout.setVisibility(player != null && player.isInFullscreen() ? View.GONE : View.VISIBLE); + relatedStreamsLayout.setVisibility(player != null && player.isFullscreen() ? View.GONE : View.VISIBLE); } } @@ -1506,9 +1361,6 @@ public class VideoDetailFragment prepareDescription(info.getDescription()); updateProgressInfo(info); - - //animateView(spinnerToolbar, true, 500); - setupActionBar(info); initThumbnailViews(info); if (player == null || player.isPlayerStopped()) @@ -1527,7 +1379,6 @@ public class VideoDetailFragment case LIVE_STREAM: case AUDIO_LIVE_STREAM: detailControlsDownload.setVisibility(View.GONE); - spinnerToolbar.setVisibility(View.GONE); break; default: if(info.getAudioStreams().isEmpty()) detailControlsBackground.setVisibility(View.GONE); @@ -1535,7 +1386,6 @@ public class VideoDetailFragment || !info.getVideoOnlyStreams().isEmpty()) break; detailControlsPopup.setVisibility(View.GONE); - spinnerToolbar.setVisibility(View.GONE); thumbnailPlayButton.setImageResource(R.drawable.ic_headset_white_24dp); break; } @@ -1629,8 +1479,8 @@ public class VideoDetailFragment }, e -> { if (DEBUG) e.printStackTrace(); }, () -> { - animateView(positionView, false, 0); - animateView(detailPositionView, false, 0); + positionView.setVisibility(View.GONE); + detailPositionView.setVisibility(View.GONE); }); } @@ -1653,15 +1503,16 @@ public class VideoDetailFragment @Override public void onQueueUpdate(PlayQueue queue) { playQueue = queue; + StackItem stackWithQueue; // This should be the only place where we push data to stack. It will allow to have live instance of PlayQueue with actual // information about deleted/added items inside Channel/Playlist queue and makes possible to have a history of played items if (stack.isEmpty() || !stack.peek().getPlayQueue().equals(queue)) { stack.push(new StackItem(serviceId, url, name, playQueue)); - } else if (findQueueInStack(queue) != null) { + } else if ((stackWithQueue = findQueueInStack(queue)) != null) { // On every MainPlayer service's destroy() playQueue gets disposed and no longer able to track progress. // That's why we update our cached disposed queue with the new one that is active and have the same history // Without that the cached playQueue will have an old recovery position - findQueueInStack(queue).setPlayQueue(queue); + stackWithQueue.setPlayQueue(queue); } if (DEBUG) { @@ -1679,7 +1530,7 @@ public class VideoDetailFragment restoreDefaultOrientation(); break; case BasePlayer.STATE_PLAYING: - if (positionView.getAlpha() != 1f + if (positionView.getAlpha() != 1.0f && player.getPlayQueue() != null && player.getPlayQueue().getItem() != null && player.getPlayQueue().getItem().getUrl().equals(url)) { @@ -1725,7 +1576,7 @@ public class VideoDetailFragment public void onPlayerError(ExoPlaybackException error) { if (error.type == ExoPlaybackException.TYPE_SOURCE || error.type == ExoPlaybackException.TYPE_UNEXPECTED) { hideMainPlayer(); - if (playerService != null && player.isInFullscreen()) + if (playerService != null && player.isFullscreen()) player.toggleFullscreen(); } } @@ -1824,7 +1675,7 @@ public class VideoDetailFragment // Listener implementation public void hideSystemUiIfNeeded() { - if (player != null && player.isInFullscreen() && bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) + if (player != null && player.isFullscreen() && bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) hideSystemUi(); } @@ -1897,11 +1748,19 @@ public class VideoDetailFragment return item; } - private boolean shouldAskBeforeClearingQueue() { - PlayQueue activeQueue = player != null ? player.getPlayQueue() : null; + private void replaceQueueIfUserConfirms(final Runnable onAllow) { + @Nullable final PlayQueue activeQueue = player == null ? null : player.getPlayQueue(); + // Player will have STATE_IDLE when a user pressed back button - return isClearingQueueConfirmationRequired(activity) && playerIsNotStopped() - && activeQueue != null && !activeQueue.equals(playQueue) && activeQueue.getStreams().size() > 1; + if (isClearingQueueConfirmationRequired(activity) + && playerIsNotStopped() + && activeQueue != null + && !activeQueue.equals(playQueue) + && activeQueue.getStreams().size() > 1) { + showClearingQueueConfirmation(onAllow); + } else { + onAllow.run(); + } } private void showClearingQueueConfirmation(Runnable onAllow) { @@ -1964,13 +1823,13 @@ public class VideoDetailFragment // Disable click because overlay buttons located on top of buttons from the player setOverlayElementsClickable(false); hideSystemUiIfNeeded(); - boolean needToExpand = isLandscape() + // Conditions when the player should be expanded to fullscreen + if (isLandscape() && player != null && player.isPlaying() - && !player.isInFullscreen() + && !player.isFullscreen() && !PlayerHelper.isTablet(activity) - && player.videoPlayerSelected(); - if (needToExpand) player.toggleFullscreen(); + && player.videoPlayerSelected()) player.toggleFullscreen(); break; case BottomSheetBehavior.STATE_COLLAPSED: // Re-enable clicks @@ -1979,7 +1838,7 @@ public class VideoDetailFragment break; case BottomSheetBehavior.STATE_DRAGGING: case BottomSheetBehavior.STATE_SETTLING: - if (player != null && player.isInFullscreen()) showSystemUi(); + if (player != null && player.isFullscreen()) showSystemUi(); if (player != null && player.isControlsVisible()) player.hideControls(0, 0); break; } @@ -1997,8 +1856,8 @@ public class VideoDetailFragment } private void updateOverlayData(@Nullable String title, @Nullable String uploader, @Nullable String thumbnailUrl) { - overlayTitleTextView.setText(!TextUtils.isEmpty(title) ? title : ""); - overlayChannelTextView.setText(!TextUtils.isEmpty(uploader) ? uploader : ""); + overlayTitleTextView.setText(TextUtils.isEmpty(title) ? "" : title); + overlayChannelTextView.setText(TextUtils.isEmpty(uploader) ? "" : uploader); overlayThumbnailImageView.setImageResource(R.drawable.dummy_thumbnail_dark); if (!TextUtils.isEmpty(thumbnailUrl)) imageLoader.displayImage(thumbnailUrl, overlayThumbnailImageView, @@ -2006,8 +1865,7 @@ public class VideoDetailFragment } private void setOverlayPlayPauseImage() { - boolean playing = player != null && player.getPlayer().getPlayWhenReady(); - int attr = playing ? R.attr.pause : R.attr.play; + int attr = player != null && player.getPlayer().getPlayWhenReady() ? R.attr.pause : R.attr.play; overlayPlayPauseButton.setImageResource(ThemeHelper.resolveResourceIdFromAttr(activity, attr)); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index f2e8aa244..5fd470745 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -436,16 +436,16 @@ public class SearchFragment if (TextUtils.isEmpty(searchString) || TextUtils.isEmpty(searchEditText.getText())) { searchToolbarContainer.setTranslationX(100); - searchToolbarContainer.setAlpha(0f); + searchToolbarContainer.setAlpha(0.0f); searchToolbarContainer.setVisibility(View.VISIBLE); searchToolbarContainer.animate() .translationX(0) - .alpha(1f) + .alpha(1.0f) .setDuration(200) .setInterpolator(new DecelerateInterpolator()).start(); } else { searchToolbarContainer.setTranslationX(0); - searchToolbarContainer.setAlpha(1f); + searchToolbarContainer.setAlpha(1.0f); searchToolbarContainer.setVisibility(View.VISIBLE); } } diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index e408f49f6..99b38aae7 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -337,7 +337,7 @@ public final class BackgroundPlayer extends Service { @Override public void onPrepared(boolean playWhenReady) { super.onPrepared(playWhenReady); - simpleExoPlayer.setVolume(1f); + simpleExoPlayer.setVolume(1.0f); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 490419c64..c31654473 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -158,7 +158,7 @@ public abstract class BasePlayer implements // Playback //////////////////////////////////////////////////////////////////////////*/ - protected static final float[] PLAYBACK_SPEEDS = {0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f}; + protected static final float[] PLAYBACK_SPEEDS = {0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f}; protected PlayQueue playQueue; protected PlayQueueAdapter playQueueAdapter; @@ -227,7 +227,7 @@ public abstract class BasePlayer implements public void setup() { if (simpleExoPlayer == null) { - initPlayer(/*playOnInit=*/true); + initPlayer(true); } initListeners(); } @@ -274,7 +274,7 @@ public abstract class BasePlayer implements return; } - boolean same = playQueue != null && playQueue.equals(queue); + boolean samePlayQueue = playQueue != null && playQueue.equals(queue); final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); final float playbackSpeed = intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed()); @@ -282,6 +282,14 @@ public abstract class BasePlayer implements final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE, getPlaybackSkipSilence()); + /* + * There are 3 situations when playback shouldn't be started from scratch (zero timestamp): + * 1. User pressed on a timestamp link and the same video should be rewound to that timestamp + * 2. User changed a player from, for example. main to popup, or from audio to main, etc + * 3. User chose to resume a video based on a saved timestamp from history of played videos + * In those cases time will be saved because re-init of the play queue is a not an instant task + * and requires network calls + * */ // seek to timestamp if stream is already playing if (simpleExoPlayer != null && queue.size() == 1 @@ -289,21 +297,20 @@ public abstract class BasePlayer implements && playQueue.size() == 1 && playQueue.getItem() != null && queue.getItem().getUrl().equals(playQueue.getItem().getUrl()) - && queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET - && simpleExoPlayer.getPlaybackState() != Player.STATE_IDLE) { + && queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET) { // Player can have state = IDLE when playback is stopped or failed and we should retry() in this case if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) simpleExoPlayer.retry(); simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition()); return; - } else if (same && !playQueue.isDisposed() && simpleExoPlayer != null) { + } else if (samePlayQueue && !playQueue.isDisposed() && simpleExoPlayer != null) { // Do not re-init the same PlayQueue. Save time // Player can have state = IDLE when playback is stopped or failed and we should retry() in this case if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) simpleExoPlayer.retry(); return; } else if (intent.getBooleanExtra(RESUME_PLAYBACK, false) && isPlaybackResumeEnabled() - && !same) { + && !samePlayQueue) { final PlayQueueItem item = queue.getItem(); if (item != null && item.getRecoveryPosition() == PlayQueueItem.RECOVERY_UNSET) { stateLoader = recordManager.loadStreamState(item) @@ -313,19 +320,16 @@ public abstract class BasePlayer implements .subscribe( state -> { queue.setRecovery(queue.getIndex(), state.getProgressTime()); - initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, - /*playOnInit=*/true); + initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true); }, error -> { if (DEBUG) error.printStackTrace(); // In case any error we can start playback without history - initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, - /*playOnInit=*/true); + initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true); }, () -> { // Completed but not found in history - initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, - /*playOnInit=*/true); + initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true); } ); databaseUpdateReactor.add(stateLoader); @@ -334,8 +338,7 @@ public abstract class BasePlayer implements } // Good to go... // In a case of equal PlayQueues we can re-init old one but only when it is disposed - initPlayback(same ? playQueue : queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, - /*playOnInit=*/true); + initPlayback(samePlayQueue ? playQueue : queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, true); } protected void initPlayback(@NonNull final PlayQueue queue, diff --git a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java index 61b69ac5e..f1f9b51da 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java @@ -184,8 +184,6 @@ public final class MainPlayer extends Service { playerImpl.destroy(); } if (notificationManager != null) notificationManager.cancel(NOTIFICATION_ID); - playerImpl = null; - lockManager = null; stopForeground(true); stopSelf(); @@ -197,7 +195,7 @@ public final class MainPlayer extends Service { boolean isLandscape() { // DisplayMetrics from activity context knows about MultiWindow feature while DisplayMetrics from app context doesn't - final DisplayMetrics metrics = playerImpl != null && playerImpl.getParentActivity() != null ? + final DisplayMetrics metrics = (playerImpl != null && playerImpl.getParentActivity() != null) ? playerImpl.getParentActivity().getResources().getDisplayMetrics() : getResources().getDisplayMetrics(); return metrics.heightPixels < metrics.widthPixels; diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index c29cfd19c..632044b06 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -797,9 +797,9 @@ public abstract class VideoPlayer extends BasePlayer if (drawableId == -1) { if (controlAnimationView.getVisibility() == View.VISIBLE) { controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, - PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f), - PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1f), - PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1f) + PropertyValuesHolder.ofFloat(View.ALPHA, 1.0f, 0.0f), + PropertyValuesHolder.ofFloat(View.SCALE_X, 1.4f, 1.0f), + PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.4f, 1.0f) ).setDuration(DEFAULT_CONTROLS_DURATION); controlViewAnimator.addListener(new AnimatorListenerAdapter() { @Override @@ -812,8 +812,8 @@ public abstract class VideoPlayer extends BasePlayer return; } - float scaleFrom = goneOnEnd ? 1f : 1f, scaleTo = goneOnEnd ? 1.8f : 1.4f; - float alphaFrom = goneOnEnd ? 1f : 0f, alphaTo = goneOnEnd ? 0f : 1f; + float scaleFrom = goneOnEnd ? 1.0f : 1.0f, scaleTo = goneOnEnd ? 1.8f : 1.4f; + float alphaFrom = goneOnEnd ? 1.0f : 0.0f, alphaTo = goneOnEnd ? 0.0f : 1.0f; controlViewAnimator = ObjectAnimator.ofPropertyValuesHolder(controlAnimationView, diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index efbe06457..aad20b0ad 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -270,14 +270,14 @@ public class VideoPlayerImpl extends VideoPlayer final float captionScale, @NonNull final CaptionStyleCompat captionStyle) { if (popupPlayerSelected()) { - float captionRatio = (captionScale - 1f) / 5f + 1f; + float captionRatio = (captionScale - 1.0f) / 5.0f + 1.0f; view.setFractionalTextSize(SubtitleView.DEFAULT_TEXT_SIZE_FRACTION * captionRatio); view.setApplyEmbeddedStyles(captionStyle.equals(CaptionStyleCompat.DEFAULT)); view.setStyle(captionStyle); } else { final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels); - final float captionRatioInverse = 20f + 4f * (1f - captionScale); + final float captionRatioInverse = 20f + 4f * (1.0f - captionScale); view.setFixedTextSize(TypedValue.COMPLEX_UNIT_PX, (float) minimumLength / captionRatioInverse); view.setApplyEmbeddedStyles(captionStyle.equals(CaptionStyleCompat.DEFAULT)); @@ -300,7 +300,7 @@ public class VideoPlayerImpl extends VideoPlayer moreOptionsButton.setVisibility(View.GONE); getTopControlsRoot().setOrientation(LinearLayout.HORIZONTAL); primaryControls.getLayoutParams().width = LinearLayout.LayoutParams.WRAP_CONTENT; - secondaryControls.setAlpha(1f); + secondaryControls.setAlpha(1.0f); secondaryControls.setVisibility(View.VISIBLE); secondaryControls.setTranslationY(0); shareButton.setVisibility(View.GONE); @@ -333,7 +333,7 @@ public class VideoPlayerImpl extends VideoPlayer getTopControlsRoot().setClickable(true); getTopControlsRoot().setFocusable(true); } - if (!isInFullscreen()) { + if (!isFullscreen()) { titleTextView.setVisibility(View.GONE); channelTextView.setVisibility(View.GONE); } else { @@ -602,10 +602,10 @@ public class VideoPlayerImpl extends VideoPlayer isFullscreen = !isFullscreen; setControlsSize(); - fragmentListener.onFullscreenStateChanged(isInFullscreen()); + fragmentListener.onFullscreenStateChanged(isFullscreen()); } - if (!isInFullscreen()) { + if (!isFullscreen()) { titleTextView.setVisibility(View.GONE); channelTextView.setVisibility(View.GONE); playerCloseButton.setVisibility(videoPlayerSelected() ? View.VISIBLE : View.GONE); @@ -674,7 +674,7 @@ public class VideoPlayerImpl extends VideoPlayer @Override public boolean onLongClick(View v) { - if (v.getId() == moreOptionsButton.getId() && isInFullscreen()) { + if (v.getId() == moreOptionsButton.getId() && isFullscreen()) { fragmentListener.onMoreOptionsLongClicked(); hideControls(0, 0); hideSystemUIIfNeeded(); @@ -690,7 +690,7 @@ public class VideoPlayerImpl extends VideoPlayer updatePlaybackButtons(); getControlsRoot().setVisibility(View.INVISIBLE); - animateView(queueLayout, SLIDE_AND_ALPHA, /*visible=*/true, + animateView(queueLayout, SLIDE_AND_ALPHA,true, DEFAULT_CONTROLS_DURATION); itemsList.scrollToPosition(playQueue.getIndex()); @@ -699,7 +699,7 @@ public class VideoPlayerImpl extends VideoPlayer public void onQueueClosed() { if (!queueVisible) return; - animateView(queueLayout, SLIDE_AND_ALPHA, /*visible=*/false, + animateView(queueLayout, SLIDE_AND_ALPHA,false, DEFAULT_CONTROLS_DURATION, 0, () -> { // Even when queueLayout is GONE it receives touch events and ruins normal behavior of the app. This line fixes it queueLayout.setTranslationY(-queueLayout.getHeight() * 5); @@ -765,12 +765,12 @@ public class VideoPlayerImpl extends VideoPlayer boolean showButton = videoPlayerSelected() && (orientationLocked || isVerticalVideo || tabletInLandscape); screenRotationButton.setVisibility(showButton ? View.VISIBLE : View.GONE); screenRotationButton.setImageDrawable(service.getResources().getDrawable( - isInFullscreen() ? R.drawable.ic_fullscreen_exit_white : R.drawable.ic_fullscreen_white)); + isFullscreen() ? R.drawable.ic_fullscreen_exit_white : R.drawable.ic_fullscreen_white)); } private void prepareOrientation() { boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service); - if (orientationLocked && isInFullscreen() && service.isLandscape() == isVerticalVideo && fragmentListener != null) + if (orientationLocked && isFullscreen() && service.isLandscape() == isVerticalVideo && fragmentListener != null) fragmentListener.onScreenRotationButtonClicked(); } @@ -893,7 +893,7 @@ public class VideoPlayerImpl extends VideoPlayer @Override public void onBlocked() { super.onBlocked(); - playPauseButton.setImageResource(R.drawable.ic_pause_white); + playPauseButton.setImageResource(R.drawable.ic_play_arrow_white); animatePlayButtons(false, 100); getRootView().setKeepScreenOn(false); @@ -1185,7 +1185,7 @@ public class VideoPlayerImpl extends VideoPlayer return distanceFromCloseButton(popupMotionEvent) <= getClosingRadius(); } - public boolean isInFullscreen() { + public boolean isFullscreen() { return isFullscreen; } @@ -1216,8 +1216,7 @@ public class VideoPlayerImpl extends VideoPlayer getControlsVisibilityHandler().removeCallbacksAndMessages(null); getControlsVisibilityHandler().postDelayed(() -> animateView(getControlsRoot(), false, duration, 0, - this::hideSystemUIIfNeeded), - /*delayMillis=*/delay + this::hideSystemUIIfNeeded), delay ); } @@ -1225,24 +1224,13 @@ public class VideoPlayerImpl extends VideoPlayer if (playQueue == null) return; - if (playQueue.getIndex() == 0) - playPreviousButton.setVisibility(View.INVISIBLE); - else - playPreviousButton.setVisibility(View.VISIBLE); - - if (playQueue.getIndex() + 1 == playQueue.getStreams().size()) - playNextButton.setVisibility(View.INVISIBLE); - else - playNextButton.setVisibility(View.VISIBLE); - - if (playQueue.getStreams().size() <= 1 || popupPlayerSelected()) - queueButton.setVisibility(View.GONE); - else - queueButton.setVisibility(View.VISIBLE); + playPreviousButton.setVisibility(playQueue.getIndex() == 0 ? View.INVISIBLE : View.VISIBLE); + playNextButton.setVisibility(playQueue.getIndex() + 1 == playQueue.getStreams().size() ? View.INVISIBLE : View.VISIBLE); + queueButton.setVisibility(playQueue.getStreams().size() <= 1 || popupPlayerSelected() ? View.GONE : View.VISIBLE); } private void showSystemUIPartially() { - if (isInFullscreen() && getParentActivity() != null) { + if (isFullscreen() && getParentActivity() != null) { int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE; getParentActivity().getWindow().getDecorView().setSystemUiVisibility(visibility); } @@ -1330,7 +1318,7 @@ public class VideoPlayerImpl extends VideoPlayer public void checkLandscape() { AppCompatActivity parent = getParentActivity(); - boolean videoInLandscapeButNotInFullscreen = service.isLandscape() && !isInFullscreen() && videoPlayerSelected() && !audioOnly; + boolean videoInLandscapeButNotInFullscreen = service.isLandscape() && !isFullscreen() && videoPlayerSelected() && !audioOnly; boolean playingState = getCurrentState() != STATE_COMPLETED && getCurrentState() != STATE_PAUSED; if (parent != null && videoInLandscapeButNotInFullscreen && playingState && !PlayerHelper.isTablet(service)) toggleFullscreen(); @@ -1421,7 +1409,7 @@ public class VideoPlayerImpl extends VideoPlayer if (DEBUG) Log.d(TAG, "initPopup() called"); // Popup is already added to windowManager - if (isPopupHasParent()) return; + if (popupHasParent()) return; updateScreenSize(); @@ -1430,13 +1418,10 @@ public class VideoPlayerImpl extends VideoPlayer SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(service); popupWidth = popupRememberSizeAndPos ? sharedPreferences.getFloat(POPUP_SAVED_WIDTH, defaultSize) : defaultSize; popupHeight = getMinimumVideoHeight(popupWidth); - final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? - WindowManager.LayoutParams.TYPE_PHONE : - WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; popupLayoutParams = new WindowManager.LayoutParams( (int) popupWidth, (int) popupHeight, - layoutParamType, + popupLayoutParamType(), IDLE_WINDOW_FLAGS, PixelFormat.TRANSLUCENT); popupLayoutParams.gravity = Gravity.LEFT | Gravity.TOP; @@ -1470,15 +1455,12 @@ public class VideoPlayerImpl extends VideoPlayer closeOverlayView = View.inflate(service, R.layout.player_popup_close_overlay, null); closeOverlayButton = closeOverlayView.findViewById(R.id.closeButton); - final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? - WindowManager.LayoutParams.TYPE_PHONE : - WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; final int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; WindowManager.LayoutParams closeOverlayLayoutParams = new WindowManager.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, - layoutParamType, + popupLayoutParamType(), flags, PixelFormat.TRANSLUCENT); closeOverlayLayoutParams.gravity = Gravity.LEFT | Gravity.TOP; @@ -1600,6 +1582,12 @@ public class VideoPlayerImpl extends VideoPlayer windowManager.updateViewLayout(getRootView(), popupLayoutParams); } + private int popupLayoutParamType() { + return Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? + WindowManager.LayoutParams.TYPE_PHONE : + WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + } + /*////////////////////////////////////////////////////////////////////////// // Misc //////////////////////////////////////////////////////////////////////////*/ @@ -1617,7 +1605,7 @@ public class VideoPlayerImpl extends VideoPlayer public void removePopupFromView() { boolean isCloseOverlayHasParent = closeOverlayView != null && closeOverlayView.getParent() != null; - if (isPopupHasParent()) + if (popupHasParent()) windowManager.removeView(getRootView()); if (isCloseOverlayHasParent) windowManager.removeView(closeOverlayView); @@ -1651,7 +1639,7 @@ public class VideoPlayerImpl extends VideoPlayer }).start(); } - private boolean isPopupHasParent() { + private boolean popupHasParent() { View root = getRootView(); return root != null && root.getLayoutParams() instanceof WindowManager.LayoutParams && root.getParent() != null; } diff --git a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java index bb9ede4d7..f8b402103 100644 --- a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java +++ b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java @@ -160,10 +160,7 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen isMovingInMain = true; - boolean acceptVolumeArea = initialEvent.getX() > playerImpl.getRootView().getWidth() / 2.0; - boolean acceptBrightnessArea = initialEvent.getX() <= playerImpl.getRootView().getWidth() / 2.0; - - if (isVolumeGestureEnabled && acceptVolumeArea) { + if (isVolumeGestureEnabled && initialEvent.getX() > playerImpl.getRootView().getWidth() / 2.0) { playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY); float currentProgressPercent = (float) playerImpl.getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength(); @@ -172,14 +169,11 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen if (DEBUG) Log.d(TAG, "onScroll().volumeControl, currentVolume = " + currentVolume); - final int resId = - currentProgressPercent <= 0 ? R.drawable.ic_volume_off_white_72dp + playerImpl.getVolumeImageView().setImageDrawable( + AppCompatResources.getDrawable(service, currentProgressPercent <= 0 ? R.drawable.ic_volume_off_white_72dp : currentProgressPercent < 0.25 ? R.drawable.ic_volume_mute_white_72dp : currentProgressPercent < 0.75 ? R.drawable.ic_volume_down_white_72dp - : R.drawable.ic_volume_up_white_72dp; - - playerImpl.getVolumeImageView().setImageDrawable( - AppCompatResources.getDrawable(service, resId) + : R.drawable.ic_volume_up_white_72dp) ); if (playerImpl.getVolumeRelativeLayout().getVisibility() != View.VISIBLE) { @@ -188,7 +182,7 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen if (playerImpl.getBrightnessRelativeLayout().getVisibility() == View.VISIBLE) { playerImpl.getBrightnessRelativeLayout().setVisibility(View.GONE); } - } else if (isBrightnessGestureEnabled && acceptBrightnessArea) { + } else if (isBrightnessGestureEnabled && initialEvent.getX() <= playerImpl.getRootView().getWidth() / 2.0) { Activity parent = playerImpl.getParentActivity(); if (parent == null) return true; @@ -203,13 +197,11 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen if (DEBUG) Log.d(TAG, "onScroll().brightnessControl, currentBrightness = " + currentProgressPercent); - final int resId = - currentProgressPercent < 0.25 ? R.drawable.ic_brightness_low_white_72dp - : currentProgressPercent < 0.75 ? R.drawable.ic_brightness_medium_white_72dp - : R.drawable.ic_brightness_high_white_72dp; - playerImpl.getBrightnessImageView().setImageDrawable( - AppCompatResources.getDrawable(service, resId) + AppCompatResources.getDrawable(service, + currentProgressPercent < 0.25 ? R.drawable.ic_brightness_low_white_72dp + : currentProgressPercent < 0.75 ? R.drawable.ic_brightness_medium_white_72dp + : R.drawable.ic_brightness_high_white_72dp) ); if (playerImpl.getBrightnessRelativeLayout().getVisibility() != View.VISIBLE) { @@ -247,7 +239,7 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: - v.getParent().requestDisallowInterceptTouchEvent(playerImpl.isInFullscreen()); + v.getParent().requestDisallowInterceptTouchEvent(playerImpl.isFullscreen()); return true; case MotionEvent.ACTION_UP: v.getParent().requestDisallowInterceptTouchEvent(false); diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java index 8f344390a..ff9d0c477 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java @@ -114,7 +114,7 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, private void onAudioFocusGain() { Log.d(TAG, "onAudioFocusGain() called"); player.setVolume(DUCK_AUDIO_TO); - animateAudio(DUCK_AUDIO_TO, 1f); + animateAudio(DUCK_AUDIO_TO, 1.0f); if (PlayerHelper.isResumeAfterAudioFocusGain(context)) { player.setPlayWhenReady(true); diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 6afb5a322..82003231d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -222,14 +222,10 @@ public class PlayerHelper { @AutoplayType public static int getAutoplayType(@NonNull final Context context) { - final String defaultType = context.getString(R.string.autoplay_wifi_key); - final String always = context.getString(R.string.autoplay_always_key); - final String never = context.getString(R.string.autoplay_never_key); - - final String type = getAutoplayType(context, defaultType); - if (type.equals(always)) { + final String type = getAutoplayType(context, context.getString(R.string.autoplay_wifi_key)); + if (type.equals(context.getString(R.string.autoplay_always_key))) { return AUTOPLAY_TYPE_ALWAYS; - } else if (type.equals(never)) { + } else if (type.equals(context.getString(R.string.autoplay_never_key))) { return AUTOPLAY_TYPE_NEVER; } else { return AUTOPLAY_TYPE_WIFI; @@ -307,12 +303,12 @@ public class PlayerHelper { * Very small - 0.25f, Small - 0.5f, Normal - 1.0f, Large - 1.5f, Very Large - 2.0f * */ public static float getCaptionScale(@NonNull final Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return 1f; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return 1.0f; final CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); if (captioningManager == null || !captioningManager.isEnabled()) { - return 1f; + return 1.0f; } return captioningManager.getFontScale(); @@ -330,8 +326,8 @@ public class PlayerHelper { public static boolean globalScreenOrientationLocked(Context context) { // 1: Screen orientation changes using accelerometer // 0: Screen orientation is locked - return !(android.provider.Settings.System.getInt( - context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1); + return android.provider.Settings.System.getInt( + context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 0; } public static boolean isTablet(@NonNull final Context context) { diff --git a/app/src/main/java/org/schabi/newpipe/streams/OggFromWebMWriter.java b/app/src/main/java/org/schabi/newpipe/streams/OggFromWebMWriter.java index 16bffea9a..5a5a9e1fd 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/OggFromWebMWriter.java +++ b/app/src/main/java/org/schabi/newpipe/streams/OggFromWebMWriter.java @@ -158,7 +158,7 @@ public class OggFromWebMWriter implements Closeable { switch (webm_track.kind) { case Audio: resolution = getSampleFrequencyFromTrack(webm_track.bMetadata); - if (resolution == 0f) { + if (resolution == 0.0f) { throw new RuntimeException("cannot get the audio sample rate"); } break; @@ -167,7 +167,7 @@ public class OggFromWebMWriter implements Closeable { if (webm_track.defaultDuration == 0) { throw new RuntimeException("missing default frame time"); } - resolution = 1000f / ((float) webm_track.defaultDuration / webm_segment.info.timecodeScale); + resolution = 1000.0f / ((float) webm_track.defaultDuration / webm_segment.info.timecodeScale); break; default: throw new RuntimeException("not implemented"); @@ -358,7 +358,7 @@ public class OggFromWebMWriter implements Closeable { } } - return 0f; + return 0.0f; } private void clearSegmentTable() { diff --git a/app/src/main/java/org/schabi/newpipe/streams/SubtitleConverter.java b/app/src/main/java/org/schabi/newpipe/streams/SubtitleConverter.java index c41db4373..9c6fa977d 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/SubtitleConverter.java +++ b/app/src/main/java/org/schabi/newpipe/streams/SubtitleConverter.java @@ -292,7 +292,7 @@ public class SubtitleConverter { time += Integer.parseInt(units[0]) * 3600000;// hours time += Integer.parseInt(units[1]) * 60000;//minutes - time += Float.parseFloat(units[2]) * 1000f;// seconds and milliseconds (if present) + time += Float.parseFloat(units[2]) * 1000.0f;// seconds and milliseconds (if present) // frames and sub-frames are ignored (not implemented) // time += units[3] * fps; diff --git a/app/src/main/java/org/schabi/newpipe/streams/WebMWriter.java b/app/src/main/java/org/schabi/newpipe/streams/WebMWriter.java index 8525fabd2..fa2cc43e2 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/WebMWriter.java +++ b/app/src/main/java/org/schabi/newpipe/streams/WebMWriter.java @@ -612,7 +612,7 @@ public class WebMWriter implements Closeable { int offset = withLength ? 1 : 0; byte[] buffer = new byte[offset + length]; - long marker = (long) Math.floor((length - 1f) / 8f); + long marker = (long) Math.floor((length - 1.0f) / 8.0f); float mul = 1; for (int i = length - 1; i >= 0; i--, mul *= 0x100) { diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 8b867a328..f0fd7e41b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -73,9 +73,7 @@ public class NavigationHelper { if (cacheKey != null) intent.putExtra(VideoPlayer.PLAY_QUEUE_KEY, cacheKey); if (quality != null) intent.putExtra(VideoPlayer.PLAYBACK_QUALITY, quality); intent.putExtra(VideoPlayer.RESUME_PLAYBACK, resumePlayback); - - int playerType = intent.getIntExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO); - intent.putExtra(VideoPlayer.PLAYER_TYPE, playerType); + intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_VIDEO); return intent; } @@ -122,7 +120,24 @@ public class NavigationHelper { public static void playOnMainPlayer(final FragmentManager fragmentManager, final PlayQueue queue, boolean autoPlay) { PlayQueueItem currentStream = queue.getItem(); - NavigationHelper.openVideoDetailFragment(fragmentManager, currentStream.getServiceId(), currentStream.getUrl(), currentStream.getTitle(), autoPlay, queue); + openVideoDetailFragment(fragmentManager, currentStream.getServiceId(), currentStream.getUrl(), currentStream.getTitle(), autoPlay, queue); + } + + public static void playOnMainPlayer(@NonNull final Context context, + @NonNull final PlayQueue queue, + @NonNull final StreamingService.LinkType linkType, + @NonNull final String url, + @NonNull final String title, + final boolean autoPlay, + final boolean resumePlayback) { + + Intent intent = getPlayerIntent(context, MainActivity.class, queue, resumePlayback); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.putExtra(Constants.KEY_LINK_TYPE, linkType); + intent.putExtra(Constants.KEY_URL, url); + intent.putExtra(Constants.KEY_TITLE, title); + intent.putExtra(VideoDetailFragment.AUTO_PLAY, autoPlay); + context.startActivity(intent); } public static void playOnPopupPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) { diff --git a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java index df012eafd..f5a7df471 100644 --- a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java +++ b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java @@ -11,7 +11,7 @@ public class ExpandableSurfaceView extends SurfaceView { private int resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT; private int baseHeight = 0; private int maxHeight = 0; - private float videoAspectRatio = 0f; + private float videoAspectRatio = 0.0f; private float scaleX = 1.0f; private float scaleY = 1.0f; @@ -22,7 +22,7 @@ public class ExpandableSurfaceView extends SurfaceView { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); - if (videoAspectRatio == 0f) return; + if (videoAspectRatio == 0.0f) return; int width = MeasureSpec.getSize(widthMeasureSpec); boolean verticalVideo = videoAspectRatio < 1; diff --git a/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java b/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java index 773ff92d1..bf9202a75 100644 --- a/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java +++ b/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java @@ -89,7 +89,7 @@ public abstract class Postprocessing implements Serializable { } public void setTemporalDir(@NonNull File directory) { - long rnd = (int) (Math.random() * 100000f); + long rnd = (int) (Math.random() * 100000.0f); tempFile = new File(directory, rnd + "_" + System.nanoTime() + ".tmp"); } diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index 8420e343b..aa7e42abc 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -198,7 +198,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb } else { h.progress.setMarquee(false); h.status.setText("100%"); - h.progress.setProgress(1f); + h.progress.setProgress(1.0f); h.size.setText(Utility.formatBytes(item.mission.length)); } } @@ -231,7 +231,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb double progress; if (mission.unknownLength) { progress = Double.NaN; - h.progress.setProgress(0f); + h.progress.setProgress(0.0f); } else { progress = done / length; } @@ -298,7 +298,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb for (int i = 0; i < h.lastSpeed.length; i++) { averageSpeed += h.lastSpeed[i]; } - averageSpeed /= h.lastSpeed.length + 1f; + averageSpeed /= h.lastSpeed.length + 1.0f; } String speedStr = Utility.formatSpeed(averageSpeed); diff --git a/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java b/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java index 3f638d418..bec947540 100644 --- a/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java +++ b/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java @@ -26,7 +26,7 @@ public class ProgressDrawable extends Drawable { public ProgressDrawable() { mMarqueeLine = null;// marquee disabled - mMarqueeProgress = 0f; + mMarqueeProgress = 0.0f; mMarqueeSize = 0; mMarqueeNext = 0; } @@ -122,7 +122,7 @@ public class ProgressDrawable extends Drawable { } private void setupMarquee(int width, int height) { - mMarqueeSize = (int) ((width * 10f) / 100f);// the size is 10% of the width + mMarqueeSize = (int) ((width * 10.0f) / 100.0f);// the size is 10% of the width mMarqueeLine.rewind(); mMarqueeLine.moveTo(-mMarqueeSize, -mMarqueeSize); diff --git a/app/src/main/res/layout/toolbar_layout.xml b/app/src/main/res/layout/toolbar_layout.xml index 5d224bda8..318d16ff5 100644 --- a/app/src/main/res/layout/toolbar_layout.xml +++ b/app/src/main/res/layout/toolbar_layout.xml @@ -19,15 +19,6 @@ app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar" app:titleTextAppearance="@style/Toolbar.Title"> - -