-
-
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
Conversation
import org.schabi.newpipe.player.Player | ||
import org.schabi.newpipe.player.helper.PlaybackParameterDialog | ||
|
||
class PlaybackSpeedListener( |
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.
Some documentation would be good in that class.
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.
Problem is I don't know what the listener does. The focus of the PR is extracting the code out of the player. Adding documentation would require more effort, which I don't want to put into it.
import org.schabi.newpipe.player.Player | ||
import org.schabi.newpipe.player.helper.PlaybackParameterDialog | ||
|
||
class PlaybackSpeedListener( |
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.
I would rename it to PlaybackSpeedClickListener
} | ||
|
||
override fun onClick(v: View) { | ||
if (player.binding.qualityTextView.id == v.id) { |
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.
this if is useless
app/src/main/java/org/schabi/newpipe/player/listeners/view/PlaybackSpeedListener.kt
Outdated
Show resolved
Hide resolved
import org.schabi.newpipe.extractor.MediaFormat | ||
import org.schabi.newpipe.player.Player | ||
|
||
class QualityTextListener( |
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.
Same statements as above also apply for this class
val qualityText = ( | ||
MediaFormat.getNameById(videoStream.formatId) + " " + | ||
videoStream.resolution | ||
) |
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.
Are the (
)
required?
import org.schabi.newpipe.extractor.MediaFormat | ||
import org.schabi.newpipe.player.Player | ||
|
||
class QualityTextListener( |
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.
Would rename the class to QualityTextClickListener
In my personal opinion those listeners would look much better as lambdas/method references, like: binding.qualityTextView.setOnClickListener(this::onQualitySelectorClicked); What I don't like much about listeners in separate classes, other than the pre-Java 8 kind of verbosity, is that it's being introduced a layer of "public-internal" APIs (like |
if (v.getId() == binding.qualityTextView.getId()) { | ||
onQualitySelectorClicked(); | ||
} else if (v.getId() == binding.playbackSpeed.getId()) { |
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
if (currentState != STATE_COMPLETED) { | |
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); | |
} | |
} | |
}); |
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)
7397d3e
to
6765135
Compare
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.
Fixed problems myself.
@Stypox You may check my implementation of manageControlsAfterOnClick
😄
Kudos, SonarCloud Quality Gate passed! |
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.
I tested and it works, thank you :-)
What is it?
Description of the changes in your PR
Fixes the following issue(s)
Due diligence