mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Extract 2 view click listeners from Player
This commit is contained in:
parent
37aca3f1c7
commit
080c4ba680
@ -167,6 +167,8 @@ import org.schabi.newpipe.player.helper.MediaSessionManager;
|
||||
import org.schabi.newpipe.player.helper.PlaybackParameterDialog;
|
||||
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.playback.CustomTrackSelector;
|
||||
import org.schabi.newpipe.player.playback.MediaSourceManager;
|
||||
import org.schabi.newpipe.player.playback.PlaybackListener;
|
||||
@ -530,9 +532,12 @@ public final class Player implements
|
||||
}
|
||||
|
||||
private void initListeners() {
|
||||
binding.qualityTextView.setOnClickListener(
|
||||
new QualityTextListener(this, qualityPopupMenu));
|
||||
binding.playbackSpeed.setOnClickListener(
|
||||
new PlaybackSpeedListener(this, playbackSpeedPopupMenu));
|
||||
|
||||
binding.playbackSeekBar.setOnSeekBarChangeListener(this);
|
||||
binding.playbackSpeed.setOnClickListener(this);
|
||||
binding.qualityTextView.setOnClickListener(this);
|
||||
binding.captionTextView.setOnClickListener(this);
|
||||
binding.resizeTextView.setOnClickListener(this);
|
||||
binding.playbackLiveSync.setOnClickListener(this);
|
||||
@ -1926,7 +1931,7 @@ public final class Player implements
|
||||
}, delay);
|
||||
}
|
||||
|
||||
private void showHideShadow(final boolean show, final long duration) {
|
||||
public void showHideShadow(final boolean show, final long duration) {
|
||||
animate(binding.playbackControlsShadow, show, duration, AnimationType.ALPHA, 0, null);
|
||||
animate(binding.playerTopShadow, show, duration, AnimationType.ALPHA, 0, null);
|
||||
animate(binding.playerBottomShadow, show, duration, AnimationType.ALPHA, 0, null);
|
||||
@ -3742,11 +3747,7 @@ public final class Player implements
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onClick() called with: v = [" + v + "]");
|
||||
}
|
||||
if (v.getId() == binding.qualityTextView.getId()) {
|
||||
onQualitySelectorClicked();
|
||||
} else if (v.getId() == binding.playbackSpeed.getId()) {
|
||||
onPlaybackSpeedClicked();
|
||||
} else if (v.getId() == binding.resizeTextView.getId()) {
|
||||
if (v.getId() == binding.resizeTextView.getId()) {
|
||||
onResizeClicked();
|
||||
} else if (v.getId() == binding.captionTextView.getId()) {
|
||||
onCaptionClicked();
|
||||
@ -4446,6 +4447,10 @@ public final class Player implements
|
||||
return isSomePopupMenuVisible;
|
||||
}
|
||||
|
||||
public void setSomePopupMenuVisible(final boolean somePopupMenuVisible) {
|
||||
isSomePopupMenuVisible = somePopupMenuVisible;
|
||||
}
|
||||
|
||||
public ImageButton getPlayPauseButton() {
|
||||
return binding.playPauseButton;
|
||||
}
|
||||
@ -4527,6 +4532,11 @@ public final class Player implements
|
||||
public PlayQueueAdapter getPlayQueueAdapter() {
|
||||
return playQueueAdapter;
|
||||
}
|
||||
|
||||
public PlayerBinding getBinding() {
|
||||
return binding;
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
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.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