From 7804a9a6e68a0a23a7811aece8eb82a0731a8982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Tue, 30 Jul 2024 10:02:48 +0200 Subject: [PATCH] Enable edge-to-edge in the demo application (#658) --- .../ch/srgssr/pillarbox/demo/MainActivity.kt | 4 +++ .../demo/ui/player/SimplePlayerActivity.kt | 25 ++++++++++++++++--- .../pillarbox/demo/ui/search/SearchHome.kt | 4 ++- .../pillarbox/demo/ui/theme/PillarboxTheme.kt | 14 ----------- .../src/main/res/values-night/themes.xml | 5 ++++ 5 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 pillarbox-demo/src/main/res/values-night/themes.xml diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainActivity.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainActivity.kt index 5e5258d09..c87e7eb5f 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainActivity.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/MainActivity.kt @@ -7,6 +7,7 @@ package ch.srgssr.pillarbox.demo import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface @@ -20,7 +21,10 @@ import ch.srgssr.pillarbox.demo.ui.theme.PillarboxTheme */ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge() + super.onCreate(savedInstanceState) + setContent { PillarboxTheme { // A surface container using the 'background' color from the theme diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerActivity.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerActivity.kt index 1adfc130c..d2c37c4f4 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerActivity.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/SimplePlayerActivity.kt @@ -10,13 +10,18 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import android.content.res.Configuration +import android.graphics.Color import android.os.Build import android.os.Bundle import android.os.IBinder import androidx.activity.ComponentActivity +import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.annotation.RequiresApi import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.runtime.Composable @@ -45,11 +50,11 @@ import java.net.URL /** * Simple player activity that can handle picture in picture. * - * It handle basic background playback, as it will stop playback when the Activity is destroyed! - * To have pure background playback with good integration from other device like Auto, Wear, etc... we need *MediaSessionService* + * It handles basic background playback, as it will stop playback when the Activity is destroyed! + * To have pure background playback with good integration from other devices like Auto, Wear, etc... we need *MediaSessionService* * * For this demo, only the picture in picture button can enable picture in picture. - * But feel free to call [startPictureInPicture] whenever you decide, for example when [onUserLeaveHint] + * But feel free to call [startPictureInPicture] whenever you decide, for example, when [onUserLeaveHint] */ class SimplePlayerActivity : ComponentActivity(), ServiceConnection { @@ -64,7 +69,13 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection { } override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.dark(Color.BLACK), + navigationBarStyle = SystemBarStyle.dark(Color.BLACK), + ) + super.onCreate(savedInstanceState) + val ilHost = IntentCompat.getSerializableExtra(intent, ARG_IL_HOST, URL::class.java) ?: IlHost.DEFAULT playerViewModel = ViewModelProvider(this, factory = SimplePlayerViewModel.Factory(application, ilHost))[SimplePlayerViewModel::class.java] readIntent(intent) @@ -83,7 +94,13 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection { bindPlaybackService() setContent { PillarboxTheme { - Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { + Surface( + modifier = Modifier + .fillMaxSize() + .statusBarsPadding() + .navigationBarsPadding(), + color = MaterialTheme.colorScheme.background, + ) { MainContent(playerViewModel.player) } } diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt index b1a5951d3..fedc9d6a2 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/search/SearchHome.kt @@ -17,6 +17,7 @@ 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.WindowInsets import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth @@ -287,7 +288,8 @@ private fun SearchInput( } } }, - shape = MaterialTheme.shapes.large + shape = MaterialTheme.shapes.large, + windowInsets = WindowInsets(0.dp), ) {} LaunchedEffect(Unit) { diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/theme/PillarboxTheme.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/theme/PillarboxTheme.kt index 54402a519..02c0e9bfb 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/theme/PillarboxTheme.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/theme/PillarboxTheme.kt @@ -4,17 +4,12 @@ */ package ch.srgssr.pillarbox.demo.ui.theme -import android.app.Activity import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.SideEffect -import androidx.compose.ui.graphics.toArgb -import androidx.compose.ui.platform.LocalView -import androidx.core.view.WindowCompat import ch.srgssr.pillarbox.demo.shared.ui.theme.md_theme_dark_background import ch.srgssr.pillarbox.demo.shared.ui.theme.md_theme_dark_error import ch.srgssr.pillarbox.demo.shared.ui.theme.md_theme_dark_errorContainer @@ -157,15 +152,6 @@ fun PillarboxTheme( lightColorScheme } - val view = LocalView.current - if (!view.isInEditMode) { - SideEffect { - val window = (view.context as Activity).window - window.statusBarColor = colorScheme.primary.toArgb() - WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme - } - } - MaterialTheme(colorScheme = colorScheme) { CompositionLocalProvider( LocalPaddings provides paddings, diff --git a/pillarbox-demo/src/main/res/values-night/themes.xml b/pillarbox-demo/src/main/res/values-night/themes.xml new file mode 100644 index 000000000..14c8f1a4f --- /dev/null +++ b/pillarbox-demo/src/main/res/values-night/themes.xml @@ -0,0 +1,5 @@ + + + +