diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 54f12db8b..c06e2f2d4 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -166,8 +166,8 @@ import org.schabi.newpipe.player.helper.LoadController; import org.schabi.newpipe.player.helper.MediaSessionManager; import org.schabi.newpipe.player.helper.PlayerDataSource; import org.schabi.newpipe.player.helper.PlayerHelper; -import org.schabi.newpipe.player.listeners.view.PlaybackSpeedListener; -import org.schabi.newpipe.player.listeners.view.QualityTextListener; +import org.schabi.newpipe.player.listeners.view.PlaybackSpeedClickListener; +import org.schabi.newpipe.player.listeners.view.QualityClickListener; import org.schabi.newpipe.player.playback.CustomTrackSelector; import org.schabi.newpipe.player.playback.MediaSourceManager; import org.schabi.newpipe.player.playback.PlaybackListener; @@ -532,9 +532,9 @@ public final class Player implements private void initListeners() { binding.qualityTextView.setOnClickListener( - new QualityTextListener(this, qualityPopupMenu)); + new QualityClickListener(this, qualityPopupMenu)); binding.playbackSpeed.setOnClickListener( - new PlaybackSpeedListener(this, playbackSpeedPopupMenu)); + new PlaybackSpeedClickListener(this, playbackSpeedPopupMenu)); binding.playbackSeekBar.setOnSeekBarChangeListener(this); binding.captionTextView.setOnClickListener(this); @@ -3772,23 +3772,33 @@ public final class Player implements context.sendBroadcast(new Intent(VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER)); } - if (currentState != STATE_COMPLETED) { - controlsVisibilityHandler.removeCallbacksAndMessages(null); - showHideShadow(true, DEFAULT_CONTROLS_DURATION); - animate(binding.playbackControlRoot, true, DEFAULT_CONTROLS_DURATION, - AnimationType.ALPHA, 0, () -> { - if (currentState == STATE_PLAYING && !isSomePopupMenuVisible) { - if (v.getId() == binding.playPauseButton.getId() - // Hide controls in fullscreen immediately - || (v.getId() == binding.screenRotationButton.getId() - && isFullscreen)) { - hideControls(0, 0); - } else { - hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME); - } - } - }); + afterOnClick(v); + } + + /** + * Function that should be executed after a click occured on the player UI. + * @param v – The view that was clicked + */ + public void afterOnClick(@NonNull final View v) { + if (currentState == STATE_COMPLETED) { + return; } + + controlsVisibilityHandler.removeCallbacksAndMessages(null); + showHideShadow(true, DEFAULT_CONTROLS_DURATION); + animate(binding.playbackControlRoot, true, DEFAULT_CONTROLS_DURATION, + AnimationType.ALPHA, 0, () -> { + if (currentState == STATE_PLAYING && !isSomePopupMenuVisible) { + if (v.getId() == binding.playPauseButton.getId() + // Hide controls in fullscreen immediately + || (v.getId() == binding.screenRotationButton.getId() + && isFullscreen)) { + hideControls(0, 0); + } else { + hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME); + } + } + }); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedClickListener.kt b/app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedClickListener.kt new file mode 100644 index 000000000..b256b084a --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedClickListener.kt @@ -0,0 +1,47 @@ +package org.schabi.newpipe.player.listeners.view + +import android.util.Log +import android.view.View +import android.widget.PopupMenu +import org.schabi.newpipe.MainActivity +import org.schabi.newpipe.player.Player +import org.schabi.newpipe.player.helper.PlaybackParameterDialog + +/** + * Click listener for the playbackSpeed textview of the player + */ +class PlaybackSpeedClickListener( + private val player: Player, + private val playbackSpeedPopupMenu: PopupMenu +) : View.OnClickListener { + + companion object { + private const val TAG: String = "PlaybSpeedClickListener" + } + + override fun onClick(v: View) { + if (MainActivity.DEBUG) { + Log.d(TAG, "onPlaybackSpeedClicked() called") + } + + if (player.videoPlayerSelected()) { + PlaybackParameterDialog.newInstance( + player.playbackSpeed.toDouble(), + player.playbackPitch.toDouble(), + player.playbackSkipSilence + ) { speed: Float, pitch: Float, skipSilence: Boolean -> + player.setPlaybackParameters( + speed, + pitch, + skipSilence + ) + } + .show(player.parentActivity!!.supportFragmentManager, null) + } else { + playbackSpeedPopupMenu.show() + player.isSomePopupMenuVisible = true + } + + player.afterOnClick(v) + } +} diff --git a/app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedListener.kt b/app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedListener.kt deleted file mode 100644 index a616e3c7e..000000000 --- a/app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedListener.kt +++ /dev/null @@ -1,46 +0,0 @@ -package org.schabi.newpipe.player.listeners.view - -import android.util.Log -import android.view.View -import android.widget.PopupMenu -import org.schabi.newpipe.MainActivity -import org.schabi.newpipe.player.Player -import org.schabi.newpipe.player.helper.PlaybackParameterDialog - -class PlaybackSpeedListener( - private val player: Player, - private val playbackSpeedPopupMenu: PopupMenu - -) : View.OnClickListener { - - companion object { - private val DEBUG = MainActivity.DEBUG - private val TAG: String = PlaybackSpeedListener::class.java.simpleName - } - - override fun onClick(v: View) { - if (player.binding.qualityTextView.id == v.id) { - if (DEBUG) { - Log.d(TAG, "onPlaybackSpeedClicked() called") - } - - if (player.videoPlayerSelected()) { - PlaybackParameterDialog.newInstance( - player.playbackSpeed.toDouble(), - player.playbackPitch.toDouble(), - player.playbackSkipSilence - ) { speed: Float, pitch: Float, skipSilence: Boolean -> - player.setPlaybackParameters( - speed, - pitch, - skipSilence - ) - } - .show(player.parentActivity!!.supportFragmentManager, null) - } else { - playbackSpeedPopupMenu.show() - player.isSomePopupMenuVisible = true - } - } - } -} diff --git a/app/src/main/java/org/schabi/newpipe/player/listeners/view/QualityClickListener.kt b/app/src/main/java/org/schabi/newpipe/player/listeners/view/QualityClickListener.kt new file mode 100644 index 000000000..17a77dc78 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/player/listeners/view/QualityClickListener.kt @@ -0,0 +1,41 @@ +package org.schabi.newpipe.player.listeners.view + +import android.annotation.SuppressLint +import android.util.Log +import android.view.View +import android.widget.PopupMenu +import org.schabi.newpipe.MainActivity +import org.schabi.newpipe.extractor.MediaFormat +import org.schabi.newpipe.player.Player + +/** + * Click listener for the qualityTextView of the player + */ +class QualityClickListener( + private val player: Player, + private val qualityPopupMenu: PopupMenu +) : View.OnClickListener { + + companion object { + private const val TAG: String = "QualityClickListener" + } + + @SuppressLint("SetTextI18n") // we don't need I18N because of a " " + override fun onClick(v: View) { + if (MainActivity.DEBUG) { + Log.d(TAG, "onQualitySelectorClicked() called") + } + + qualityPopupMenu.show() + player.isSomePopupMenuVisible = true + + val videoStream = player.selectedVideoStream + if (videoStream != null) { + player.binding.qualityTextView.text = + MediaFormat.getNameById(videoStream.formatId) + " " + videoStream.resolution + } + + player.saveWasPlaying() + player.afterOnClick(v) + } +} diff --git a/app/src/main/java/org/schabi/newpipe/player/listeners/view/QualityTextListener.kt b/app/src/main/java/org/schabi/newpipe/player/listeners/view/QualityTextListener.kt deleted file mode 100644 index 58d4db9ea..000000000 --- a/app/src/main/java/org/schabi/newpipe/player/listeners/view/QualityTextListener.kt +++ /dev/null @@ -1,41 +0,0 @@ -package org.schabi.newpipe.player.listeners.view - -import android.util.Log -import android.view.View -import android.widget.PopupMenu -import org.schabi.newpipe.MainActivity -import org.schabi.newpipe.extractor.MediaFormat -import org.schabi.newpipe.player.Player - -class QualityTextListener( - private val player: Player, - private val qualityPopupMenu: PopupMenu -) : View.OnClickListener { - - companion object { - private val DEBUG = MainActivity.DEBUG - private val TAG: String = QualityTextListener::class.java.simpleName - } - - override fun onClick(v: View) { - if (player.binding.qualityTextView.id == v.id) { - if (DEBUG) { - Log.d(TAG, "onQualitySelectorClicked() called") - } - - qualityPopupMenu.show() - player.isSomePopupMenuVisible = true - - val videoStream = player.selectedVideoStream - if (videoStream != null) { - val qualityText = ( - MediaFormat.getNameById(videoStream.formatId) + " " + - videoStream.resolution - ) - player.binding.qualityTextView.text = qualityText - } - - player.saveWasPlaying() - } - } -}