mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-10 12:00:03 +00:00
Refactored code
This commit is contained in:
parent
d348c2099e
commit
30a8f25d52
@ -166,8 +166,8 @@ import org.schabi.newpipe.player.helper.LoadController;
|
|||||||
import org.schabi.newpipe.player.helper.MediaSessionManager;
|
import org.schabi.newpipe.player.helper.MediaSessionManager;
|
||||||
import org.schabi.newpipe.player.helper.PlayerDataSource;
|
import org.schabi.newpipe.player.helper.PlayerDataSource;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHelper;
|
import org.schabi.newpipe.player.helper.PlayerHelper;
|
||||||
import org.schabi.newpipe.player.listeners.view.PlaybackSpeedListener;
|
import org.schabi.newpipe.player.listeners.view.PlaybackSpeedClickListener;
|
||||||
import org.schabi.newpipe.player.listeners.view.QualityTextListener;
|
import org.schabi.newpipe.player.listeners.view.QualityClickListener;
|
||||||
import org.schabi.newpipe.player.playback.CustomTrackSelector;
|
import org.schabi.newpipe.player.playback.CustomTrackSelector;
|
||||||
import org.schabi.newpipe.player.playback.MediaSourceManager;
|
import org.schabi.newpipe.player.playback.MediaSourceManager;
|
||||||
import org.schabi.newpipe.player.playback.PlaybackListener;
|
import org.schabi.newpipe.player.playback.PlaybackListener;
|
||||||
@ -532,9 +532,9 @@ public final class Player implements
|
|||||||
|
|
||||||
private void initListeners() {
|
private void initListeners() {
|
||||||
binding.qualityTextView.setOnClickListener(
|
binding.qualityTextView.setOnClickListener(
|
||||||
new QualityTextListener(this, qualityPopupMenu));
|
new QualityClickListener(this, qualityPopupMenu));
|
||||||
binding.playbackSpeed.setOnClickListener(
|
binding.playbackSpeed.setOnClickListener(
|
||||||
new PlaybackSpeedListener(this, playbackSpeedPopupMenu));
|
new PlaybackSpeedClickListener(this, playbackSpeedPopupMenu));
|
||||||
|
|
||||||
binding.playbackSeekBar.setOnSeekBarChangeListener(this);
|
binding.playbackSeekBar.setOnSeekBarChangeListener(this);
|
||||||
binding.captionTextView.setOnClickListener(this);
|
binding.captionTextView.setOnClickListener(this);
|
||||||
@ -3772,23 +3772,33 @@ public final class Player implements
|
|||||||
context.sendBroadcast(new Intent(VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER));
|
context.sendBroadcast(new Intent(VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentState != STATE_COMPLETED) {
|
afterOnClick(v);
|
||||||
controlsVisibilityHandler.removeCallbacksAndMessages(null);
|
}
|
||||||
showHideShadow(true, DEFAULT_CONTROLS_DURATION);
|
|
||||||
animate(binding.playbackControlRoot, true, DEFAULT_CONTROLS_DURATION,
|
/**
|
||||||
AnimationType.ALPHA, 0, () -> {
|
* Function that should be executed after a click occured on the player UI.
|
||||||
if (currentState == STATE_PLAYING && !isSomePopupMenuVisible) {
|
* @param v – The view that was clicked
|
||||||
if (v.getId() == binding.playPauseButton.getId()
|
*/
|
||||||
// Hide controls in fullscreen immediately
|
public void afterOnClick(@NonNull final View v) {
|
||||||
|| (v.getId() == binding.screenRotationButton.getId()
|
if (currentState == STATE_COMPLETED) {
|
||||||
&& isFullscreen)) {
|
return;
|
||||||
hideControls(0, 0);
|
|
||||||
} else {
|
|
||||||
hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user