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,7 +3772,18 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
controlsVisibilityHandler.removeCallbacksAndMessages(null);
|
||||||
showHideShadow(true, DEFAULT_CONTROLS_DURATION);
|
showHideShadow(true, DEFAULT_CONTROLS_DURATION);
|
||||||
animate(binding.playbackControlRoot, true, DEFAULT_CONTROLS_DURATION,
|
animate(binding.playbackControlRoot, true, DEFAULT_CONTROLS_DURATION,
|
||||||
|
@ -3789,7 +3800,6 @@ public final class Player implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(final View v) {
|
public boolean onLongClick(final View v) {
|
||||||
|
|
|
@ -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