-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract view click listeners from Player #8011
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
080c4ba
Extract 2 view click listeners from Player
XiangRongLin 6a400dd
delete unused methods
XiangRongLin d348c20
stupid checkstyle
XiangRongLin 30a8f25
Refactored code
litetex ee5e0e1
Made ``onClick`` less (cognitive) complex
litetex cefb524
Better naming
litetex 6765135
Fixed conflicts
litetex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I've just noticed now that those listeners can't even be extracted from here since there is the following logic at the end of the
onClick
method that runs regardless of the item that gets clicked:NewPipe/app/src/main/java/org/schabi/newpipe/player/Player.java
Lines 3738 to 3753 in 47f9ed0
There are only a few branches in
onClick
that do an early return and can therefore be safely extracted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe that part could be extracted in a player function? Something like
maintainControlsShown
or something like that (I think there is a particular verb for that in the english language but I cannot remember it rn)