-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8011 from XiangRongLin/extract_view_listeners
Extract view click listeners from Player
- Loading branch information
Showing
4 changed files
with
172 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedClickListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.schabi.newpipe.player.listeners.view | ||
|
||
import android.util.Log | ||
import android.view.View | ||
import androidx.appcompat.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.manageControlsAfterOnClick(v) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/org/schabi/newpipe/player/listeners/view/QualityClickListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.schabi.newpipe.player.listeners.view | ||
|
||
import android.annotation.SuppressLint | ||
import android.util.Log | ||
import android.view.View | ||
import androidx.appcompat.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.manageControlsAfterOnClick(v) | ||
} | ||
} |
Oops, something went wrong.