@@ -31,7 +31,6 @@ import android.view.View
3131import android.view.View.OnLongClickListener
3232import android.view.View.OnTouchListener
3333import android.view.ViewGroup
34- import android.view.ViewParent
3534import android.view.ViewTreeObserver
3635import android.view.WindowManager
3736import android.view.animation.DecelerateInterpolator
@@ -126,10 +125,8 @@ import org.schabi.newpipe.util.image.CoilHelper.loadDetailsThumbnail
126125import java.util.LinkedList
127126import java.util.List
128127import java.util.Objects
129- import java.util.Optional
130128import java.util.concurrent.TimeUnit
131129import java.util.function.Consumer
132- import java.util.function.Function
133130import kotlin.math.abs
134131import kotlin.math.max
135132import kotlin.math.min
@@ -229,8 +226,8 @@ class VideoDetailFragment :
229226 // It will do nothing if the player is not in fullscreen mode
230227 hideSystemUiIfNeeded()
231228
232- val playerUi: Optional < MainPlayerUi > =
233- player!! .UIs ().getOpt< MainPlayerUi > (MainPlayerUi ::class .java)
229+ val playerUi: MainPlayerUi ? =
230+ player!! .UIs ().get (MainPlayerUi ::class .java)
234231 if (! player!! .videoPlayerSelected() && ! playAfterConnect) {
235232 return
236233 }
@@ -239,19 +236,22 @@ class VideoDetailFragment :
239236 // If the video is playing but orientation changed
240237 // let's make the video in fullscreen again
241238 checkLandscape()
242- } else if (playerUi.map<Boolean ?>(Function { ui: MainPlayerUi ? -> ui!! .isFullscreen() && ! ui.isVerticalVideo() })
243- .orElse(false ) && // Tablet UI has orientation-independent fullscreen
239+ } else if (playerUi != null &&
240+ playerUi.isFullscreen() &&
241+ ! playerUi.isVerticalVideo() &&
242+ // Tablet UI has orientation-independent fullscreen
244243 ! DeviceUtils .isTablet(activity)
245244 ) {
246245 // Device is in portrait orientation after rotation but UI is in fullscreen.
247246 // Return back to non-fullscreen state
248- playerUi.ifPresent( Consumer { obj : MainPlayerUi ? -> obj !! . toggleFullscreen() } )
247+ playerUi.toggleFullscreen()
249248 }
250249
251250 if (playAfterConnect ||
252251 (
253- currentInfo != null && this .isAutoplayEnabled &&
254- playerUi.isEmpty()
252+ currentInfo != null &&
253+ this .isAutoplayEnabled &&
254+ playerUi == null
255255 )
256256 ) {
257257 autoPlayEnabled = true // forcefully start playing
@@ -572,8 +572,7 @@ class VideoDetailFragment :
572572 View .OnClickListener { v: View ? ->
573573 if (playerIsNotStopped()) {
574574 player!! .playPause()
575- player!! .UIs ().getOpt<VideoPlayerUi >(VideoPlayerUi ::class .java)
576- .ifPresent(Consumer { ui: VideoPlayerUi ? -> ui!! .hideControls(0 , 0 ) })
575+ player!! .UIs ().get(VideoPlayerUi ::class .java)?.hideControls(0 , 0 )
577576 showSystemUi()
578577 } else {
579578 autoPlayEnabled = true // forcefully start playing
@@ -776,9 +775,7 @@ class VideoDetailFragment :
776775
777776 override fun onKeyDown (keyCode : Int ): Boolean {
778777 return this .isPlayerAvailable &&
779- player!! .UIs ().getOpt<VideoPlayerUi >(VideoPlayerUi ::class .java)
780- .map<Boolean ?>(Function { playerUi: VideoPlayerUi ? -> playerUi!! .onKeyDown(keyCode) })
781- .orElse(false )
778+ player!! .UIs ().get(VideoPlayerUi ::class .java)?.onKeyDown(keyCode) == true
782779 }
783780
784781 override fun onBackPressed (): Boolean {
@@ -1139,14 +1136,11 @@ class VideoDetailFragment :
11391136 // If a user watched video inside fullscreen mode and than chose another player
11401137 // return to non-fullscreen mode
11411138 if (this .isPlayerAvailable) {
1142- player!! .UIs ().getOpt<MainPlayerUi >(MainPlayerUi ::class .java)
1143- .ifPresent(
1144- Consumer { playerUi: MainPlayerUi ? ->
1145- if (playerUi!! .isFullscreen()) {
1146- playerUi.toggleFullscreen()
1147- }
1148- }
1149- )
1139+ player!! .UIs ().get(MainPlayerUi ::class .java)?.let {
1140+ if (it.isFullscreen) {
1141+ it.toggleFullscreen()
1142+ }
1143+ }
11501144 }
11511145 }
11521146
@@ -1290,14 +1284,14 @@ class VideoDetailFragment :
12901284 */
12911285 private fun hideMainPlayerOnLoadingNewStream () {
12921286 val root = this .root
1293- if (noPlayerServiceAvailable() || root.isEmpty() || ! player!! .videoPlayerSelected()) {
1287+ if (noPlayerServiceAvailable() || root == null || ! player!! .videoPlayerSelected()) {
12941288 return
12951289 }
12961290
12971291 removeVideoPlayerView()
12981292 if (this .isAutoplayEnabled) {
12991293 playerService!! .stopForImmediateReusing()
1300- root.ifPresent( Consumer { view : View -> view. setVisibility(View .GONE ) } )
1294+ root.setVisibility(View .GONE )
13011295 } else {
13021296 PlayerHolder .stopService()
13031297 }
@@ -1378,18 +1372,16 @@ class VideoDetailFragment :
13781372 }
13791373 // setup the surface view height, so that it fits the video correctly
13801374 setHeightThumbnail()
1381- player!! .UIs ().getOpt<MainPlayerUi >(MainPlayerUi ::class .java)
1382- .ifPresent(
1383- Consumer { playerUi: MainPlayerUi ? ->
1384- // sometimes binding would be null here, even though getView() != null above u.u
1385- if (binding != null ) {
1386- // prevent from re-adding a view multiple times
1387- playerUi!! .removeViewFromParent()
1388- binding!! .playerPlaceholder.addView(playerUi.getBinding().getRoot())
1389- playerUi.setupVideoSurfaceIfNeeded()
1390- }
1391- }
1392- )
1375+ player!! .UIs ().get(MainPlayerUi ::class .java)?.let { playerUi ->
1376+ val b = binding
1377+ // sometimes binding would be null here, even though getView() != null above u.u
1378+ if (b != null ) {
1379+ // prevent from re-adding a view multiple times
1380+ playerUi.removeViewFromParent()
1381+ b.playerPlaceholder.addView(playerUi.getBinding().getRoot())
1382+ playerUi.setupVideoSurfaceIfNeeded()
1383+ }
1384+ }
13931385 }
13941386 )
13951387 }
@@ -1398,8 +1390,7 @@ class VideoDetailFragment :
13981390 makeDefaultHeightForVideoPlaceholder()
13991391
14001392 if (player != null ) {
1401- player!! .UIs ().getOpt<VideoPlayerUi >(VideoPlayerUi ::class .java)
1402- .ifPresent(Consumer { obj: VideoPlayerUi ? -> obj!! .removeViewFromParent() })
1393+ player!! .UIs ().get(VideoPlayerUi ::class .java)?.removeViewFromParent()
14031394 }
14041395 }
14051396
@@ -1476,15 +1467,12 @@ class VideoDetailFragment :
14761467 binding!! .detailThumbnailImageView.setMinimumHeight(newHeight)
14771468 if (this .isPlayerAvailable) {
14781469 val maxHeight = (metrics.heightPixels * MAX_PLAYER_HEIGHT ).toInt()
1479- player!! .UIs ().getOpt<VideoPlayerUi >(VideoPlayerUi ::class .java)
1480- .ifPresent(
1481- Consumer { ui: VideoPlayerUi ? ->
1482- ui!! .getBinding().surfaceView.setHeights(
1483- newHeight,
1484- if (ui.isFullscreen()) newHeight else maxHeight
1485- )
1486- }
1470+ player!! .UIs ().get(VideoPlayerUi ::class .java)?.let {
1471+ it.binding.surfaceView.setHeights(
1472+ newHeight,
1473+ if (it.isFullscreen) newHeight else maxHeight
14871474 )
1475+ }
14881476 }
14891477 }
14901478
@@ -2067,9 +2055,9 @@ class VideoDetailFragment :
20672055
20682056 override fun onFullscreenStateChanged (fullscreen : Boolean ) {
20692057 setupBrightness()
2070- if (! this .isPlayerAndPlayerServiceAvailable || player !! . UIs ()
2071- .getOpt< MainPlayerUi >( MainPlayerUi ::class .java).isEmpty() ||
2072- this .root.map< ViewParent ?>( Function { obj : View ? -> obj !! .getParent() }).isEmpty()
2058+ if (! this .isPlayerAndPlayerServiceAvailable ||
2059+ player?. UIs ()?.get( MainPlayerUi ::class .java) == null ||
2060+ this .root?.parent == null
20732061 ) {
20742062 return
20752063 }
@@ -2098,8 +2086,7 @@ class VideoDetailFragment :
20982086 if (DeviceUtils .isTablet(activity) &&
20992087 (! PlayerHelper .globalScreenOrientationLocked(activity) || isLandscape)
21002088 ) {
2101- player!! .UIs ().getOpt<MainPlayerUi >(MainPlayerUi ::class .java)
2102- .ifPresent(Consumer { obj: MainPlayerUi ? -> obj!! .toggleFullscreen() })
2089+ player!! .UIs ().get(MainPlayerUi ::class .java)?.toggleFullscreen()
21032090 return
21042091 }
21052092
@@ -2205,10 +2192,8 @@ class VideoDetailFragment :
22052192 }
22062193
22072194 private val isFullscreen: Boolean
2208- get() = this .isPlayerAvailable && player!! .UIs ()
2209- .getOpt<VideoPlayerUi >(VideoPlayerUi ::class .java)
2210- .map<Boolean ?>(Function { obj: VideoPlayerUi ? -> obj!! .isFullscreen() })
2211- .orElse(false )
2195+ get() = this .isPlayerAvailable && player?.UIs ()
2196+ ?.get(VideoPlayerUi ::class .java)?.isFullscreen() == true
22122197
22132198 private fun playerIsNotStopped (): Boolean {
22142199 return this .isPlayerAvailable && ! player!! .isStopped()
@@ -2292,8 +2277,7 @@ class VideoDetailFragment :
22922277 setAutoPlay(true )
22932278 }
22942279
2295- player!! .UIs ().getOpt<MainPlayerUi >(MainPlayerUi ::class .java)
2296- .ifPresent(Consumer { obj: MainPlayerUi ? -> obj!! .checkLandscape() })
2280+ player!! .UIs ().get(MainPlayerUi ::class .java)?.checkLandscape()
22972281 // Let's give a user time to look at video information page if video is not playing
22982282 if (PlayerHelper .globalScreenOrientationLocked(activity) && ! player!! .isPlaying()) {
22992283 player!! .play()
@@ -2592,8 +2576,7 @@ class VideoDetailFragment :
25922576 player!! .isPlaying() &&
25932577 ! this @VideoDetailFragment.isFullscreen && ! DeviceUtils .isTablet(activity)
25942578 ) {
2595- player!! .UIs ().getOpt<MainPlayerUi >(MainPlayerUi ::class .java)
2596- .ifPresent(Consumer { obj: MainPlayerUi ? -> obj!! .toggleFullscreen() })
2579+ player!! .UIs ().get(MainPlayerUi ::class .java)?.toggleFullscreen()
25972580 }
25982581 setOverlayLook(binding!! .appBarLayout, behavior, 1f )
25992582 }
@@ -2607,8 +2590,7 @@ class VideoDetailFragment :
26072590 // Re-enable clicks
26082591 setOverlayElementsClickable(true )
26092592 if (this @VideoDetailFragment.isPlayerAvailable) {
2610- player!! .UIs ().getOpt<MainPlayerUi >(MainPlayerUi ::class .java)
2611- .ifPresent(Consumer { obj: MainPlayerUi ? -> obj!! .closeItemsList() })
2593+ player!! .UIs ().get(MainPlayerUi ::class .java)?.closeItemsList()
26122594 }
26132595 setOverlayLook(binding!! .appBarLayout, behavior, 0f )
26142596 }
@@ -2618,13 +2600,11 @@ class VideoDetailFragment :
26182600 showSystemUi()
26192601 }
26202602 if (this @VideoDetailFragment.isPlayerAvailable) {
2621- player!! .UIs ().getOpt<MainPlayerUi >(MainPlayerUi ::class .java).ifPresent(
2622- Consumer { ui: MainPlayerUi ? ->
2623- if (ui!! .isControlsVisible()) {
2624- ui.hideControls(0 , 0 )
2625- }
2603+ player!! .UIs ().get(MainPlayerUi ::class .java)?.let {
2604+ if (it.isControlsVisible) {
2605+ it.hideControls(0 , 0 )
26262606 }
2627- )
2607+ }
26282608 }
26292609 }
26302610
@@ -2726,18 +2706,8 @@ class VideoDetailFragment :
27262706 val isPlayerAndPlayerServiceAvailable: Boolean
27272707 get() = player != null && playerService != null
27282708
2729- val root: Optional <View ?>
2730- get() = Optional .ofNullable<Player ?>(player)
2731- .flatMap<VideoPlayerUi ?>(
2732- Function { player1: Player ? ->
2733- player1!! .UIs ().getOpt<VideoPlayerUi >(VideoPlayerUi ::class .java)
2734- }
2735- )
2736- .map<View ?>(
2737- Function { playerUi: VideoPlayerUi ? ->
2738- playerUi!! .getBinding().getRoot()
2739- }
2740- )
2709+ val root: View ?
2710+ get() = player?.UIs ()?.get(VideoPlayerUi ::class .java)?.binding?.root
27412711
27422712 private fun updateBottomSheetState (newState : Int ) {
27432713 bottomSheetState = newState
0 commit comments