Skip to content

Commit

Permalink
Enable edge-to-edge in the demo application (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored Jul 30, 2024
1 parent 415a79d commit 7804a9a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand All @@ -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)
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -287,7 +288,8 @@ private fun SearchInput(
}
}
},
shape = MaterialTheme.shapes.large
shape = MaterialTheme.shapes.large,
windowInsets = WindowInsets(0.dp),
) {}

LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions pillarbox-demo/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.PillarboxDemo" parent="android:Theme.Material.NoActionBar" />
</resources>

0 comments on commit 7804a9a

Please sign in to comment.