Skip to content
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

Player UI list to kotlin #11829

Open
wants to merge 3 commits into
base: refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void onServiceConnected(final Player connectedPlayer,
// It will do nothing if the player is not in fullscreen mode
hideSystemUiIfNeeded();

final Optional<MainPlayerUi> playerUi = player.UIs().get(MainPlayerUi.class);
final Optional<MainPlayerUi> playerUi = player.UIs().getOpt(MainPlayerUi.class);
if (!player.videoPlayerSelected() && !playAfterConnect) {
return;
}
Expand Down Expand Up @@ -519,7 +519,7 @@ private void setOnClickListeners() {
binding.overlayPlayPauseButton.setOnClickListener(v -> {
if (playerIsNotStopped()) {
player.playPause();
player.UIs().get(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
showSystemUi();
} else {
autoPlayEnabled = true; // forcefully start playing
Expand Down Expand Up @@ -678,7 +678,7 @@ protected void initListeners() {
@Override
public boolean onKeyDown(final int keyCode) {
return isPlayerAvailable()
&& player.UIs().get(VideoPlayerUi.class)
&& player.UIs().getOpt(VideoPlayerUi.class)
.map(playerUi -> playerUi.onKeyDown(keyCode)).orElse(false);
}

Expand Down Expand Up @@ -1018,7 +1018,7 @@ private void toggleFullscreenIfInFullscreenMode() {
// If a user watched video inside fullscreen mode and than chose another player
// return to non-fullscreen mode
if (isPlayerAvailable()) {
player.UIs().get(MainPlayerUi.class).ifPresent(playerUi -> {
player.UIs().getOpt(MainPlayerUi.class).ifPresent(playerUi -> {
if (playerUi.isFullscreen()) {
playerUi.toggleFullscreen();
}
Expand Down Expand Up @@ -1234,7 +1234,7 @@ private void tryAddVideoPlayerView() {
// setup the surface view height, so that it fits the video correctly
setHeightThumbnail();

player.UIs().get(MainPlayerUi.class).ifPresent(playerUi -> {
player.UIs().getOpt(MainPlayerUi.class).ifPresent(playerUi -> {
// sometimes binding would be null here, even though getView() != null above u.u
if (binding != null) {
// prevent from re-adding a view multiple times
Expand All @@ -1250,7 +1250,7 @@ private void removeVideoPlayerView() {
makeDefaultHeightForVideoPlaceholder();

if (player != null) {
player.UIs().get(VideoPlayerUi.class).ifPresent(VideoPlayerUi::removeViewFromParent);
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(VideoPlayerUi::removeViewFromParent);
}
}

Expand Down Expand Up @@ -1317,7 +1317,7 @@ private void setHeightThumbnail(final int newHeight, final DisplayMetrics metric
binding.detailThumbnailImageView.setMinimumHeight(newHeight);
if (isPlayerAvailable()) {
final int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT);
player.UIs().get(VideoPlayerUi.class).ifPresent(ui ->
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(ui ->
ui.getBinding().surfaceView.setHeights(newHeight,
ui.isFullscreen() ? newHeight : maxHeight));
}
Expand Down Expand Up @@ -1848,7 +1848,7 @@ public void onServiceStopped() {
public void onFullscreenStateChanged(final boolean fullscreen) {
setupBrightness();
if (!isPlayerAndPlayerServiceAvailable()
|| player.UIs().get(MainPlayerUi.class).isEmpty()
|| player.UIs().getOpt(MainPlayerUi.class).isEmpty()
|| getRoot().map(View::getParent).isEmpty()) {
return;
}
Expand Down Expand Up @@ -1877,7 +1877,7 @@ public void onScreenRotationButtonClicked() {
final boolean isLandscape = DeviceUtils.isLandscape(requireContext());
if (DeviceUtils.isTablet(activity)
&& (!globalScreenOrientationLocked(activity) || isLandscape)) {
player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen);
player.UIs().getOpt(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen);
return;
}

Expand Down Expand Up @@ -1977,7 +1977,7 @@ public void hideSystemUiIfNeeded() {
}

private boolean isFullscreen() {
return isPlayerAvailable() && player.UIs().get(VideoPlayerUi.class)
return isPlayerAvailable() && player.UIs().getOpt(VideoPlayerUi.class)
.map(VideoPlayerUi::isFullscreen).orElse(false);
}

Expand Down Expand Up @@ -2054,7 +2054,7 @@ private void checkLandscape() {
setAutoPlay(true);
}

player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::checkLandscape);
player.UIs().getOpt(MainPlayerUi.class).ifPresent(MainPlayerUi::checkLandscape);
// Let's give a user time to look at video information page if video is not playing
if (globalScreenOrientationLocked(activity) && !player.isPlaying()) {
player.play();
Expand Down Expand Up @@ -2319,7 +2319,7 @@ && isPlayerAvailable()
&& player.isPlaying()
&& !isFullscreen()
&& !DeviceUtils.isTablet(activity)) {
player.UIs().get(MainPlayerUi.class)
player.UIs().getOpt(MainPlayerUi.class)
.ifPresent(MainPlayerUi::toggleFullscreen);
}
setOverlayLook(binding.appBarLayout, behavior, 1);
Expand All @@ -2333,7 +2333,7 @@ && isPlayerAvailable()
// Re-enable clicks
setOverlayElementsClickable(true);
if (isPlayerAvailable()) {
player.UIs().get(MainPlayerUi.class)
player.UIs().getOpt(MainPlayerUi.class)
.ifPresent(MainPlayerUi::closeItemsList);
}
setOverlayLook(binding.appBarLayout, behavior, 0);
Expand All @@ -2344,7 +2344,7 @@ && isPlayerAvailable()
showSystemUi();
}
if (isPlayerAvailable()) {
player.UIs().get(MainPlayerUi.class).ifPresent(ui -> {
player.UIs().getOpt(MainPlayerUi.class).ifPresent(ui -> {
if (ui.isControlsVisible()) {
ui.hideControls(0, 0);
}
Expand Down Expand Up @@ -2441,7 +2441,7 @@ boolean isPlayerAndPlayerServiceAvailable() {

public Optional<View> getRoot() {
return Optional.ofNullable(player)
.flatMap(player1 -> player1.UIs().get(VideoPlayerUi.class))
.flatMap(player1 -> player1.UIs().getOpt(VideoPlayerUi.class))
.map(playerUi -> playerUi.getBinding().getRoot());
}

Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,15 @@ public void handleIntent(@NonNull final Intent intent) {
}

private void initUIsForCurrentPlayerType() {
if ((UIs.get(MainPlayerUi.class).isPresent() && playerType == PlayerType.MAIN)
|| (UIs.get(PopupPlayerUi.class).isPresent() && playerType == PlayerType.POPUP)) {
if ((UIs.getOpt(MainPlayerUi.class).isPresent() && playerType == PlayerType.MAIN)
|| (UIs.getOpt(PopupPlayerUi.class).isPresent()
&& playerType == PlayerType.POPUP)) {
// correct UI already in place
return;
}

// try to reuse binding if possible
final PlayerBinding binding = UIs.get(VideoPlayerUi.class).map(VideoPlayerUi::getBinding)
final PlayerBinding binding = UIs.getOpt(VideoPlayerUi.class).map(VideoPlayerUi::getBinding)
.orElseGet(() -> {
if (playerType == PlayerType.AUDIO) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ otherwise if nothing is played or initializing the player and its components (es
loading stream metadata) takes a lot of time, the app would crash on Android 8+ as the
service would never be put in the foreground while we said to the system we would do so
*/
player.UIs().get(NotificationPlayerUi.class)
player.UIs().getOpt(NotificationPlayerUi.class)
.ifPresent(NotificationPlayerUi::createNotificationAndStartForeground);
}

Expand All @@ -88,7 +88,7 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
do anything
*/
if (player != null) {
player.UIs().get(NotificationPlayerUi.class)
player.UIs().getOpt(NotificationPlayerUi.class)
.ifPresent(NotificationPlayerUi::createNotificationAndStartForeground);
}

Expand All @@ -106,7 +106,7 @@ public int onStartCommand(final Intent intent, final int flags, final int startI

if (player != null) {
player.handleIntent(intent);
player.UIs().get(MediaSessionPlayerUi.class)
player.UIs().getOpt(MediaSessionPlayerUi.class)
.ifPresent(ui -> ui.handleMediaButtonIntent(intent));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private ForwardingPlayer getForwardingPlayer() {
public void play() {
player.play();
// hide the player controls even if the play command came from the media session
player.UIs().get(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private synchronized NotificationCompat.Builder createNotification() {
mediaStyle.setShowActionsInCompactView(compactSlots);
}
player.UIs()
.get(MediaSessionPlayerUi.class)
.getOpt(MediaSessionPlayerUi.class)
.flatMap(MediaSessionPlayerUi::getSessionToken)
.ifPresent(mediaStyle::setMediaSession);

Expand Down
90 changes: 0 additions & 90 deletions app/src/main/java/org/schabi/newpipe/player/ui/PlayerUiList.java

This file was deleted.

Loading
Loading