mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-08-23 02:37:41 +00:00
VideoDetailFragment: replace every getOpt() with get()
This commit is contained in:
parent
38ed1da79e
commit
91aed1e240
@ -31,7 +31,6 @@ import android.view.View
|
|||||||
import android.view.View.OnLongClickListener
|
import android.view.View.OnLongClickListener
|
||||||
import android.view.View.OnTouchListener
|
import android.view.View.OnTouchListener
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewParent
|
|
||||||
import android.view.ViewTreeObserver
|
import android.view.ViewTreeObserver
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.view.animation.DecelerateInterpolator
|
import android.view.animation.DecelerateInterpolator
|
||||||
@ -126,10 +125,8 @@ import org.schabi.newpipe.util.image.CoilHelper.loadDetailsThumbnail
|
|||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.List
|
import java.util.List
|
||||||
import java.util.Objects
|
import java.util.Objects
|
||||||
import java.util.Optional
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
import java.util.function.Function
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
@ -229,8 +226,8 @@ class VideoDetailFragment :
|
|||||||
// It will do nothing if the player is not in fullscreen mode
|
// It will do nothing if the player is not in fullscreen mode
|
||||||
hideSystemUiIfNeeded()
|
hideSystemUiIfNeeded()
|
||||||
|
|
||||||
val playerUi: Optional<MainPlayerUi> =
|
val playerUi: MainPlayerUi? =
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java)
|
player!!.UIs().get(MainPlayerUi::class.java)
|
||||||
if (!player!!.videoPlayerSelected() && !playAfterConnect) {
|
if (!player!!.videoPlayerSelected() && !playAfterConnect) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -239,19 +236,22 @@ class VideoDetailFragment :
|
|||||||
// If the video is playing but orientation changed
|
// If the video is playing but orientation changed
|
||||||
// let's make the video in fullscreen again
|
// let's make the video in fullscreen again
|
||||||
checkLandscape()
|
checkLandscape()
|
||||||
} else if (playerUi.map<Boolean?>(Function { ui: MainPlayerUi? -> ui!!.isFullscreen() && !ui.isVerticalVideo() })
|
} else if (playerUi != null &&
|
||||||
.orElse(false) && // Tablet UI has orientation-independent fullscreen
|
playerUi.isFullscreen() &&
|
||||||
|
!playerUi.isVerticalVideo() &&
|
||||||
|
// Tablet UI has orientation-independent fullscreen
|
||||||
!DeviceUtils.isTablet(activity)
|
!DeviceUtils.isTablet(activity)
|
||||||
) {
|
) {
|
||||||
// Device is in portrait orientation after rotation but UI is in fullscreen.
|
// Device is in portrait orientation after rotation but UI is in fullscreen.
|
||||||
// Return back to non-fullscreen state
|
// Return back to non-fullscreen state
|
||||||
playerUi.ifPresent(Consumer { obj: MainPlayerUi? -> obj!!.toggleFullscreen() })
|
playerUi.toggleFullscreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playAfterConnect ||
|
if (playAfterConnect ||
|
||||||
(
|
(
|
||||||
currentInfo != null && this.isAutoplayEnabled &&
|
currentInfo != null &&
|
||||||
playerUi.isEmpty()
|
this.isAutoplayEnabled &&
|
||||||
|
playerUi == null
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
autoPlayEnabled = true // forcefully start playing
|
autoPlayEnabled = true // forcefully start playing
|
||||||
@ -572,8 +572,7 @@ class VideoDetailFragment :
|
|||||||
View.OnClickListener { v: View? ->
|
View.OnClickListener { v: View? ->
|
||||||
if (playerIsNotStopped()) {
|
if (playerIsNotStopped()) {
|
||||||
player!!.playPause()
|
player!!.playPause()
|
||||||
player!!.UIs().getOpt<VideoPlayerUi>(VideoPlayerUi::class.java)
|
player!!.UIs().get(VideoPlayerUi::class.java)?.hideControls(0, 0)
|
||||||
.ifPresent(Consumer { ui: VideoPlayerUi? -> ui!!.hideControls(0, 0) })
|
|
||||||
showSystemUi()
|
showSystemUi()
|
||||||
} else {
|
} else {
|
||||||
autoPlayEnabled = true // forcefully start playing
|
autoPlayEnabled = true // forcefully start playing
|
||||||
@ -776,9 +775,7 @@ class VideoDetailFragment :
|
|||||||
|
|
||||||
override fun onKeyDown(keyCode: Int): Boolean {
|
override fun onKeyDown(keyCode: Int): Boolean {
|
||||||
return this.isPlayerAvailable &&
|
return this.isPlayerAvailable &&
|
||||||
player!!.UIs().getOpt<VideoPlayerUi>(VideoPlayerUi::class.java)
|
player!!.UIs().get(VideoPlayerUi::class.java)?.onKeyDown(keyCode) == true
|
||||||
.map<Boolean?>(Function { playerUi: VideoPlayerUi? -> playerUi!!.onKeyDown(keyCode) })
|
|
||||||
.orElse(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
@ -1137,14 +1134,11 @@ class VideoDetailFragment :
|
|||||||
// If a user watched video inside fullscreen mode and than chose another player
|
// If a user watched video inside fullscreen mode and than chose another player
|
||||||
// return to non-fullscreen mode
|
// return to non-fullscreen mode
|
||||||
if (this.isPlayerAvailable) {
|
if (this.isPlayerAvailable) {
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java)
|
player!!.UIs().get(MainPlayerUi::class.java)?.let {
|
||||||
.ifPresent(
|
if (it.isFullscreen) {
|
||||||
Consumer { playerUi: MainPlayerUi? ->
|
it.toggleFullscreen()
|
||||||
if (playerUi!!.isFullscreen()) {
|
|
||||||
playerUi.toggleFullscreen()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1288,14 +1282,14 @@ class VideoDetailFragment :
|
|||||||
*/
|
*/
|
||||||
private fun hideMainPlayerOnLoadingNewStream() {
|
private fun hideMainPlayerOnLoadingNewStream() {
|
||||||
val root = this.root
|
val root = this.root
|
||||||
if (noPlayerServiceAvailable() || root.isEmpty() || !player!!.videoPlayerSelected()) {
|
if (noPlayerServiceAvailable() || root == null || !player!!.videoPlayerSelected()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
removeVideoPlayerView()
|
removeVideoPlayerView()
|
||||||
if (this.isAutoplayEnabled) {
|
if (this.isAutoplayEnabled) {
|
||||||
playerService!!.stopForImmediateReusing()
|
playerService!!.stopForImmediateReusing()
|
||||||
root.ifPresent(Consumer { view: View -> view.setVisibility(View.GONE) })
|
root.setVisibility(View.GONE)
|
||||||
} else {
|
} else {
|
||||||
PlayerHolder.stopService()
|
PlayerHolder.stopService()
|
||||||
}
|
}
|
||||||
@ -1376,18 +1370,16 @@ class VideoDetailFragment :
|
|||||||
}
|
}
|
||||||
// setup the surface view height, so that it fits the video correctly
|
// setup the surface view height, so that it fits the video correctly
|
||||||
setHeightThumbnail()
|
setHeightThumbnail()
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java)
|
player!!.UIs().get(MainPlayerUi::class.java)?.let { playerUi ->
|
||||||
.ifPresent(
|
val b = binding
|
||||||
Consumer { playerUi: MainPlayerUi? ->
|
|
||||||
// sometimes binding would be null here, even though getView() != null above u.u
|
// sometimes binding would be null here, even though getView() != null above u.u
|
||||||
if (binding != null) {
|
if (b != null) {
|
||||||
// prevent from re-adding a view multiple times
|
// prevent from re-adding a view multiple times
|
||||||
playerUi!!.removeViewFromParent()
|
playerUi.removeViewFromParent()
|
||||||
binding!!.playerPlaceholder.addView(playerUi.getBinding().getRoot())
|
b.playerPlaceholder.addView(playerUi.getBinding().getRoot())
|
||||||
playerUi.setupVideoSurfaceIfNeeded()
|
playerUi.setupVideoSurfaceIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1396,8 +1388,7 @@ class VideoDetailFragment :
|
|||||||
makeDefaultHeightForVideoPlaceholder()
|
makeDefaultHeightForVideoPlaceholder()
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player!!.UIs().getOpt<VideoPlayerUi>(VideoPlayerUi::class.java)
|
player!!.UIs().get(VideoPlayerUi::class.java)?.removeViewFromParent()
|
||||||
.ifPresent(Consumer { obj: VideoPlayerUi? -> obj!!.removeViewFromParent() })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1474,15 +1465,12 @@ class VideoDetailFragment :
|
|||||||
binding!!.detailThumbnailImageView.setMinimumHeight(newHeight)
|
binding!!.detailThumbnailImageView.setMinimumHeight(newHeight)
|
||||||
if (this.isPlayerAvailable) {
|
if (this.isPlayerAvailable) {
|
||||||
val maxHeight = (metrics.heightPixels * MAX_PLAYER_HEIGHT).toInt()
|
val maxHeight = (metrics.heightPixels * MAX_PLAYER_HEIGHT).toInt()
|
||||||
player!!.UIs().getOpt<VideoPlayerUi>(VideoPlayerUi::class.java)
|
player!!.UIs().get(VideoPlayerUi::class.java)?.let {
|
||||||
.ifPresent(
|
it.binding.surfaceView.setHeights(
|
||||||
Consumer { ui: VideoPlayerUi? ->
|
|
||||||
ui!!.getBinding().surfaceView.setHeights(
|
|
||||||
newHeight,
|
newHeight,
|
||||||
if (ui.isFullscreen()) newHeight else maxHeight
|
if (it.isFullscreen) newHeight else maxHeight
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2065,9 +2053,9 @@ class VideoDetailFragment :
|
|||||||
|
|
||||||
override fun onFullscreenStateChanged(fullscreen: Boolean) {
|
override fun onFullscreenStateChanged(fullscreen: Boolean) {
|
||||||
setupBrightness()
|
setupBrightness()
|
||||||
if (!this.isPlayerAndPlayerServiceAvailable || player!!.UIs()
|
if (!this.isPlayerAndPlayerServiceAvailable ||
|
||||||
.getOpt<MainPlayerUi>(MainPlayerUi::class.java).isEmpty() ||
|
player?.UIs()?.get(MainPlayerUi::class.java) == null ||
|
||||||
this.root.map<ViewParent?>(Function { obj: View? -> obj!!.getParent() }).isEmpty()
|
this.root?.parent == null
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2096,8 +2084,7 @@ class VideoDetailFragment :
|
|||||||
if (DeviceUtils.isTablet(activity) &&
|
if (DeviceUtils.isTablet(activity) &&
|
||||||
(!PlayerHelper.globalScreenOrientationLocked(activity) || isLandscape)
|
(!PlayerHelper.globalScreenOrientationLocked(activity) || isLandscape)
|
||||||
) {
|
) {
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java)
|
player!!.UIs().get(MainPlayerUi::class.java)?.toggleFullscreen()
|
||||||
.ifPresent(Consumer { obj: MainPlayerUi? -> obj!!.toggleFullscreen() })
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2203,10 +2190,8 @@ class VideoDetailFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val isFullscreen: Boolean
|
private val isFullscreen: Boolean
|
||||||
get() = this.isPlayerAvailable && player!!.UIs()
|
get() = this.isPlayerAvailable && player?.UIs()
|
||||||
.getOpt<VideoPlayerUi>(VideoPlayerUi::class.java)
|
?.get(VideoPlayerUi::class.java)?.isFullscreen() == true
|
||||||
.map<Boolean?>(Function { obj: VideoPlayerUi? -> obj!!.isFullscreen() })
|
|
||||||
.orElse(false)
|
|
||||||
|
|
||||||
private fun playerIsNotStopped(): Boolean {
|
private fun playerIsNotStopped(): Boolean {
|
||||||
return this.isPlayerAvailable && !player!!.isStopped()
|
return this.isPlayerAvailable && !player!!.isStopped()
|
||||||
@ -2290,8 +2275,7 @@ class VideoDetailFragment :
|
|||||||
setAutoPlay(true)
|
setAutoPlay(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java)
|
player!!.UIs().get(MainPlayerUi::class.java)?.checkLandscape()
|
||||||
.ifPresent(Consumer { obj: MainPlayerUi? -> obj!!.checkLandscape() })
|
|
||||||
// Let's give a user time to look at video information page if video is not playing
|
// Let's give a user time to look at video information page if video is not playing
|
||||||
if (PlayerHelper.globalScreenOrientationLocked(activity) && !player!!.isPlaying()) {
|
if (PlayerHelper.globalScreenOrientationLocked(activity) && !player!!.isPlaying()) {
|
||||||
player!!.play()
|
player!!.play()
|
||||||
@ -2590,8 +2574,7 @@ class VideoDetailFragment :
|
|||||||
player!!.isPlaying() &&
|
player!!.isPlaying() &&
|
||||||
!this@VideoDetailFragment.isFullscreen && !DeviceUtils.isTablet(activity)
|
!this@VideoDetailFragment.isFullscreen && !DeviceUtils.isTablet(activity)
|
||||||
) {
|
) {
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java)
|
player!!.UIs().get(MainPlayerUi::class.java)?.toggleFullscreen()
|
||||||
.ifPresent(Consumer { obj: MainPlayerUi? -> obj!!.toggleFullscreen() })
|
|
||||||
}
|
}
|
||||||
setOverlayLook(binding!!.appBarLayout, behavior, 1f)
|
setOverlayLook(binding!!.appBarLayout, behavior, 1f)
|
||||||
}
|
}
|
||||||
@ -2605,8 +2588,7 @@ class VideoDetailFragment :
|
|||||||
// Re-enable clicks
|
// Re-enable clicks
|
||||||
setOverlayElementsClickable(true)
|
setOverlayElementsClickable(true)
|
||||||
if (this@VideoDetailFragment.isPlayerAvailable) {
|
if (this@VideoDetailFragment.isPlayerAvailable) {
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java)
|
player!!.UIs().get(MainPlayerUi::class.java)?.closeItemsList()
|
||||||
.ifPresent(Consumer { obj: MainPlayerUi? -> obj!!.closeItemsList() })
|
|
||||||
}
|
}
|
||||||
setOverlayLook(binding!!.appBarLayout, behavior, 0f)
|
setOverlayLook(binding!!.appBarLayout, behavior, 0f)
|
||||||
}
|
}
|
||||||
@ -2616,13 +2598,11 @@ class VideoDetailFragment :
|
|||||||
showSystemUi()
|
showSystemUi()
|
||||||
}
|
}
|
||||||
if (this@VideoDetailFragment.isPlayerAvailable) {
|
if (this@VideoDetailFragment.isPlayerAvailable) {
|
||||||
player!!.UIs().getOpt<MainPlayerUi>(MainPlayerUi::class.java).ifPresent(
|
player!!.UIs().get(MainPlayerUi::class.java)?.let {
|
||||||
Consumer { ui: MainPlayerUi? ->
|
if (it.isControlsVisible) {
|
||||||
if (ui!!.isControlsVisible()) {
|
it.hideControls(0, 0)
|
||||||
ui.hideControls(0, 0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2724,18 +2704,8 @@ class VideoDetailFragment :
|
|||||||
val isPlayerAndPlayerServiceAvailable: Boolean
|
val isPlayerAndPlayerServiceAvailable: Boolean
|
||||||
get() = player != null && playerService != null
|
get() = player != null && playerService != null
|
||||||
|
|
||||||
val root: Optional<View?>
|
val root: View?
|
||||||
get() = Optional.ofNullable<Player?>(player)
|
get() = player?.UIs()?.get(VideoPlayerUi::class.java)?.binding?.root
|
||||||
.flatMap<VideoPlayerUi?>(
|
|
||||||
Function { player1: Player? ->
|
|
||||||
player1!!.UIs().getOpt<VideoPlayerUi>(VideoPlayerUi::class.java)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.map<View?>(
|
|
||||||
Function { playerUi: VideoPlayerUi? ->
|
|
||||||
playerUi!!.getBinding().getRoot()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun updateBottomSheetState(newState: Int) {
|
private fun updateBottomSheetState(newState: Int) {
|
||||||
bottomSheetState = newState
|
bottomSheetState = newState
|
||||||
|
Loading…
x
Reference in New Issue
Block a user