mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 11:02:35 +01:00
Use Optional.map correctly and other improvements
This commit is contained in:
parent
e8216b2e80
commit
9c7ed80662
@ -255,7 +255,9 @@ public final class VideoDetailFragment
|
||||
playerUi.ifPresent(MainPlayerUi::toggleFullscreen);
|
||||
}
|
||||
|
||||
if (playAfterConnect || (currentInfo != null && isAutoplayEnabled()
|
||||
if (playAfterConnect
|
||||
|| (currentInfo != null
|
||||
&& isAutoplayEnabled()
|
||||
&& playerUi.isEmpty())) {
|
||||
autoPlayEnabled = true; // forcefully start playing
|
||||
openVideoPlayerAutoFullscreen();
|
||||
@ -1883,8 +1885,9 @@ public final class VideoDetailFragment
|
||||
@Override
|
||||
public void onFullscreenStateChanged(final boolean fullscreen) {
|
||||
setupBrightness();
|
||||
if (!isPlayerAndPlayerServiceAvailable() || player.UIs().get(MainPlayerUi.class).isEmpty()
|
||||
|| getRoot().map(View::getParent).isEmpty()) {
|
||||
if (!isPlayerAndPlayerServiceAvailable()
|
||||
|| player.UIs().get(MainPlayerUi.class).isEmpty()
|
||||
|| getRoot().flatMap(v -> Optional.ofNullable(v.getParent())).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1875,8 +1875,7 @@ public final class Player implements PlaybackListener, Listener {
|
||||
loadController.disablePreloadingOfCurrentTrack();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public VideoStream getSelectedVideoStream() {
|
||||
public Optional<VideoStream> getSelectedVideoStream() {
|
||||
return Optional.ofNullable(currentMetadata)
|
||||
.flatMap(MediaItemTag::getMaybeQuality)
|
||||
.filter(quality -> {
|
||||
@ -1885,8 +1884,7 @@ public final class Player implements PlaybackListener, Listener {
|
||||
&& selectedStreamIndex < quality.getSortedVideoStreams().size();
|
||||
})
|
||||
.map(quality -> quality.getSortedVideoStreams()
|
||||
.get(quality.getSelectedVideoStreamIndex()))
|
||||
.orElse(null);
|
||||
.get(quality.getSelectedVideoStreamIndex()));
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
@ -62,8 +62,8 @@ public interface MediaItemTag {
|
||||
@NonNull
|
||||
static Optional<MediaItemTag> from(@Nullable final MediaItem mediaItem) {
|
||||
return Optional.ofNullable(mediaItem)
|
||||
.map(item -> item.localConfiguration)
|
||||
.map(localConfiguration -> localConfiguration.tag)
|
||||
.flatMap(item -> Optional.ofNullable(item.localConfiguration))
|
||||
.flatMap(localConfiguration -> Optional.ofNullable(localConfiguration.tag))
|
||||
.filter(MediaItemTag.class::isInstance)
|
||||
.map(MediaItemTag.class::cast);
|
||||
}
|
||||
|
@ -1060,12 +1060,11 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa
|
||||
qualityPopupMenu.getMenu().add(POPUP_MENU_ID_QUALITY, i, Menu.NONE, MediaFormat
|
||||
.getNameById(videoStream.getFormatId()) + " " + videoStream.getResolution());
|
||||
}
|
||||
final VideoStream selectedVideoStream = player.getSelectedVideoStream();
|
||||
if (selectedVideoStream != null) {
|
||||
binding.qualityTextView.setText(selectedVideoStream.getResolution());
|
||||
}
|
||||
qualityPopupMenu.setOnMenuItemClickListener(this);
|
||||
qualityPopupMenu.setOnDismissListener(this);
|
||||
|
||||
player.getSelectedVideoStream()
|
||||
.ifPresent(s -> binding.qualityTextView.setText(s.getResolution()));
|
||||
}
|
||||
|
||||
private void buildPlaybackSpeedMenu() {
|
||||
@ -1171,12 +1170,9 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa
|
||||
qualityPopupMenu.show();
|
||||
isSomePopupMenuVisible = true;
|
||||
|
||||
final VideoStream videoStream = player.getSelectedVideoStream();
|
||||
if (videoStream != null) {
|
||||
//noinspection SetTextI18n
|
||||
binding.qualityTextView.setText(MediaFormat.getNameById(videoStream.getFormatId())
|
||||
+ " " + videoStream.getResolution());
|
||||
}
|
||||
player.getSelectedVideoStream()
|
||||
.map(s -> MediaFormat.getNameById(s.getFormatId()) + " " + s.getResolution())
|
||||
.ifPresent(binding.qualityTextView::setText);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1232,10 +1228,9 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa
|
||||
Log.d(TAG, "onDismiss() called with: menu = [" + menu + "]");
|
||||
}
|
||||
isSomePopupMenuVisible = false; //TODO check if this works
|
||||
final VideoStream selectedVideoStream = player.getSelectedVideoStream();
|
||||
if (selectedVideoStream != null) {
|
||||
binding.qualityTextView.setText(selectedVideoStream.getResolution());
|
||||
}
|
||||
player.getSelectedVideoStream()
|
||||
.ifPresent(s -> binding.qualityTextView.setText(s.getResolution()));
|
||||
|
||||
if (player.isPlaying()) {
|
||||
hideControls(DEFAULT_CONTROLS_DURATION, 0);
|
||||
hideSystemUIIfNeeded();
|
||||
|
Loading…
Reference in New Issue
Block a user