Skip to content

Commit d1954ba

Browse files
authored
Merge pull request #11829 from Profpatsch/PlayerUIList-to-kotlin
Player UI list to kotlin
2 parents 7cecda5 + a8da994 commit d1954ba

8 files changed

Lines changed: 194 additions & 112 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void onPlayerConnected(@NonNull final Player connectedPlayer,
246246
// It will do nothing if the player is not in fullscreen mode
247247
hideSystemUiIfNeeded();
248248

249-
final Optional<MainPlayerUi> playerUi = player.UIs().get(MainPlayerUi.class);
249+
final Optional<MainPlayerUi> playerUi = player.UIs().getOpt(MainPlayerUi.class);
250250
if (!player.videoPlayerSelected() && !playAfterConnect) {
251251
return;
252252
}
@@ -529,7 +529,7 @@ private void setOnClickListeners() {
529529
binding.overlayPlayPauseButton.setOnClickListener(v -> {
530530
if (playerIsNotStopped()) {
531531
player.playPause();
532-
player.UIs().get(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
532+
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
533533
showSystemUi();
534534
} else {
535535
autoPlayEnabled = true; // forcefully start playing
@@ -688,7 +688,7 @@ protected void initListeners() {
688688
@Override
689689
public boolean onKeyDown(final int keyCode) {
690690
return isPlayerAvailable()
691-
&& player.UIs().get(VideoPlayerUi.class)
691+
&& player.UIs().getOpt(VideoPlayerUi.class)
692692
.map(playerUi -> playerUi.onKeyDown(keyCode)).orElse(false);
693693
}
694694

@@ -1028,7 +1028,7 @@ private void toggleFullscreenIfInFullscreenMode() {
10281028
// If a user watched video inside fullscreen mode and than chose another player
10291029
// return to non-fullscreen mode
10301030
if (isPlayerAvailable()) {
1031-
player.UIs().get(MainPlayerUi.class).ifPresent(playerUi -> {
1031+
player.UIs().getOpt(MainPlayerUi.class).ifPresent(playerUi -> {
10321032
if (playerUi.isFullscreen()) {
10331033
playerUi.toggleFullscreen();
10341034
}
@@ -1244,7 +1244,7 @@ private void tryAddVideoPlayerView() {
12441244
// setup the surface view height, so that it fits the video correctly
12451245
setHeightThumbnail();
12461246

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

12621262
if (player != null) {
1263-
player.UIs().get(VideoPlayerUi.class).ifPresent(VideoPlayerUi::removeViewFromParent);
1263+
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(VideoPlayerUi::removeViewFromParent);
12641264
}
12651265
}
12661266

@@ -1327,7 +1327,7 @@ private void setHeightThumbnail(final int newHeight, final DisplayMetrics metric
13271327
binding.detailThumbnailImageView.setMinimumHeight(newHeight);
13281328
if (isPlayerAvailable()) {
13291329
final int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT);
1330-
player.UIs().get(VideoPlayerUi.class).ifPresent(ui ->
1330+
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(ui ->
13311331
ui.getBinding().surfaceView.setHeights(newHeight,
13321332
ui.isFullscreen() ? newHeight : maxHeight));
13331333
}
@@ -1861,7 +1861,7 @@ public void onServiceStopped() {
18611861
public void onFullscreenStateChanged(final boolean fullscreen) {
18621862
setupBrightness();
18631863
if (!isPlayerAndPlayerServiceAvailable()
1864-
|| player.UIs().get(MainPlayerUi.class).isEmpty()
1864+
|| player.UIs().getOpt(MainPlayerUi.class).isEmpty()
18651865
|| getRoot().map(View::getParent).isEmpty()) {
18661866
return;
18671867
}
@@ -1890,7 +1890,7 @@ public void onScreenRotationButtonClicked() {
18901890
final boolean isLandscape = DeviceUtils.isLandscape(requireContext());
18911891
if (DeviceUtils.isTablet(activity)
18921892
&& (!globalScreenOrientationLocked(activity) || isLandscape)) {
1893-
player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen);
1893+
player.UIs().getOpt(MainPlayerUi.class).ifPresent(MainPlayerUi::toggleFullscreen);
18941894
return;
18951895
}
18961896

@@ -1990,7 +1990,7 @@ public void hideSystemUiIfNeeded() {
19901990
}
19911991

19921992
private boolean isFullscreen() {
1993-
return isPlayerAvailable() && player.UIs().get(VideoPlayerUi.class)
1993+
return isPlayerAvailable() && player.UIs().getOpt(VideoPlayerUi.class)
19941994
.map(VideoPlayerUi::isFullscreen).orElse(false);
19951995
}
19961996

@@ -2067,7 +2067,7 @@ private void checkLandscape() {
20672067
setAutoPlay(true);
20682068
}
20692069

2070-
player.UIs().get(MainPlayerUi.class).ifPresent(MainPlayerUi::checkLandscape);
2070+
player.UIs().getOpt(MainPlayerUi.class).ifPresent(MainPlayerUi::checkLandscape);
20712071
// Let's give a user time to look at video information page if video is not playing
20722072
if (globalScreenOrientationLocked(activity) && !player.isPlaying()) {
20732073
player.play();
@@ -2332,7 +2332,7 @@ && isPlayerAvailable()
23322332
&& player.isPlaying()
23332333
&& !isFullscreen()
23342334
&& !DeviceUtils.isTablet(activity)) {
2335-
player.UIs().get(MainPlayerUi.class)
2335+
player.UIs().getOpt(MainPlayerUi.class)
23362336
.ifPresent(MainPlayerUi::toggleFullscreen);
23372337
}
23382338
setOverlayLook(binding.appBarLayout, behavior, 1);
@@ -2346,7 +2346,7 @@ && isPlayerAvailable()
23462346
// Re-enable clicks
23472347
setOverlayElementsClickable(true);
23482348
if (isPlayerAvailable()) {
2349-
player.UIs().get(MainPlayerUi.class)
2349+
player.UIs().getOpt(MainPlayerUi.class)
23502350
.ifPresent(MainPlayerUi::closeItemsList);
23512351
}
23522352
setOverlayLook(binding.appBarLayout, behavior, 0);
@@ -2357,7 +2357,7 @@ && isPlayerAvailable()
23572357
showSystemUi();
23582358
}
23592359
if (isPlayerAvailable()) {
2360-
player.UIs().get(MainPlayerUi.class).ifPresent(ui -> {
2360+
player.UIs().getOpt(MainPlayerUi.class).ifPresent(ui -> {
23612361
if (ui.isControlsVisible()) {
23622362
ui.hideControls(0, 0);
23632363
}
@@ -2454,7 +2454,7 @@ boolean isPlayerAndPlayerServiceAvailable() {
24542454

24552455
public Optional<View> getRoot() {
24562456
return Optional.ofNullable(player)
2457-
.flatMap(player1 -> player1.UIs().get(VideoPlayerUi.class))
2457+
.flatMap(player1 -> player1.UIs().getOpt(VideoPlayerUi.class))
24582458
.map(playerUi -> playerUi.getBinding().getRoot());
24592459
}
24602460

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,15 @@ public void handleIntent(@NonNull final Intent intent) {
473473
}
474474

475475
private void initUIsForCurrentPlayerType() {
476-
if ((UIs.get(MainPlayerUi.class).isPresent() && playerType == PlayerType.MAIN)
477-
|| (UIs.get(PopupPlayerUi.class).isPresent() && playerType == PlayerType.POPUP)) {
476+
if ((UIs.getOpt(MainPlayerUi.class).isPresent() && playerType == PlayerType.MAIN)
477+
|| (UIs.getOpt(PopupPlayerUi.class).isPresent()
478+
&& playerType == PlayerType.POPUP)) {
478479
// correct UI already in place
479480
return;
480481
}
481482

482483
// try to reuse binding if possible
483-
final PlayerBinding binding = UIs.get(VideoPlayerUi.class).map(VideoPlayerUi::getBinding)
484+
final PlayerBinding binding = UIs.getOpt(VideoPlayerUi.class).map(VideoPlayerUi::getBinding)
484485
.orElseGet(() -> {
485486
if (playerType == PlayerType.AUDIO) {
486487
return null;

app/src/main/java/org/schabi/newpipe/player/PlayerService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
148148
// no one already and starting the service in foreground should not create any issues.
149149
// If the service is already started in foreground, requesting it to be started
150150
// shouldn't do anything.
151-
player.UIs().get(NotificationPlayerUi.class)
151+
player.UIs().getOpt(NotificationPlayerUi.class)
152152
.ifPresent(NotificationPlayerUi::createNotificationAndStartForeground);
153153

154154
if (playerWasNull && onPlayerStartedOrStopped != null) {
@@ -173,7 +173,7 @@ public int onStartCommand(final Intent intent, final int flags, final int startI
173173

174174
if (player != null) {
175175
player.handleIntent(intent);
176-
player.UIs().get(MediaSessionPlayerUi.class)
176+
player.UIs().getOpt(MediaSessionPlayerUi.class)
177177
.ifPresent(ui -> ui.handleMediaButtonIntent(intent));
178178
}
179179

app/src/main/java/org/schabi/newpipe/player/mediasession/MediaSessionPlayerUi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private ForwardingPlayer getForwardingPlayer() {
138138
public void play() {
139139
player.play();
140140
// hide the player controls even if the play command came from the media session
141-
player.UIs().get(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
141+
player.UIs().getOpt(VideoPlayerUi.class).ifPresent(ui -> ui.hideControls(0, 0));
142142
}
143143

144144
@Override

app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private synchronized NotificationCompat.Builder createNotification() {
102102
mediaStyle.setShowActionsInCompactView(compactSlots);
103103
}
104104
player.UIs()
105-
.get(MediaSessionPlayerUi.class)
105+
.getOpt(MediaSessionPlayerUi.class)
106106
.flatMap(MediaSessionPlayerUi::getSessionToken)
107107
.ifPresent(mediaStyle::setMediaSession);
108108

app/src/main/java/org/schabi/newpipe/player/ui/PlayerUiList.java

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)