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

Changed the controller visibility during Ads #31

Closed
wants to merge 9 commits into from
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
> - 🏠 Internal
> - 💅 Polish

## Unreleased

* 🐛 Disable system gestures on the `SeekBar` component. ([#30](https://github.com/THEOplayer/android-ui/pull/30))

## v1.7.0 (2024-08-12)

* 💥 Updated to Jetpack Compose version 1.6.8 ([BOM](https://developer.android.com/jetpack/compose/bom) 2024.06.00).
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ui-test-junit4 = "1.6.8" # ...not in BOM for some reason?
androidx-junit = "1.2.1"
androidx-espresso = "3.6.1"
dokka = "1.9.20"
theoplayer = "7.8.0"
theoplayer = "7.10.0"

[libraries]
androidx-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "ktx" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ internal class FullscreenHandlerImpl(private val view: View) : FullscreenHandler
val window = activity.window

// Hide system bars
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowCompat.getInsetsController(window, view).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
previousSystemBarsBehavior = controller.systemBarsBehavior
Expand Down Expand Up @@ -74,7 +73,6 @@ internal class FullscreenHandlerImpl(private val view: View) : FullscreenHandler
val window = activity.window

// Restore system bars
WindowCompat.setDecorFitsSystemWindows(window, true)
WindowCompat.getInsetsController(window, view).let { controller ->
controller.show(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior = previousSystemBarsBehavior
Expand Down
13 changes: 10 additions & 3 deletions ui/src/main/java/com/theoplayer/android/ui/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.theoplayer.android.api.cast.Cast
import com.theoplayer.android.api.cast.chromecast.PlayerCastState
import com.theoplayer.android.api.error.THEOplayerException
import com.theoplayer.android.api.event.EventListener
import com.theoplayer.android.api.event.ads.AdBeginEvent
import com.theoplayer.android.api.event.ads.AdEvent
import com.theoplayer.android.api.event.ads.AdsEventTypes
import com.theoplayer.android.api.event.chromecast.CastErrorEvent
Expand Down Expand Up @@ -347,8 +348,11 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
videoHeight = player?.videoHeight ?: 0
}

private fun updatePlayingAd() {
playingAd = player?.ads?.isPlaying ?: false
private fun updatePlayingAd(event: AdEvent<*>? = null) {
playingAd = when (event) {
is AdBeginEvent -> true
else -> false
}
}

private val playListener = EventListener<PlayEvent> { updateCurrentTimeAndPlaybackState() }
Expand All @@ -362,7 +366,9 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
private val readyStateChangeListener =
EventListener<ReadyStateChangeEvent> { updateCurrentTimeAndPlaybackState() }
private val resizeListener = EventListener<ResizeEvent> { updateVideoWidthAndHeight() }
private val adListener = EventListener<AdEvent<*>> { updatePlayingAd() }
private val adListener = EventListener<AdEvent<*>> {
updatePlayingAd(it)
}
private val sourceChangeListener = EventListener<SourceChangeEvent> {
_source = player?.source
error = null
Expand Down Expand Up @@ -681,6 +687,7 @@ internal class PlayerImpl(override val theoplayerView: THEOplayerView?) : Player
textTrackListChangeListener
)
ads?.addEventListener(AdsEventTypes.AD_BEGIN, adListener)
ads?.addEventListener(AdsEventTypes.AD_SKIP, adListener)
ads?.addEventListener(AdsEventTypes.AD_END, adListener)
cast?.chromecast?.addEventListener(
ChromecastEventTypes.STATECHANGE,
Expand Down
3 changes: 2 additions & 1 deletion ui/src/main/java/com/theoplayer/android/ui/SeekBar.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.theoplayer.android.ui

import androidx.compose.foundation.systemGestureExclusion
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderColors
import androidx.compose.material3.SliderDefaults
Expand Down Expand Up @@ -42,7 +43,7 @@ fun SeekBar(
var wasPlayingBeforeSeek by remember { mutableStateOf(false) }

Slider(
modifier = modifier,
modifier = modifier.systemGestureExclusion(),
colors = colors,
value = seekTime ?: currentTime,
valueRange = valueRange,
Expand Down
42 changes: 36 additions & 6 deletions ui/src/main/java/com/theoplayer/android/ui/UIController.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
package com.theoplayer.android.ui

import android.view.ViewGroup
import androidx.compose.animation.*
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.*
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
Expand All @@ -22,7 +51,7 @@ import com.theoplayer.android.api.THEOplayerView
import com.theoplayer.android.api.cast.chromecast.PlayerCastState
import com.theoplayer.android.api.source.SourceDescription
import com.theoplayer.android.ui.theme.THEOplayerTheme
import kotlinx.coroutines.*
import kotlinx.coroutines.delay
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
Expand Down Expand Up @@ -330,7 +359,8 @@ private fun PlayerContainer(
ViewCompositionStrategy.DisposeOnLifecycleDestroyed(lifecycle)
)
setContent {
ui()
if (player.playingAd.not())
ui()
}
}
// Host the THEOplayer view inside our AndroidView
Expand Down