From b2164ce5fcc3111d8cd1f503657524aceaee30c7 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Sun, 12 Jul 2020 03:59:47 +0300 Subject: [PATCH] Marked many (too many) variables as final --- .../material/appbar/FlingBehavior.java | 6 +- .../java/org/schabi/newpipe/MainActivity.java | 9 +- .../newpipe/fragments/detail/StackItem.java | 2 +- .../fragments/detail/VideoDetailFragment.java | 278 +++++++++--------- .../org/schabi/newpipe/player/BasePlayer.java | 2 +- .../org/schabi/newpipe/player/MainPlayer.java | 14 +- .../newpipe/player/ServicePlayerActivity.java | 2 +- .../newpipe/player/VideoPlayerImpl.java | 121 ++++---- .../event/CustomBottomSheetBehavior.java | 8 +- .../player/event/PlayerGestureListener.java | 31 +- .../newpipe/player/playqueue/PlayQueue.java | 17 +- .../schabi/newpipe/util/NavigationHelper.java | 65 ++-- .../newpipe/views/ExpandableSurfaceView.java | 13 +- 13 files changed, 295 insertions(+), 273 deletions(-) diff --git a/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java b/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java index d8c5fd014..95137414e 100644 --- a/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java +++ b/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java @@ -23,13 +23,13 @@ public final class FlingBehavior extends AppBarLayout.Behavior { } private boolean allowScroll = true; - private Rect globalRect = new Rect(); + private final Rect globalRect = new Rect(); @Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout child, MotionEvent ev) { - ViewGroup playQueue = child.findViewById(R.id.playQueuePanel); + final ViewGroup playQueue = child.findViewById(R.id.playQueuePanel); if (playQueue != null) { - boolean visible = playQueue.getGlobalVisibleRect(globalRect); + final boolean visible = playQueue.getGlobalVisibleRect(globalRect); if (visible && globalRect.contains((int) ev.getRawX(), (int) ev.getRawY())) { allowScroll = false; return false; diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index f63003661..2fb5d616a 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -45,7 +45,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.navigation.NavigationView; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance; @@ -453,21 +452,21 @@ public class MainActivity extends AppCompatActivity { public void onBackPressed() { if (DEBUG) Log.d(TAG, "onBackPressed() called"); - FrameLayout bottomSheetLayout = findViewById(R.id.fragment_player_holder); - BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout); + final FrameLayout bottomSheetLayout = findViewById(R.id.fragment_player_holder); + final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout); final int sheetState = bottomSheetBehavior.getState(); // In case bottomSheet is not visible on the screen or collapsed we can assume that the user interacts with a fragment // inside fragment_holder so all back presses should be handled by it if (sheetState == BottomSheetBehavior.STATE_HIDDEN || sheetState == BottomSheetBehavior.STATE_COLLAPSED) { - Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder); + final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder); // If current fragment implements BackPressable (i.e. can/wanna handle back press) delegate the back press to it if (fragment instanceof BackPressable) { if (((BackPressable) fragment).onBackPressed()) return; } } else { - Fragment fragmentPlayer = getSupportFragmentManager().findFragmentById(R.id.fragment_player_holder); + final Fragment fragmentPlayer = getSupportFragmentManager().findFragmentById(R.id.fragment_player_holder); // If current fragment implements BackPressable (i.e. can/wanna handle back press) delegate the back press to it if (fragmentPlayer instanceof BackPressable) { if (!((BackPressable) fragmentPlayer).onBackPressed()) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java index 38e41b2fb..ca96b5f96 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java @@ -10,7 +10,7 @@ class StackItem implements Serializable { private String url; private PlayQueue playQueue; - StackItem(int serviceId, String url, String title, PlayQueue playQueue) { + StackItem(final int serviceId, final String url, final String title, final PlayQueue playQueue) { this.serviceId = serviceId; this.url = url; this.title = title; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 9d6d20c0d..060f95b68 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -73,10 +73,7 @@ import org.schabi.newpipe.util.*; import org.schabi.newpipe.views.AnimatedProgressBar; import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; +import java.util.*; import java.util.concurrent.TimeUnit; import icepick.State; @@ -143,7 +140,7 @@ public class VideoDetailFragment private List sortedVideoStreams; private int selectedVideoStreamIndex = -1; - private BottomSheetBehavior bottomSheetBehavior; + private BottomSheetBehavior bottomSheetBehavior; private BroadcastReceiver broadcastReceiver; /*////////////////////////////////////////////////////////////////////////// @@ -194,7 +191,7 @@ public class VideoDetailFragment private ImageButton overlayCloseButton; private AppBarLayout appBarLayout; - private ViewPager viewPager; + private ViewPager viewPager; private TabAdaptor pageAdapter; private TabLayout tabLayout; private FrameLayout relatedStreamsLayout; @@ -210,19 +207,19 @@ public class VideoDetailFragment // Service management //////////////////////////////////////////////////////////////////////////*/ - private ServiceConnection getServiceConnection(boolean playAfterConnect) { + private ServiceConnection getServiceConnection(final boolean playAfterConnect) { return new ServiceConnection() { @Override - public void onServiceDisconnected(ComponentName name) { + public void onServiceDisconnected(final ComponentName name) { if (DEBUG) Log.d(TAG, "Player service is disconnected"); unbind(); } @Override - public void onServiceConnected(ComponentName compName, IBinder service) { + public void onServiceConnected(final ComponentName compName, final IBinder service) { if (DEBUG) Log.d(TAG, "Player service is connected"); - MainPlayer.LocalBinder localBinder = (MainPlayer.LocalBinder) service; + final MainPlayer.LocalBinder localBinder = (MainPlayer.LocalBinder) service; playerService = localBinder.getService(); player = localBinder.getPlayer(); @@ -255,18 +252,16 @@ public class VideoDetailFragment private void bind() { if (DEBUG) Log.d(TAG, "bind() called"); - Intent serviceIntent = new Intent(getContext(), MainPlayer.class); - final boolean success = getContext().bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE); - - if (!success) getContext().unbindService(serviceConnection); - bound = success; + final Intent serviceIntent = new Intent(getContext(), MainPlayer.class); + bound = requireContext().bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE); + if (!bound) requireContext().unbindService(serviceConnection); } private void unbind() { if (DEBUG) Log.d(TAG, "unbind() called"); if (bound) { - getContext().unbindService(serviceConnection); + requireContext().unbindService(serviceConnection); bound = false; stopPlayerListener(); playerService = null; @@ -286,20 +281,20 @@ public class VideoDetailFragment // startService() can be called concurrently and it will give a random crashes and NullPointerExceptions // inside the service because the service will be bound twice. Prevent it with unbinding first unbind(); - getContext().startService(new Intent(getContext(), MainPlayer.class)); + requireContext().startService(new Intent(getContext(), MainPlayer.class)); serviceConnection = getServiceConnection(playAfterConnect); bind(); } private void stopService() { unbind(); - getContext().stopService(new Intent(getContext(), MainPlayer.class)); + requireContext().stopService(new Intent(getContext(), MainPlayer.class)); } /*////////////////////////////////////////////////////////////////////////*/ - public static VideoDetailFragment getInstance(int serviceId, String videoUrl, String name, PlayQueue playQueue) { + public static VideoDetailFragment getInstance(final int serviceId, final String videoUrl, final String name, final PlayQueue playQueue) { VideoDetailFragment instance = new VideoDetailFragment(); instance.setInitialData(serviceId, videoUrl, name, playQueue); return instance; @@ -330,8 +325,8 @@ public class VideoDetailFragment settingsContentObserver = new ContentObserver(new Handler()) { @Override - public void onChange(boolean selfChange) { - if(activity != null && !PlayerHelper.globalScreenOrientationLocked(activity)) + public void onChange(final boolean selfChange) { + if (activity != null && !PlayerHelper.globalScreenOrientationLocked(activity)) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } }; @@ -402,10 +397,9 @@ public class VideoDetailFragment if (positionSubscriber != null) positionSubscriber.dispose(); if (currentWorker != null) currentWorker.dispose(); - if (disposables != null) disposables.clear(); + disposables.clear(); positionSubscriber = null; currentWorker = null; - disposables = null; bottomSheetBehavior.setBottomSheetCallback(null); } @@ -521,10 +515,9 @@ public class VideoDetailFragment case R.id.overlay_play_pause_button: if (playerIsNotStopped()) { player.onPlayPause(); - player.hideControls(0,0); + player.hideControls(0, 0); showSystemUi(); - } - else openVideoPlayer(); + } else openVideoPlayer(); setOverlayPlayPauseImage(); break; @@ -754,12 +747,13 @@ public class VideoDetailFragment // Remove top stack.pop(); // Get stack item from the new top + assert stack.peek() != null; setupFromHistoryItem(stack.peek()); return true; } - private void setupFromHistoryItem(StackItem item) { + private void setupFromHistoryItem(final StackItem item) { setAutoplay(false); hideMainPlayer(); @@ -773,9 +767,9 @@ public class VideoDetailFragment // Maybe an item was deleted in background activity if (item.getPlayQueue().getItem() == null) return; - PlayQueueItem playQueueItem = item.getPlayQueue().getItem(); + final PlayQueueItem playQueueItem = item.getPlayQueue().getItem(); // Update title, url, uploader from the last item in the stack (it's current now) - boolean isPlayerStopped = player == null || player.isPlayerStopped(); + final boolean isPlayerStopped = player == null || player.isPlayerStopped(); if (playQueueItem != null && isPlayerStopped) updateOverlayData(playQueueItem.getTitle(), playQueueItem.getUploader(), playQueueItem.getThumbnailUrl()); } @@ -792,7 +786,7 @@ public class VideoDetailFragment else prepareAndHandleInfo(currentInfo, false); } - public void selectAndLoadVideo(int serviceId, String videoUrl, String name, PlayQueue playQueue) { + public void selectAndLoadVideo(final int serviceId, final String videoUrl, final String name, final PlayQueue playQueue) { // Situation when user switches from players to main player. All needed data is here, we can start watching if (this.playQueue != null && this.playQueue.equals(playQueue)) { openVideoPlayer(); @@ -802,7 +796,7 @@ public class VideoDetailFragment startLoading(false, true); } - public void prepareAndHandleInfo(final StreamInfo info, boolean scrollToTop) { + public void prepareAndHandleInfo(final StreamInfo info, final boolean scrollToTop) { if (DEBUG) Log.d(TAG, "prepareAndHandleInfo() called with: info = [" + info + "], scrollToTop = [" + scrollToTop + "]"); @@ -821,7 +815,7 @@ public class VideoDetailFragment } @Override - public void startLoading(boolean forceLoad) { + public void startLoading(final boolean forceLoad) { super.startLoading(forceLoad); initTabs(); @@ -831,7 +825,7 @@ public class VideoDetailFragment runWorker(forceLoad, stack.isEmpty()); } - private void startLoading(boolean forceLoad, boolean addToBackStack) { + private void startLoading(final boolean forceLoad, final boolean addToBackStack) { super.startLoading(false); initTabs(); @@ -841,7 +835,7 @@ public class VideoDetailFragment runWorker(forceLoad, addToBackStack); } - private void runWorker(boolean forceLoad, boolean addToBackStack) { + private void runWorker(final boolean forceLoad, final boolean addToBackStack) { currentWorker = ExtractorHelper.getStreamInfo(serviceId, url, forceLoad) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -867,26 +861,26 @@ public class VideoDetailFragment } pageAdapter.clearAllItems(); - if(shouldShowComments()){ + if (shouldShowComments()) { pageAdapter.addFragment(CommentsFragment.getInstance(serviceId, url, name), COMMENTS_TAB_TAG); } - if(showRelatedStreams && null == relatedStreamsLayout){ + if (showRelatedStreams && null == relatedStreamsLayout) { //temp empty fragment. will be updated in handleResult pageAdapter.addFragment(new Fragment(), RELATED_TAB_TAG); } - if(pageAdapter.getCount() == 0){ + if (pageAdapter.getCount() == 0) { pageAdapter.addFragment(new EmptyFragment(), EMPTY_TAB_TAG); } pageAdapter.notifyDataSetUpdate(); - if(pageAdapter.getCount() < 2){ + if (pageAdapter.getCount() < 2) { tabLayout.setVisibility(View.GONE); - }else{ - int position = pageAdapter.getItemPositionByTitle(selectedTabTag); - if(position != -1) viewPager.setCurrentItem(position); + } else { + final int position = pageAdapter.getItemPositionByTitle(selectedTabTag); + if (position != -1) viewPager.setCurrentItem(position); tabLayout.setVisibility(View.VISIBLE); } } @@ -911,10 +905,10 @@ public class VideoDetailFragment //////////////////////////////////////////////////////////////////////////*/ private void openBackgroundPlayer(final boolean append) { - AudioStream audioStream = currentInfo.getAudioStreams() + final AudioStream audioStream = currentInfo.getAudioStreams() .get(ListHelper.getDefaultAudioFormat(activity, currentInfo.getAudioStreams())); - boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity) + final boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity) .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 @@ -939,7 +933,7 @@ public class VideoDetailFragment // If a user watched video inside fullscreen mode and than chose another player return to non-fullscreen mode if (player != null && player.isFullscreen()) player.toggleFullscreen(); - PlayQueue queue = setupPlayQueueForIntent(append); + final PlayQueue queue = setupPlayQueueForIntent(append); if (append) { NavigationHelper.enqueueOnPopupPlayer(activity, queue, false); } else { @@ -950,7 +944,8 @@ public class VideoDetailFragment private void openVideoPlayer() { if (PreferenceManager.getDefaultSharedPreferences(activity) .getBoolean(this.getString(R.string.use_external_video_player_key), false)) { - VideoStream selectedVideoStream = getSelectedVideoStream(); + final VideoStream selectedVideoStream = getSelectedVideoStream(); + if (selectedVideoStream == null) return; startOnExternalPlayer(activity, currentInfo, selectedVideoStream); } else { replaceQueueIfUserConfirms(this::openMainPlayer); @@ -961,7 +956,7 @@ public class VideoDetailFragment // See UI changes while remote playQueue changes if (!bound) startService(false); - PlayQueue queue = setupPlayQueueForIntent(append); + final PlayQueue queue = setupPlayQueueForIntent(append); if (append) { NavigationHelper.enqueueOnBackgroundPlayer(activity, queue, false); } else { @@ -971,18 +966,18 @@ public class VideoDetailFragment private void openMainPlayer() { if (playerService == null) { - startService(true); - return; + startService(true); + return; } if (currentInfo == null) return; - PlayQueue queue = setupPlayQueueForIntent(false); + final PlayQueue queue = setupPlayQueueForIntent(false); // Video view can have elements visible from popup, We hide it here but once it ready the view will be shown in handleIntent() - playerService.getView().setVisibility(View.GONE); + Objects.requireNonNull(playerService.getView()).setVisibility(View.GONE); addVideoPlayerView(); - Intent playerIntent = NavigationHelper.getPlayerIntent(getContext(), MainPlayer.class, queue, null, true); + final Intent playerIntent = NavigationHelper.getPlayerIntent(requireContext(), MainPlayer.class, queue, null, true); activity.startService(playerIntent); } @@ -995,7 +990,7 @@ public class VideoDetailFragment playerService.getView().setVisibility(View.GONE); } - private PlayQueue setupPlayQueueForIntent(boolean append) { + private PlayQueue setupPlayQueueForIntent(final boolean append) { if (append) return new SinglePlayQueue(currentInfo); PlayQueue queue = playQueue; @@ -1026,7 +1021,7 @@ public class VideoDetailFragment // Utils //////////////////////////////////////////////////////////////////////////*/ - public void setAutoplay(boolean autoplay) { + public void setAutoplay(final boolean autoplay) { this.autoPlayEnabled = autoplay; } @@ -1059,7 +1054,7 @@ public class VideoDetailFragment && isAutoplayAllowedByUser(); } - private boolean isAutoplayAllowedByUser () { + private boolean isAutoplayAllowedByUser() { if (activity == null) return false; switch (PlayerHelper.getAutoplayType(activity)) { @@ -1076,7 +1071,7 @@ public class VideoDetailFragment private void addVideoPlayerView() { if (player == null || getView() == null) return; - FrameLayout viewHolder = getView().findViewById(R.id.player_placeholder); + final FrameLayout viewHolder = getView().findViewById(R.id.player_placeholder); // Check if viewHolder already contains a child if (player.getRootView().getParent() != viewHolder) removeVideoPlayerView(); @@ -1095,7 +1090,7 @@ public class VideoDetailFragment private void makeDefaultHeightForVideoPlaceholder() { if (getView() == null) return; - FrameLayout viewHolder = getView().findViewById(R.id.player_placeholder); + final FrameLayout viewHolder = getView().findViewById(R.id.player_placeholder); viewHolder.getLayoutParams().height = FrameLayout.LayoutParams.MATCH_PARENT; viewHolder.requestLayout(); } @@ -1113,7 +1108,7 @@ public class VideoDetailFragment disposables.add(Single.just(descriptionHtml) .map((@io.reactivex.annotations.NonNull String description) -> { - Spanned parsedDescription; + final Spanned parsedDescription; if (Build.VERSION.SDK_INT >= 24) { parsedDescription = Html.fromHtml(description, 0); } else { @@ -1137,11 +1132,11 @@ public class VideoDetailFragment */ private void setHeightThumbnail() { final DisplayMetrics metrics = getResources().getDisplayMetrics(); - boolean isPortrait = metrics.heightPixels > metrics.widthPixels; + final boolean isPortrait = metrics.heightPixels > metrics.widthPixels; - int height; + final int height; if (player != null && player.isFullscreen()) - height = isInMultiWindow() ? getView().getHeight() : activity.getWindow().getDecorView().getHeight(); + height = isInMultiWindow() ? Objects.requireNonNull(getView()).getHeight() : activity.getWindow().getDecorView().getHeight(); else height = isPortrait ? (int) (metrics.widthPixels / (16.0f / 9.0f)) @@ -1150,7 +1145,7 @@ public class VideoDetailFragment thumbnailImageView.setLayoutParams(new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height)); thumbnailImageView.setMinimumHeight(height); if (player != null) { - int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT); + final int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT); player.getSurfaceView().setHeights(height, player.isFullscreen() ? height : maxHeight); } } @@ -1159,7 +1154,7 @@ public class VideoDetailFragment contentRootLayoutHiding.setVisibility(View.VISIBLE); } - protected void setInitialData(int serviceId, String url, String name, PlayQueue playQueue) { + protected void setInitialData(final int serviceId, final String url, final String name, final PlayQueue playQueue) { this.serviceId = serviceId; this.url = url; this.name = !TextUtils.isEmpty(name) ? name : ""; @@ -1188,9 +1183,9 @@ public class VideoDetailFragment broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if(intent.getAction().equals(ACTION_SHOW_MAIN_PLAYER)) { + if (intent.getAction().equals(ACTION_SHOW_MAIN_PLAYER)) { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); - } else if(intent.getAction().equals(ACTION_HIDE_MAIN_PLAYER)) { + } else if (intent.getAction().equals(ACTION_HIDE_MAIN_PLAYER)) { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); } } @@ -1227,7 +1222,7 @@ public class VideoDetailFragment super.showLoading(); //if data is already cached, transition from VISIBLE -> INVISIBLE -> VISIBLE is not required - if(!ExtractorHelper.isCached(serviceId, url, InfoItem.InfoType.STREAM)){ + if (!ExtractorHelper.isCached(serviceId, url, InfoItem.InfoType.STREAM)) { contentRootLayoutHiding.setVisibility(View.INVISIBLE); } @@ -1245,10 +1240,10 @@ public class VideoDetailFragment videoTitleToggleArrow.setVisibility(View.GONE); videoTitleRoot.setClickable(false); - if(relatedStreamsLayout != null){ - if(showRelatedStreams){ + if (relatedStreamsLayout != null) { + if (showRelatedStreams) { relatedStreamsLayout.setVisibility(player != null && player.isFullscreen() ? View.GONE : View.INVISIBLE); - }else{ + } else { relatedStreamsLayout.setVisibility(View.GONE); } } @@ -1266,11 +1261,11 @@ public class VideoDetailFragment currentInfo = info; setInitialData(info.getServiceId(), info.getOriginalUrl(), info.getName(), playQueue); - if(showRelatedStreams){ - if(null == relatedStreamsLayout){ //phone + if (showRelatedStreams) { + if (null == relatedStreamsLayout) { //phone pageAdapter.updateItem(RELATED_TAB_TAG, RelatedVideosFragment.getInstance(info)); pageAdapter.notifyDataSetUpdate(); - }else{ //tablet + } else { //tablet getChildFragmentManager().beginTransaction() .replace(R.id.relatedStreamsLayout, RelatedVideosFragment.getInstance(info)) .commitNow(); @@ -1359,6 +1354,12 @@ public class VideoDetailFragment videoUploadDateView.setVisibility(View.GONE); } + sortedVideoStreams = ListHelper.getSortedStreamVideosList( + activity, + info.getVideoStreams(), + info.getVideoOnlyStreams(), + false); + selectedVideoStreamIndex = ListHelper.getDefaultResolutionIndex(activity, sortedVideoStreams); prepareDescription(info.getDescription()); updateProgressInfo(info); initThumbnailViews(info); @@ -1381,7 +1382,7 @@ public class VideoDetailFragment detailControlsDownload.setVisibility(View.GONE); break; default: - if(info.getAudioStreams().isEmpty()) detailControlsBackground.setVisibility(View.GONE); + if (info.getAudioStreams().isEmpty()) detailControlsBackground.setVisibility(View.GONE); if (!info.getVideoStreams().isEmpty() || !info.getVideoOnlyStreams().isEmpty()) break; @@ -1393,28 +1394,28 @@ public class VideoDetailFragment public void openDownloadDialog() { - try { - DownloadDialog downloadDialog = DownloadDialog.newInstance(currentInfo); - downloadDialog.setVideoStreams(sortedVideoStreams); - downloadDialog.setAudioStreams(currentInfo.getAudioStreams()); - downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex); - downloadDialog.setSubtitleStreams(currentInfo.getSubtitles()); + try { + final DownloadDialog downloadDialog = DownloadDialog.newInstance(currentInfo); + downloadDialog.setVideoStreams(sortedVideoStreams); + downloadDialog.setAudioStreams(currentInfo.getAudioStreams()); + downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex); + downloadDialog.setSubtitleStreams(currentInfo.getSubtitles()); - downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog"); - } catch (Exception e) { - ErrorActivity.ErrorInfo info = ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, - ServiceList.all() - .get(currentInfo - .getServiceId()) - .getServiceInfo() - .getName(), "", - R.string.could_not_setup_download_menu); + downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog"); + } catch (Exception e) { + final ErrorActivity.ErrorInfo info = ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, + ServiceList.all() + .get(currentInfo + .getServiceId()) + .getServiceInfo() + .getName(), "", + R.string.could_not_setup_download_menu); - ErrorActivity.reportError(activity, - e, - activity.getClass(), - activity.findViewById(android.R.id.content), info); - } + ErrorActivity.reportError(activity, + e, + activity.getClass(), + activity.findViewById(android.R.id.content), info); + } } /*////////////////////////////////////////////////////////////////////////// @@ -1428,7 +1429,7 @@ public class VideoDetailFragment else if (exception instanceof ContentNotAvailableException) { showError(getString(R.string.content_not_available), false); } else { - int errorId = exception instanceof YoutubeStreamExtractor.DecryptException + final int errorId = exception instanceof YoutubeStreamExtractor.DecryptException ? R.string.youtube_signature_decryption_error : exception instanceof ParsingException ? R.string.parsing_error @@ -1484,7 +1485,7 @@ public class VideoDetailFragment }); } - private void showPlaybackProgress(long progress, long duration) { + private void showPlaybackProgress(final long progress, final long duration) { final int progressSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(progress); final int durationSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(duration); positionView.setMax(durationSeconds); @@ -1501,9 +1502,9 @@ public class VideoDetailFragment //////////////////////////////////////////////////////////////////////////*/ @Override - public void onQueueUpdate(PlayQueue queue) { + public void onQueueUpdate(final PlayQueue queue) { playQueue = queue; - StackItem stackWithQueue; + final 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)) { @@ -1522,7 +1523,7 @@ public class VideoDetailFragment } @Override - public void onPlaybackUpdate(int state, int repeatMode, boolean shuffled, PlaybackParameters parameters) { + public void onPlaybackUpdate(final int state, final int repeatMode, final boolean shuffled, final PlaybackParameters parameters) { setOverlayPlayPauseImage(); switch (state) { @@ -1542,7 +1543,7 @@ public class VideoDetailFragment } @Override - public void onProgressUpdate(int currentProgress, int duration, int bufferPercent) { + public void onProgressUpdate(final int currentProgress, final int duration, final int bufferPercent) { // Progress updates every second even if media is paused. It's useless until playing if (!player.getPlayer().isPlaying() || playQueue == null) return; @@ -1551,8 +1552,8 @@ public class VideoDetailFragment } @Override - public void onMetadataUpdate(StreamInfo info, PlayQueue queue) { - StackItem item = findQueueInStack(queue); + public void onMetadataUpdate(final StreamInfo info, final PlayQueue queue) { + final StackItem item = findQueueInStack(queue); if (item != null) { // When PlayQueue can have multiple streams (PlaylistPlayQueue or ChannelPlayQueue) every new played stream gives // new title and url. StackItem contains information about first played stream. Let's update it here @@ -1567,13 +1568,13 @@ public class VideoDetailFragment if (currentInfo != null && info.getUrl().equals(currentInfo.getUrl())) return; currentInfo = info; - setInitialData(info.getServiceId(), info.getUrl(),info.getName(), queue); + setInitialData(info.getServiceId(), info.getUrl(), info.getName(), queue); setAutoplay(false); prepareAndHandleInfo(info, true); } @Override - public void onPlayerError(ExoPlaybackException error) { + public void onPlayerError(final ExoPlaybackException error) { if (error.type == ExoPlaybackException.TYPE_SOURCE || error.type == ExoPlaybackException.TYPE_UNEXPECTED) { hideMainPlayer(); if (playerService != null && player.isFullscreen()) @@ -1590,12 +1591,12 @@ public class VideoDetailFragment } @Override - public void onFullscreenStateChanged(boolean fullscreen) { + public void onFullscreenStateChanged(final boolean fullscreen) { if (playerService.getView() == null || player.getParentActivity() == null) return; - View view = playerService.getView(); - ViewGroup parent = (ViewGroup) view.getParent(); + final View view = playerService.getView(); + final ViewGroup parent = (ViewGroup) view.getParent(); if (parent == null) return; if (fullscreen) { @@ -1619,7 +1620,7 @@ public class VideoDetailFragment return; } - int newOrientation = isLandscape() ? + final int newOrientation = isLandscape() ? ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; @@ -1627,13 +1628,13 @@ public class VideoDetailFragment } /* - * Will scroll down to description view after long click on moreOptionsButton - * */ + * Will scroll down to description view after long click on moreOptionsButton + * */ @Override public void onMoreOptionsLongClicked() { - CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); - AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); - ValueAnimator valueAnimator = ValueAnimator.ofInt(0, -getView().findViewById(R.id.player_placeholder).getHeight()); + final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); + final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); + final ValueAnimator valueAnimator = ValueAnimator.ofInt(0, -getView().findViewById(R.id.player_placeholder).getHeight()); valueAnimator.setInterpolator(new DecelerateInterpolator()); valueAnimator.addUpdateListener(animation -> { behavior.setTopAndBottomOffset((int) animation.getAnimatedValue()); @@ -1662,7 +1663,7 @@ public class VideoDetailFragment if (activity == null) return; - int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE + final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN @@ -1683,12 +1684,10 @@ public class VideoDetailFragment return player != null && player.getPlayer() != null && player.getPlayer().getPlaybackState() != Player.STATE_IDLE; } - private void setupBrightness(boolean save) { + private void setupBrightness(final boolean save) { if (activity == null) return; - WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); - float brightnessLevel; - + final WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); if (save) { // Save current brightness level PlayerHelper.setScreenBrightness(activity, lp.screenBrightness); @@ -1698,7 +1697,7 @@ public class VideoDetailFragment lp.screenBrightness = -1; } else { // Restore already saved brightness level - brightnessLevel = PlayerHelper.getScreenBrightness(activity); + final float brightnessLevel = PlayerHelper.getScreenBrightness(activity); if (brightnessLevel <= 0.0f && brightnessLevel > 1.0f) return; @@ -1712,7 +1711,7 @@ public class VideoDetailFragment setAutoplay(true); player.checkLandscape(); - boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(activity); + final boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(activity); // Let's give a user time to look at video information page if video is not playing if (orientationLocked && !player.isPlaying()) { player.onPlay(); @@ -1729,17 +1728,17 @@ public class VideoDetailFragment } /* - * Means that the player fragment was swiped away via BottomSheetLayout and is empty but ready for any new actions. See cleanUp() - * */ + * Means that the player fragment was swiped away via BottomSheetLayout and is empty but ready for any new actions. See cleanUp() + * */ private boolean wasCleared() { return url == null; } - private StackItem findQueueInStack(PlayQueue queue) { + private StackItem findQueueInStack(final PlayQueue queue) { StackItem item = null; - Iterator iterator = stack.descendingIterator(); + final Iterator iterator = stack.descendingIterator(); while (iterator.hasNext()) { - StackItem next = iterator.next(); + final StackItem next = iterator.next(); if (next.getPlayQueue().equals(queue)) { item = next; break; @@ -1763,7 +1762,7 @@ public class VideoDetailFragment } } - private void showClearingQueueConfirmation(Runnable onAllow) { + private void showClearingQueueConfirmation(final Runnable onAllow) { new AlertDialog.Builder(activity) .setTitle(R.string.confirm_prompt) .setMessage(R.string.clear_queue_confirmation_description) @@ -1775,14 +1774,14 @@ public class VideoDetailFragment } /* - * Remove unneeded information while waiting for a next task - * */ + * Remove unneeded information while waiting for a next task + * */ private void cleanUp() { // New beginning stack.clear(); if (currentWorker != null) currentWorker.dispose(); stopService(); - setInitialData(0,null,"", null); + setInitialData(0, null, "", null); currentInfo = null; updateOverlayData(null, null, null); } @@ -1792,10 +1791,10 @@ public class VideoDetailFragment //////////////////////////////////////////////////////////////////////////*/ private void setupBottomPlayer() { - CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); - AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); + final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); + final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior(); - FrameLayout bottomSheetLayout = activity.findViewById(R.id.fragment_player_holder); + final FrameLayout bottomSheetLayout = activity.findViewById(R.id.fragment_player_holder); bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout); bottomSheetBehavior.setState(bottomSheetState); final int peekHeight = getResources().getDimensionPixelSize(R.dimen.mini_player_height); @@ -1810,7 +1809,8 @@ public class VideoDetailFragment } bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { - @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { + @Override + public void onStateChanged(@NonNull final View bottomSheet, final int newState) { bottomSheetState = newState; switch (newState) { @@ -1843,7 +1843,9 @@ public class VideoDetailFragment break; } } - @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { + + @Override + public void onSlide(@NonNull final View bottomSheet, final float slideOffset) { setOverlayLook(appBarLayout, behavior, slideOffset); } }); @@ -1855,31 +1857,31 @@ public class VideoDetailFragment }); } - private void updateOverlayData(@Nullable String title, @Nullable String uploader, @Nullable String thumbnailUrl) { + private void updateOverlayData(@Nullable final String title, @Nullable final String uploader, @Nullable final String thumbnailUrl) { 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, - ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS, null); + ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS, null); } private void setOverlayPlayPauseImage() { - int attr = player != null && player.getPlayer().getPlayWhenReady() ? R.attr.pause : R.attr.play; + final int attr = player != null && player.getPlayer().getPlayWhenReady() ? R.attr.pause : R.attr.play; overlayPlayPauseButton.setImageResource(ThemeHelper.resolveResourceIdFromAttr(activity, attr)); } - private void setOverlayLook(AppBarLayout appBarLayout, AppBarLayout.Behavior behavior, float slideOffset) { + private void setOverlayLook(final AppBarLayout appBarLayout, final AppBarLayout.Behavior behavior, final float slideOffset) { if (behavior != null) { overlay.setAlpha(Math.min(MAX_OVERLAY_ALPHA, 1 - slideOffset)); // These numbers are not special. They just do a cool transition - behavior.setTopAndBottomOffset((int)(-thumbnailImageView.getHeight() * 2 * (1 - slideOffset) / 3)); + behavior.setTopAndBottomOffset((int) (-thumbnailImageView.getHeight() * 2 * (1 - slideOffset) / 3)); appBarLayout.requestLayout(); } } - private void setOverlayElementsClickable(boolean enable) { + private void setOverlayElementsClickable(final boolean enable) { overlayThumbnailImageView.setClickable(enable); overlayThumbnailImageView.setLongClickable(enable); overlayMetadata.setClickable(enable); 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 c31654473..634ce7779 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -274,7 +274,7 @@ public abstract class BasePlayer implements return; } - boolean samePlayQueue = playQueue != null && playQueue.equals(queue); + final boolean samePlayQueue = playQueue != null && playQueue.equals(queue); final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); final float playbackSpeed = intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed()); 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 f1f9b51da..5bfa4732e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java @@ -102,7 +102,7 @@ public final class MainPlayer extends Service { } private void createView() { - View layout = View.inflate(this, R.layout.activity_main_player, null); + final View layout = View.inflate(this, R.layout.activity_main_player, null); playerImpl = new VideoPlayerImpl(this); playerImpl.setup(layout); @@ -124,7 +124,7 @@ public final class MainPlayer extends Service { return START_NOT_STICKY; } - public void stop(boolean autoplayEnabled) { + public void stop(final boolean autoplayEnabled) { if (DEBUG) Log.d(TAG, "stop() called"); if (playerImpl.getPlayer() != null) { @@ -212,7 +212,7 @@ public final class MainPlayer extends Service { if (getView().getParent() != null) { if (playerImpl.getParentActivity() != null) { // This means view was added to fragment - ViewGroup parent = (ViewGroup) getView().getParent(); + final ViewGroup parent = (ViewGroup) getView().getParent(); parent.removeView(getView()); } else // This means view was added by windowManager for popup player @@ -244,7 +244,7 @@ public final class MainPlayer extends Service { setupNotification(notRemoteView); setupNotification(bigNotRemoteView); - NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) + final NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) .setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) @@ -254,7 +254,7 @@ public final class MainPlayer extends Service { return builder; } - private void setupNotification(RemoteViews remoteViews) { + private void setupNotification(final RemoteViews remoteViews) { // Don't show anything until player is playing if (playerImpl == null) return; @@ -298,7 +298,7 @@ public final class MainPlayer extends Service { * * @param drawableId if != -1, sets the drawable with that id on the play/pause button */ - synchronized void updateNotification(int drawableId) { + synchronized void updateNotification(final int drawableId) { //if (DEBUG) Log.d(TAG, "updateNotification() called with: drawableId = [" + drawableId + "]"); if (notBuilder == null) return; if (drawableId != -1) { @@ -329,7 +329,7 @@ public final class MainPlayer extends Service { } private Intent getIntentForNotification() { - Intent intent; + final Intent intent; if (playerImpl.audioPlayerSelected() || playerImpl.popupPlayerSelected()) { // Means we play in popup or audio only. Let's show BackgroundPlayerActivity intent = NavigationHelper.getBackgroundPlayerActivityIntent(getApplicationContext()); diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index 619200727..9b5838a40 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -186,7 +186,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity } Intent getSwitchIntent(final Class clazz, final MainPlayer.PlayerType playerType) { - Intent intent = NavigationHelper.getPlayerIntent( + final Intent intent = NavigationHelper.getPlayerIntent( getApplicationContext(), clazz, this.player.getPlayQueue(), 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 aad20b0ad..6c1843763 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -97,7 +97,7 @@ public class VideoPlayerImpl extends VideoPlayer View.OnLongClickListener { private static final String TAG = ".VideoPlayerImpl"; - private final float MAX_GESTURE_LENGTH = 0.75f; + private static final float MAX_GESTURE_LENGTH = 0.75f; private TextView titleTextView; private TextView channelTextView; @@ -142,11 +142,11 @@ public class VideoPlayerImpl extends VideoPlayer private boolean isVerticalVideo = false; boolean shouldUpdateOnProgress; - private MainPlayer service; + private final MainPlayer service; private PlayerServiceEventListener fragmentListener; private PlayerEventListener activityListener; private GestureDetector gestureDetector; - private SharedPreferences defaultPreferences; + private final SharedPreferences defaultPreferences; private ContentObserver settingsContentObserver; @NonNull final private AudioPlaybackResolver resolver; @@ -184,7 +184,7 @@ public class VideoPlayerImpl extends VideoPlayer public void handleIntent(Intent intent) { if (intent.getStringExtra(VideoPlayer.PLAY_QUEUE_KEY) == null) return; - MainPlayer.PlayerType oldPlayerType = playerType; + final MainPlayer.PlayerType oldPlayerType = playerType; choosePlayerTypeFromIntent(intent); audioOnly = audioPlayerSelected(); @@ -350,8 +350,8 @@ public class VideoPlayerImpl extends VideoPlayer */ private void setupElementsSize() { if (popupPlayerSelected()) { - int controlsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_popup_controls_padding); - int buttonsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_popup_buttons_padding); + final int controlsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_popup_controls_padding); + final int buttonsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_popup_buttons_padding); getTopControlsRoot().setPaddingRelative(controlsPadding, 0, controlsPadding, 0); getBottomControlsRoot().setPaddingRelative(controlsPadding, 0, controlsPadding, 0); getQualityTextView().setPadding(buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); @@ -361,10 +361,10 @@ public class VideoPlayerImpl extends VideoPlayer getQualityTextView().setMinimumWidth(0); getPlaybackSpeedTextView().setMinimumWidth(0); } else if (videoPlayerSelected()) { - int buttonsMinWidth = service.getResources().getDimensionPixelSize(R.dimen.player_main_buttons_min_width); - int playerTopPadding = service.getResources().getDimensionPixelSize(R.dimen.player_main_top_padding); - int controlsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_main_controls_padding); - int buttonsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_main_buttons_padding); + final int buttonsMinWidth = service.getResources().getDimensionPixelSize(R.dimen.player_main_buttons_min_width); + final int playerTopPadding = service.getResources().getDimensionPixelSize(R.dimen.player_main_top_padding); + final int controlsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_main_controls_padding); + final int buttonsPadding = service.getResources().getDimensionPixelSize(R.dimen.player_main_buttons_padding); getTopControlsRoot().setPaddingRelative(controlsPadding, playerTopPadding, controlsPadding, 0); getBottomControlsRoot().setPaddingRelative(controlsPadding, 0, controlsPadding, 0); getQualityTextView().setPadding(buttonsPadding, buttonsPadding, buttonsPadding, buttonsPadding); @@ -379,7 +379,7 @@ public class VideoPlayerImpl extends VideoPlayer public void initListeners() { super.initListeners(); - PlayerGestureListener listener = new PlayerGestureListener(this, service); + final PlayerGestureListener listener = new PlayerGestureListener(this, service); gestureDetector = new GestureDetector(context, listener); getRootView().setOnTouchListener(listener); @@ -415,7 +415,7 @@ public class VideoPlayerImpl extends VideoPlayer if (getRootView() == null || getRootView().getParent() == null || !(getRootView().getParent() instanceof ViewGroup)) return null; - ViewGroup parent = (ViewGroup) getRootView().getParent(); + final ViewGroup parent = (ViewGroup) getRootView().getParent(); return (AppCompatActivity) parent.getContext(); } @@ -509,7 +509,7 @@ public class VideoPlayerImpl extends VideoPlayer } @Override - public void onUpdateProgress(int currentProgress, int duration, int bufferPercent) { + public void onUpdateProgress(final int currentProgress, final int duration, final int bufferPercent) { super.onUpdateProgress(currentProgress, duration, bufferPercent); updateProgress(currentProgress, duration, bufferPercent); @@ -560,7 +560,8 @@ public class VideoPlayerImpl extends VideoPlayer } @Override - protected void initPlayback(@NonNull PlayQueue queue, int repeatMode, float playbackSpeed, float playbackPitch, boolean playbackSkipSilence, boolean playOnReady) { + protected void initPlayback(@NonNull PlayQueue queue, int repeatMode, float playbackSpeed, + float playbackPitch, boolean playbackSkipSilence, boolean playOnReady) { super.initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, playOnReady); updateQueue(); } @@ -760,16 +761,16 @@ public class VideoPlayerImpl extends VideoPlayer } private void setupScreenRotationButton() { - boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service); - boolean tabletInLandscape = isTablet(service) && service.isLandscape(); - boolean showButton = videoPlayerSelected() && (orientationLocked || isVerticalVideo || tabletInLandscape); + final boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service); + final boolean tabletInLandscape = isTablet(service) && service.isLandscape(); + final boolean showButton = videoPlayerSelected() && (orientationLocked || isVerticalVideo || tabletInLandscape); screenRotationButton.setVisibility(showButton ? View.VISIBLE : View.GONE); screenRotationButton.setImageDrawable(service.getResources().getDrawable( isFullscreen() ? R.drawable.ic_fullscreen_exit_white : R.drawable.ic_fullscreen_white)); } private void prepareOrientation() { - boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service); + final boolean orientationLocked = PlayerHelper.globalScreenOrientationLocked(service); if (orientationLocked && isFullscreen() && service.isLandscape() == isVerticalVideo && fragmentListener != null) fragmentListener.onScreenRotationButtonClicked(); } @@ -1068,8 +1069,8 @@ public class VideoPlayerImpl extends VideoPlayer // because in that case the controls should be aligned to another side of a screen. The problem is when user leaves // the app and returns back (while the app in landscape) Android reports via DisplayMetrics that orientation is // portrait and it gives wrong sizes calculations. Let's skip re-calculation in every case but landscape - boolean reportedOrientationIsLandscape = service.isLandscape(); - boolean actualOrientationIsLandscape = context.getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE; + final boolean reportedOrientationIsLandscape = service.isLandscape(); + final boolean actualOrientationIsLandscape = context.getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE; if (reportedOrientationIsLandscape && actualOrientationIsLandscape) setControlsSize(); // Close it because when changing orientation from portrait (in fullscreen mode) the size of queue layout can be // larger than the screen size @@ -1130,7 +1131,7 @@ public class VideoPlayerImpl extends VideoPlayer } } - private void choosePlayerTypeFromIntent(Intent intent) { + private void choosePlayerTypeFromIntent(final Intent intent) { // If you want to open popup from the app just include Constants.POPUP_ONLY into an extra if (intent.getIntExtra(PLAYER_TYPE, PLAYER_TYPE_VIDEO) == PLAYER_TYPE_AUDIO) { playerType = MainPlayer.PlayerType.AUDIO; @@ -1165,12 +1166,12 @@ public class VideoPlayerImpl extends VideoPlayer return getPlayer() == null || getPlayer().getPlaybackState() == SimpleExoPlayer.STATE_IDLE; } - private int distanceFromCloseButton(MotionEvent popupMotionEvent) { + private int distanceFromCloseButton(final MotionEvent popupMotionEvent) { final int closeOverlayButtonX = closeOverlayButton.getLeft() + closeOverlayButton.getWidth() / 2; final int closeOverlayButtonY = closeOverlayButton.getTop() + closeOverlayButton.getHeight() / 2; - float fingerX = popupLayoutParams.x + popupMotionEvent.getX(); - float fingerY = popupLayoutParams.y + popupMotionEvent.getY(); + final float fingerX = popupLayoutParams.x + popupMotionEvent.getX(); + final float fingerY = popupLayoutParams.y + popupMotionEvent.getY(); return (int) Math.sqrt(Math.pow(closeOverlayButtonX - fingerX, 2) + Math.pow(closeOverlayButtonY - fingerY, 2)); } @@ -1181,7 +1182,7 @@ public class VideoPlayerImpl extends VideoPlayer return buttonRadius * 1.2f; } - public boolean isInsideClosingRadius(MotionEvent popupMotionEvent) { + public boolean isInsideClosingRadius(final MotionEvent popupMotionEvent) { return distanceFromCloseButton(popupMotionEvent) <= getClosingRadius(); } @@ -1199,7 +1200,7 @@ public class VideoPlayerImpl extends VideoPlayer } @Override - public void showControls(long duration) { + public void showControls(final long duration) { if (queueVisible) return; showOrHideButtons(); @@ -1208,7 +1209,7 @@ public class VideoPlayerImpl extends VideoPlayer } @Override - public void hideControls(final long duration, long delay) { + public void hideControls(final long duration, final long delay) { if (DEBUG) Log.d(TAG, "hideControls() called with: delay = [" + delay + "]"); showOrHideButtons(); @@ -1231,7 +1232,7 @@ public class VideoPlayerImpl extends VideoPlayer private void showSystemUIPartially() { if (isFullscreen() && getParentActivity() != null) { - int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE; getParentActivity().getWindow().getDecorView().setSystemUiVisibility(visibility); } } @@ -1247,40 +1248,40 @@ public class VideoPlayerImpl extends VideoPlayer * NavigationBar and notches but not under them. Tablets have only bottom NavigationBar */ public void setControlsSize() { - Point size = new Point(); - Display display = getRootView().getDisplay(); + final Point size = new Point(); + final Display display = getRootView().getDisplay(); if (display == null || !videoPlayerSelected()) return; // This method will give a correct size of a usable area of a window. // It doesn't include NavigationBar, notches, etc. display.getSize(size); - int width = isFullscreen ? (service.isLandscape() ? size.x : size.y) : ViewGroup.LayoutParams.MATCH_PARENT; - int gravity = isFullscreen ? (display.getRotation() == Surface.ROTATION_90 ? Gravity.START : Gravity.END) : Gravity.TOP; + final int width = isFullscreen ? (service.isLandscape() ? size.x : size.y) : ViewGroup.LayoutParams.MATCH_PARENT; + final int gravity = isFullscreen ? (display.getRotation() == Surface.ROTATION_90 ? Gravity.START : Gravity.END) : Gravity.TOP; getTopControlsRoot().getLayoutParams().width = width; - RelativeLayout.LayoutParams topParams = ((RelativeLayout.LayoutParams) getTopControlsRoot().getLayoutParams()); + final RelativeLayout.LayoutParams topParams = ((RelativeLayout.LayoutParams) getTopControlsRoot().getLayoutParams()); topParams.removeRule(RelativeLayout.ALIGN_PARENT_START); topParams.removeRule(RelativeLayout.ALIGN_PARENT_END); topParams.addRule(gravity == Gravity.END ? RelativeLayout.ALIGN_PARENT_END : RelativeLayout.ALIGN_PARENT_START); getTopControlsRoot().requestLayout(); getBottomControlsRoot().getLayoutParams().width = width; - RelativeLayout.LayoutParams bottomParams = ((RelativeLayout.LayoutParams) getBottomControlsRoot().getLayoutParams()); + final RelativeLayout.LayoutParams bottomParams = ((RelativeLayout.LayoutParams) getBottomControlsRoot().getLayoutParams()); bottomParams.removeRule(RelativeLayout.ALIGN_PARENT_START); bottomParams.removeRule(RelativeLayout.ALIGN_PARENT_END); bottomParams.addRule(gravity == Gravity.END ? RelativeLayout.ALIGN_PARENT_END : RelativeLayout.ALIGN_PARENT_START); getBottomControlsRoot().requestLayout(); - ViewGroup controlsRoot = getRootView().findViewById(R.id.playbackWindowRoot); + final ViewGroup controlsRoot = getRootView().findViewById(R.id.playbackWindowRoot); // In tablet navigationBar located at the bottom of the screen. And the situations when we need to set custom height is // in fullscreen mode in tablet in non-multiWindow mode or with vertical video. Other than that MATCH_PARENT is good - boolean navBarAtTheBottom = PlayerHelper.isTablet(service) || !service.isLandscape(); + final boolean navBarAtTheBottom = PlayerHelper.isTablet(service) || !service.isLandscape(); controlsRoot.getLayoutParams().height = isFullscreen && !isInMultiWindow() && navBarAtTheBottom ? size.y : ViewGroup.LayoutParams.MATCH_PARENT; controlsRoot.requestLayout(); - int topPadding = isFullscreen && !isInMultiWindow() ? getStatusBarHeight() : 0; + final int topPadding = isFullscreen && !isInMultiWindow() ? getStatusBarHeight() : 0; getRootView().findViewById(R.id.playbackWindowRoot).setPadding(0, topPadding, 0, 0); getRootView().findViewById(R.id.playbackWindowRoot).requestLayout(); } @@ -1290,11 +1291,11 @@ public class VideoPlayerImpl extends VideoPlayer */ private int getStatusBarHeight() { int statusBarHeight = 0; - int resourceId = service.getResources().getIdentifier("status_bar_height_landscape", "dimen", "android"); + final int resourceId = service.getResources().getIdentifier("status_bar_height_landscape", "dimen", "android"); if (resourceId > 0) statusBarHeight = service.getResources().getDimensionPixelSize(resourceId); if (statusBarHeight == 0) { // Some devices provide wrong value for status bar height in landscape mode, this is workaround - DisplayMetrics metrics = getRootView().getResources().getDisplayMetrics(); + final DisplayMetrics metrics = getRootView().getResources().getDisplayMetrics(); statusBarHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, metrics); } return statusBarHeight; @@ -1304,7 +1305,7 @@ public class VideoPlayerImpl extends VideoPlayer * @return true if main player is attached to activity and activity inside multiWindow mode */ private boolean isInMultiWindow() { - AppCompatActivity parent = getParentActivity(); + final AppCompatActivity parent = getParentActivity(); return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && parent != null && parent.isInMultiWindowMode(); } @@ -1317,9 +1318,9 @@ public class VideoPlayerImpl extends VideoPlayer } public void checkLandscape() { - AppCompatActivity parent = getParentActivity(); - boolean videoInLandscapeButNotInFullscreen = service.isLandscape() && !isFullscreen() && videoPlayerSelected() && !audioOnly; - boolean playingState = getCurrentState() != STATE_COMPLETED && getCurrentState() != STATE_PAUSED; + final AppCompatActivity parent = getParentActivity(); + final boolean videoInLandscapeButNotInFullscreen = service.isLandscape() && !isFullscreen() && videoPlayerSelected() && !audioOnly; + final boolean playingState = getCurrentState() != STATE_COMPLETED && getCurrentState() != STATE_PAUSED; if (parent != null && videoInLandscapeButNotInFullscreen && playingState && !PlayerHelper.isTablet(service)) toggleFullscreen(); @@ -1342,7 +1343,7 @@ public class VideoPlayerImpl extends VideoPlayer itemsListCloseButton.setOnClickListener(view -> onQueueClosed()); } - public void useVideoSource(boolean video) { + public void useVideoSource(final boolean video) { if (playQueue == null || audioOnly == !video || audioPlayerSelected()) return; @@ -1415,7 +1416,7 @@ public class VideoPlayerImpl extends VideoPlayer final boolean popupRememberSizeAndPos = PlayerHelper.isRememberingPopupDimensions(service); final float defaultSize = service.getResources().getDimension(R.dimen.popup_default_width); - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(service); + final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(service); popupWidth = popupRememberSizeAndPos ? sharedPreferences.getFloat(POPUP_SAVED_WIDTH, defaultSize) : defaultSize; popupHeight = getMinimumVideoHeight(popupWidth); @@ -1428,8 +1429,8 @@ public class VideoPlayerImpl extends VideoPlayer popupLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; getSurfaceView().setHeights((int) popupHeight, (int) popupHeight); - int centerX = (int) (screenWidth / 2f - popupWidth / 2f); - int centerY = (int) (screenHeight / 2f - popupHeight / 2f); + final int centerX = (int) (screenWidth / 2f - popupWidth / 2f); + final int centerY = (int) (screenHeight / 2f - popupHeight / 2f); popupLayoutParams.x = popupRememberSizeAndPos ? sharedPreferences.getInt(POPUP_SAVED_X, centerX) : centerX; popupLayoutParams.y = popupRememberSizeAndPos ? sharedPreferences.getInt(POPUP_SAVED_Y, centerY) : centerY; @@ -1458,7 +1459,7 @@ public class VideoPlayerImpl extends VideoPlayer 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( + final WindowManager.LayoutParams closeOverlayLayoutParams = new WindowManager.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, popupLayoutParamType(), flags, @@ -1523,19 +1524,19 @@ public class VideoPlayerImpl extends VideoPlayer } public void savePositionAndSize() { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(service); + final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(service); sharedPreferences.edit().putInt(POPUP_SAVED_X, popupLayoutParams.x).apply(); sharedPreferences.edit().putInt(POPUP_SAVED_Y, popupLayoutParams.y).apply(); sharedPreferences.edit().putFloat(POPUP_SAVED_WIDTH, popupLayoutParams.width).apply(); } - private float getMinimumVideoHeight(float width) { + private float getMinimumVideoHeight(final float width) { //if (DEBUG) Log.d(TAG, "getMinimumVideoHeight() called with: width = [" + width + "], returned: " + height); return width / (16.0f / 9.0f); // Respect the 16:9 ratio that most videos have } public void updateScreenSize() { - DisplayMetrics metrics = new DisplayMetrics(); + final DisplayMetrics metrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(metrics); screenWidth = metrics.widthPixels; @@ -1604,7 +1605,7 @@ public class VideoPlayerImpl extends VideoPlayer } public void removePopupFromView() { - boolean isCloseOverlayHasParent = closeOverlayView != null && closeOverlayView.getParent() != null; + final boolean isCloseOverlayHasParent = closeOverlayView != null && closeOverlayView.getParent() != null; if (popupHasParent()) windowManager.removeView(getRootView()); if (isCloseOverlayHasParent) @@ -1640,7 +1641,7 @@ public class VideoPlayerImpl extends VideoPlayer } private boolean popupHasParent() { - View root = getRootView(); + final View root = getRootView(); return root != null && root.getLayoutParams() instanceof WindowManager.LayoutParams && root.getParent() != null; } @@ -1648,27 +1649,27 @@ public class VideoPlayerImpl extends VideoPlayer // Manipulations with listener /////////////////////////////////////////////////////////////////////////// - public void setFragmentListener(PlayerServiceEventListener listener) { + public void setFragmentListener(final PlayerServiceEventListener listener) { fragmentListener = listener; updateMetadata(); updatePlayback(); triggerProgressUpdate(); } - public void removeFragmentListener(PlayerServiceEventListener listener) { + public void removeFragmentListener(final PlayerServiceEventListener listener) { if (fragmentListener == listener) { fragmentListener = null; } } - /*package-private*/ void setActivityListener(PlayerEventListener listener) { + void setActivityListener(final PlayerEventListener listener) { activityListener = listener; updateMetadata(); updatePlayback(); triggerProgressUpdate(); } - /*package-private*/ void removeActivityListener(PlayerEventListener listener) { + void removeActivityListener(final PlayerEventListener listener) { if (activityListener == listener) { activityListener = null; } @@ -1703,7 +1704,7 @@ public class VideoPlayerImpl extends VideoPlayer } } - private void updateProgress(int currentProgress, int duration, int bufferPercent) { + private void updateProgress(final int currentProgress, final int duration, final int bufferPercent) { if (fragmentListener != null) { fragmentListener.onProgressUpdate(currentProgress, duration, bufferPercent); } @@ -1787,11 +1788,11 @@ public class VideoPlayerImpl extends VideoPlayer return popupHeight; } - public void setPopupWidth(float width) { + public void setPopupWidth(final float width) { popupWidth = width; } - public void setPopupHeight(float height) { + public void setPopupHeight(final float height) { popupHeight = height; } diff --git a/app/src/main/java/org/schabi/newpipe/player/event/CustomBottomSheetBehavior.java b/app/src/main/java/org/schabi/newpipe/player/event/CustomBottomSheetBehavior.java index 9d4707666..24ef5dffc 100644 --- a/app/src/main/java/org/schabi/newpipe/player/event/CustomBottomSheetBehavior.java +++ b/app/src/main/java/org/schabi/newpipe/player/event/CustomBottomSheetBehavior.java @@ -16,14 +16,14 @@ import java.util.List; public class CustomBottomSheetBehavior extends BottomSheetBehavior { - public CustomBottomSheetBehavior(Context context, AttributeSet attrs) { + public CustomBottomSheetBehavior(final Context context, final AttributeSet attrs) { super(context, attrs); } boolean visible; Rect globalRect = new Rect(); private boolean skippingInterception = false; - private List skipInterceptionOfElements = Arrays.asList( + private final List skipInterceptionOfElements = Arrays.asList( R.id.detail_content_root_layout, R.id.relatedStreamsLayout, R.id.playQueuePanel, R.id.viewpager); @Override @@ -38,8 +38,8 @@ public class CustomBottomSheetBehavior extends BottomSheetBehavior // Don't need to do anything if bottomSheet isn't expanded if (getState() == BottomSheetBehavior.STATE_EXPANDED) { // Without overriding scrolling will not work when user touches these elements - for (Integer element : skipInterceptionOfElements) { - ViewGroup viewGroup = child.findViewById(element); + for (final Integer element : skipInterceptionOfElements) { + final ViewGroup viewGroup = child.findViewById(element); if (viewGroup != null) { visible = viewGroup.getGlobalVisibleRect(globalRect); if (visible && globalRect.contains((int) event.getRawX(), (int) event.getRawY())) { 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 f8b402103..8e4a5c2ac 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 @@ -20,8 +20,8 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen private static final String TAG = ".PlayerGestureListener"; private static final boolean DEBUG = BasePlayer.DEBUG; - private VideoPlayerImpl playerImpl; - private MainPlayer service; + private final VideoPlayerImpl playerImpl; + private final MainPlayer service; private int initialPopupX, initialPopupY; @@ -29,7 +29,7 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen private boolean isResizing; - private int tossFlingVelocity; + private final int tossFlingVelocity; private final boolean isVolumeGestureEnabled; private final boolean isBrightnessGestureEnabled; @@ -114,9 +114,9 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen //////////////////////////////////////////////////////////////////////////*/ private boolean onDoubleTapInMain(MotionEvent e) { - if (e.getX() > playerImpl.getRootView().getWidth() * 2 / 3) { + if (e.getX() > playerImpl.getRootView().getWidth() * 2.0 / 3.0) { playerImpl.onFastForward(); - } else if (e.getX() < playerImpl.getRootView().getWidth() / 3) { + } else if (e.getX() < playerImpl.getRootView().getWidth() / 3.0) { playerImpl.onFastRewind(); } else { playerImpl.getPlayPauseButton().performClick(); @@ -143,7 +143,8 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen return true; } - private boolean onScrollInMain(MotionEvent initialEvent, MotionEvent movingEvent, float distanceX, float distanceY) { + private boolean onScrollInMain(final MotionEvent initialEvent, final MotionEvent movingEvent, + final float distanceX, final float distanceY) { if (!isVolumeGestureEnabled && !isBrightnessGestureEnabled) return false; //noinspection PointlessBooleanExpression @@ -162,9 +163,9 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen if (isVolumeGestureEnabled && initialEvent.getX() > playerImpl.getRootView().getWidth() / 2.0) { playerImpl.getVolumeProgressBar().incrementProgressBy((int) distanceY); - float currentProgressPercent = + final float currentProgressPercent = (float) playerImpl.getVolumeProgressBar().getProgress() / playerImpl.getMaxGestureLength(); - int currentVolume = (int) (maxVolume * currentProgressPercent); + final int currentVolume = (int) (maxVolume * currentProgressPercent); playerImpl.getAudioReactor().setVolume(currentVolume); if (DEBUG) Log.d(TAG, "onScroll().volumeControl, currentVolume = " + currentVolume); @@ -183,15 +184,15 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen playerImpl.getBrightnessRelativeLayout().setVisibility(View.GONE); } } else if (isBrightnessGestureEnabled && initialEvent.getX() <= playerImpl.getRootView().getWidth() / 2.0) { - Activity parent = playerImpl.getParentActivity(); + final Activity parent = playerImpl.getParentActivity(); if (parent == null) return true; - Window window = parent.getWindow(); + final Window window = parent.getWindow(); playerImpl.getBrightnessProgressBar().incrementProgressBy((int) distanceY); - float currentProgressPercent = + final float currentProgressPercent = (float) playerImpl.getBrightnessProgressBar().getProgress() / playerImpl.getMaxGestureLength(); - WindowManager.LayoutParams layoutParams = window.getAttributes(); + final WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.screenBrightness = currentProgressPercent; window.setAttributes(layoutParams); @@ -306,8 +307,10 @@ public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListen isMovingInPopup = true; - float diffX = (int) (movingEvent.getRawX() - initialEvent.getRawX()), posX = (int) (initialPopupX + diffX); - float diffY = (int) (movingEvent.getRawY() - initialEvent.getRawY()), posY = (int) (initialPopupY + diffY); + final float diffX = (int) (movingEvent.getRawX() - initialEvent.getRawX()); + float posX = (int) (initialPopupX + diffX); + final float diffY = (int) (movingEvent.getRawY() - initialEvent.getRawY()); + float posY = (int) (initialPopupY + diffY); if (posX > (playerImpl.getScreenWidth() - playerImpl.getPopupWidth())) posX = (int) (playerImpl.getScreenWidth() - playerImpl.getPopupWidth()); else if (posX < 0) posX = 0; diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java index e739b8f33..482b36100 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java @@ -46,7 +46,7 @@ public abstract class PlayQueue implements Serializable { private ArrayList backup; private ArrayList streams; - private ArrayList history; + private final ArrayList history; @NonNull private final AtomicInteger queueIndex; private transient BehaviorSubject eventBroadcast; @@ -132,7 +132,7 @@ public abstract class PlayQueue implements Serializable { * Returns the item at the given index. * May throw {@link IndexOutOfBoundsException}. * */ - public PlayQueueItem getItem(int index) { + public PlayQueueItem getItem(final int index) { if (index < 0 || index >= streams.size() || streams.get(index) == null) return null; return streams.get(index); } @@ -235,7 +235,7 @@ public abstract class PlayQueue implements Serializable { * Will emit a {@link AppendEvent} on any given context. * */ public synchronized void append(@NonNull final List items) { - List itemList = new ArrayList<>(items); + final List itemList = new ArrayList<>(items); if (isShuffled()) { backup.addAll(itemList); @@ -300,8 +300,7 @@ public abstract class PlayQueue implements Serializable { } if (backup != null) { - final int backupIndex = backup.indexOf(getItem(removeIndex)); - backup.remove(backupIndex); + backup.remove(getItem(removeIndex)); } history.remove(streams.remove(removeIndex)); @@ -332,7 +331,7 @@ public abstract class PlayQueue implements Serializable { queueIndex.incrementAndGet(); } - PlayQueueItem playQueueItem = streams.remove(source); + final PlayQueueItem playQueueItem = streams.remove(source); playQueueItem.setAutoQueued(false); streams.add(target, playQueueItem); broadcast(new MoveEvent(source, target)); @@ -431,7 +430,7 @@ public abstract class PlayQueue implements Serializable { history.remove(history.size() - 1); - PlayQueueItem last = history.remove(history.size() - 1); + final PlayQueueItem last = history.remove(history.size() - 1); setIndex(indexOf(last)); return true; @@ -443,11 +442,11 @@ public abstract class PlayQueue implements Serializable { * VideoDetailFragment without duplicating items from two identical queues * */ @Override - public boolean equals(@Nullable Object obj) { + public boolean equals(@Nullable final Object obj) { if (!(obj instanceof PlayQueue) || getStreams().size() != ((PlayQueue) obj).getStreams().size()) return false; - PlayQueue other = (PlayQueue) obj; + final PlayQueue other = (PlayQueue) obj; for (int i = 0; i < getStreams().size(); i++) { if (!getItem(i).getUrl().equals(other.getItem(i).getUrl())) return false; 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 f0fd7e41b..e897e827f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -114,13 +114,25 @@ public class NavigationHelper { .putExtra(BasePlayer.PLAYBACK_SKIP_SILENCE, playbackSkipSilence); } - public static void playOnMainPlayer(final AppCompatActivity activity, final PlayQueue queue, final boolean autoPlay) { + public static void playOnMainPlayer( + final AppCompatActivity activity, + final PlayQueue queue, + final boolean autoPlay) { playOnMainPlayer(activity.getSupportFragmentManager(), queue, autoPlay); } - public static void playOnMainPlayer(final FragmentManager fragmentManager, final PlayQueue queue, boolean autoPlay) { - PlayQueueItem currentStream = queue.getItem(); - openVideoDetailFragment(fragmentManager, currentStream.getServiceId(), currentStream.getUrl(), currentStream.getTitle(), autoPlay, queue); + public static void playOnMainPlayer( + final FragmentManager fragmentManager, + final PlayQueue queue, + final boolean autoPlay) { + final PlayQueueItem currentStream = queue.getItem(); + openVideoDetailFragment( + fragmentManager, + currentStream.getServiceId(), + currentStream.getUrl(), + currentStream.getTitle(), + autoPlay, + queue); } public static void playOnMainPlayer(@NonNull final Context context, @@ -131,7 +143,7 @@ public class NavigationHelper { final boolean autoPlay, final boolean resumePlayback) { - Intent intent = getPlayerIntent(context, MainActivity.class, queue, resumePlayback); + final 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); @@ -147,14 +159,14 @@ public class NavigationHelper { } Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show(); - Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback); + final Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback); intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_POPUP); startService(context, intent); } public static void playOnBackgroundPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) { Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT).show(); - Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback); + final Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback); intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_AUDIO); startService(context, intent); } @@ -170,7 +182,7 @@ public class NavigationHelper { } Toast.makeText(context, R.string.popup_playing_append, Toast.LENGTH_SHORT).show(); - Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue, selectOnAppend, resumePlayback); + final Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue, selectOnAppend, resumePlayback); intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_POPUP); startService(context, intent); } @@ -179,9 +191,9 @@ public class NavigationHelper { enqueueOnBackgroundPlayer(context, queue, false, resumePlayback); } - public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue, boolean selectOnAppend, final boolean resumePlayback) { + public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue, final boolean selectOnAppend, final boolean resumePlayback) { Toast.makeText(context, R.string.background_player_append, Toast.LENGTH_SHORT).show(); - Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue, selectOnAppend, resumePlayback); + final Intent intent = getPlayerEnqueueIntent(context, MainPlayer.class, queue, selectOnAppend, resumePlayback); intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_AUDIO); startService(context, intent); } @@ -307,25 +319,31 @@ public class NavigationHelper { openVideoDetailFragment(fragmentManager, serviceId, url, title, true, null); } - public static void openVideoDetailFragment(FragmentManager fragmentManager, int serviceId, String url, String title, boolean autoPlay, PlayQueue playQueue) { - Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_player_holder); + public static void openVideoDetailFragment( + FragmentManager fragmentManager, + int serviceId, + String url, + String title, + boolean autoPlay, + PlayQueue playQueue) { + final Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_player_holder); if (title == null) title = ""; if (fragment instanceof VideoDetailFragment && fragment.isVisible()) { - expandMainPlayer(fragment.getActivity()); - VideoDetailFragment detailFragment = (VideoDetailFragment) fragment; + expandMainPlayer(fragment.requireActivity()); + final VideoDetailFragment detailFragment = (VideoDetailFragment) fragment; detailFragment.setAutoplay(autoPlay); detailFragment.selectAndLoadVideo(serviceId, url, title, playQueue); detailFragment.scrollToTop(); return; } - VideoDetailFragment instance = VideoDetailFragment.getInstance(serviceId, url, title, playQueue); + final VideoDetailFragment instance = VideoDetailFragment.getInstance(serviceId, url, title, playQueue); instance.setAutoplay(autoPlay); defaultTransaction(fragmentManager) .replace(R.id.fragment_player_holder, instance) - .runOnCommit(() -> expandMainPlayer(instance.getActivity())) + .runOnCommit(() -> expandMainPlayer(instance.requireActivity())) .commit(); } @@ -335,9 +353,9 @@ public class NavigationHelper { } public static void openChannelFragment( - FragmentManager fragmentManager, - int serviceId, - String url, + final FragmentManager fragmentManager, + final int serviceId, + final String url, String name) { if (name == null) name = ""; defaultTransaction(fragmentManager) @@ -525,7 +543,7 @@ public class NavigationHelper { case STREAM: rIntent.putExtra(VideoDetailFragment.AUTO_PLAY, PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(context.getString(R.string.autoplay_through_intent_key), false)); + .getBoolean(context.getString(R.string.autoplay_through_intent_key), false)); break; } @@ -558,6 +576,7 @@ public class NavigationHelper { /** * Start an activity to install Kore + * * @param context the context */ public static void installKore(Context context) { @@ -566,13 +585,13 @@ public class NavigationHelper { /** * Start Kore app to show a video on Kodi - * + *

* For a list of supported urls see the * - * Kore source code + * Kore source code * . * - * @param context the context to use + * @param context the context to use * @param videoURL the url to the video */ public static void playWithKore(Context context, Uri videoURL) { 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 f5a7df471..3d69e9cdc 100644 --- a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java +++ b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java @@ -25,14 +25,14 @@ public class ExpandableSurfaceView extends SurfaceView { if (videoAspectRatio == 0.0f) return; int width = MeasureSpec.getSize(widthMeasureSpec); - boolean verticalVideo = videoAspectRatio < 1; + final boolean verticalVideo = videoAspectRatio < 1; // Use maxHeight only on non-fit resize mode and in vertical videos int height = maxHeight != 0 && resizeMode != AspectRatioFrameLayout.RESIZE_MODE_FIT && verticalVideo ? maxHeight : baseHeight; if (height == 0) return; - float viewAspectRatio = width / ((float) height); - float aspectDeformation = videoAspectRatio / viewAspectRatio - 1; + final float viewAspectRatio = width / ((float) height); + final float aspectDeformation = videoAspectRatio / viewAspectRatio - 1; scaleX = 1.0f; scaleY = 1.0f; @@ -73,15 +73,14 @@ public class ExpandableSurfaceView extends SurfaceView { * @param base The height that will be used in every resize mode as a minimum height * @param max The max height for vertical videos in non-FIT resize modes */ - public void setHeights(int base, int max) { + public void setHeights(final int base, final int max) { if (baseHeight == base && maxHeight == max) return; baseHeight = base; maxHeight = max; requestLayout(); } - @AspectRatioFrameLayout.ResizeMode - public void setResizeMode(int newResizeMode) { + public void setResizeMode(@AspectRatioFrameLayout.ResizeMode final int newResizeMode) { if (resizeMode == newResizeMode) return; resizeMode = newResizeMode; @@ -93,7 +92,7 @@ public class ExpandableSurfaceView extends SurfaceView { return resizeMode; } - public void setAspectRatio(float aspectRatio) { + public void setAspectRatio(final float aspectRatio) { if (videoAspectRatio == aspectRatio) return; videoAspectRatio = aspectRatio;