-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Gaëtan Muller <[email protected]>
- Loading branch information
Showing
13 changed files
with
263 additions
and
43 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/LocalTimeFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.demo.shared.ui | ||
|
||
import kotlinx.datetime.LocalTime | ||
import kotlinx.datetime.format.Padding | ||
import kotlinx.datetime.format.char | ||
|
||
/** | ||
* Local time formatter that format [LocalTime] to HH:mm:ss. | ||
*/ | ||
val localTimeFormatter by lazy { | ||
LocalTime.Format { | ||
hour(Padding.ZERO) | ||
char(':') | ||
minute(Padding.ZERO) | ||
char(':') | ||
second(Padding.ZERO) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/showcases/misc/TimeBasedContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.demo.ui.showcases.misc | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.minimumInteractiveComponentSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.lifecycle.compose.LifecycleStartEffect | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import ch.srgssr.pillarbox.demo.ui.components.DemoListHeaderView | ||
import ch.srgssr.pillarbox.demo.ui.components.DemoListItemView | ||
import ch.srgssr.pillarbox.demo.ui.components.DemoListSectionView | ||
import ch.srgssr.pillarbox.demo.ui.player.DemoPlayerView | ||
import ch.srgssr.pillarbox.demo.ui.theme.paddings | ||
import ch.srgssr.pillarbox.player.extension.seekToUnixTimeMs | ||
import kotlinx.datetime.Clock | ||
|
||
/** | ||
* Time-based content that demonstrates how to use timestamp-based api. | ||
*/ | ||
@Composable | ||
fun TimeBasedContent() { | ||
val viewModel: TimeBasedContentViewModel = viewModel() | ||
val player = viewModel.player | ||
val timedEvents by viewModel.deltaTimeEvents.collectAsStateWithLifecycle() | ||
|
||
LifecycleStartEffect(player) { | ||
player.play() | ||
onStopOrDispose { | ||
player.pause() | ||
} | ||
} | ||
Column { | ||
DemoPlayerView(player = player, modifier = Modifier.weight(1f)) | ||
LazyColumn( | ||
modifier = Modifier | ||
.padding(horizontal = MaterialTheme.paddings.baseline) | ||
.weight(1f), | ||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.paddings.small) | ||
) { | ||
item { | ||
DemoListHeaderView("Timed events") | ||
} | ||
item { | ||
DemoListSectionView { | ||
timedEvents.forEachIndexed { index, timedEvent -> | ||
DemoListItemView( | ||
title = timedEvent.name, | ||
subtitle = "Delta time ${timedEvent.delta}", | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.minimumInteractiveComponentSize() | ||
) { | ||
val now = Clock.System.now() | ||
player.seekToUnixTimeMs((now + timedEvent.delta).toEpochMilliseconds()) | ||
} | ||
|
||
if (index < timedEvents.lastIndex) { | ||
HorizontalDivider() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.