Skip to content

Commit

Permalink
Use movable content to swap players (#472)
Browse files Browse the repository at this point in the history
Co-authored-by: Gaëtan Muller <[email protected]>
  • Loading branch information
StaehliJ and MGaetan89 authored Mar 15, 2024
1 parent 3b16eca commit 0edbc63
Showing 1 changed file with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package ch.srgssr.pillarbox.demo.ui.showcases.misc
import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
Expand All @@ -16,6 +15,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.movableContentOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -67,46 +67,34 @@ fun MultiPlayerShowcase() {
playerTwo.pause()
}
}
val leftPlayer = if (swapLeftRight) playerTwo else playerOne
val rightPlayer = if (swapLeftRight) playerOne else playerTwo
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Button(onClick = { swapLeftRight = !swapLeftRight }) {
Text(text = "Swap players")
}
if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Row(modifier = Modifier.fillMaxWidth()) {
val players = remember {
movableContentOf {
PlayerView(
modifier = Modifier
.weight(1.0f)
.padding(MaterialTheme.paddings.mini),
player = leftPlayer,
player = if (swapLeftRight) playerTwo else playerOne,
)
PlayerView(
modifier = Modifier
.weight(1.0f)
.padding(MaterialTheme.paddings.mini),
player = rightPlayer
player = if (swapLeftRight) playerOne else playerTwo,
)
}
}
if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Row(modifier = Modifier.fillMaxWidth()) {
players()
}
} else {
Column(modifier = Modifier.fillMaxWidth()) {
PlayerView(
modifier = Modifier
.weight(1.0f)
.aspectRatio(AspectRatio)
.padding(MaterialTheme.paddings.mini),
player = leftPlayer
)
PlayerView(
modifier = Modifier
.weight(1.0f)
.aspectRatio(AspectRatio)
.padding(MaterialTheme.paddings.mini),
player = rightPlayer
)
players()
}
}
}
}

private const val AspectRatio = 16 / 9f

0 comments on commit 0edbc63

Please sign in to comment.