new: pass audioResourcePath in navigation, update Record model and integrate index into UI

This commit is contained in:
2026-06-19 10:36:25 +02:00
parent 9c6ee21ae7
commit 03b3ab1965
7 changed files with 26 additions and 10 deletions
@@ -41,7 +41,12 @@ fun App() {
is Route.Records -> NavEntry(key) { is Route.Records -> NavEntry(key) {
RecordsScreen( RecordsScreen(
onRecordClick = { record -> onRecordClick = { record ->
backStack.add(Route.Player(record.title)) backStack.add(
Route.Player(
title = record.title,
audioResourcePath = record.audioResourcePath,
),
)
}, },
) )
} }
@@ -49,6 +54,7 @@ fun App() {
is Route.Player -> NavEntry(key) { is Route.Player -> NavEntry(key) {
PlayerScreen( PlayerScreen(
recordTitle = key.title, recordTitle = key.title,
audioResourcePath = key.audioResourcePath,
onBackClicked = { backStack.removeLastOrNull() }, onBackClicked = { backStack.removeLastOrNull() },
) )
} }
@@ -11,5 +11,6 @@ sealed interface Route : NavKey {
@Serializable @Serializable
data class Player( data class Player(
val title: String, val title: String,
val audioResourcePath: String,
) : Route ) : Route
} }
@@ -38,13 +38,14 @@ import org.koin.compose.viewmodel.koinViewModel
@Composable @Composable
fun PlayerScreen( fun PlayerScreen(
recordTitle: String, recordTitle: String,
audioResourcePath: String,
onBackClicked: () -> Unit, onBackClicked: () -> Unit,
viewModel: PlayerViewModel = koinViewModel(), viewModel: PlayerViewModel = koinViewModel(),
) { ) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle() val uiState by viewModel.uiState.collectAsStateWithLifecycle()
DisposableEffect(Unit) { DisposableEffect(audioResourcePath) {
viewModel.play(filePath = "files/demat.ogg") viewModel.play(filePath = audioResourcePath)
onDispose { onDispose {
viewModel.stop() viewModel.stop()
} }
@@ -31,7 +31,13 @@ class InMemoryRecordRepository : RecordRepository {
"Stad a vuhez (1)", "Stad a vuhez (1)",
"Stad a vuhez (2)", "Stad a vuhez (2)",
"Lec'hiiñ", "Lec'hiiñ",
).map { Record(it) } ).mapIndexed { index, title ->
Record(
index = index + 1,
title = title,
audioResourcePath = "files/$title.ogg",
)
}
override fun getRecords(): Flow<List<Record>> = flowOf(records) override fun getRecords(): Flow<List<Record>> = flowOf(records)
} }
@@ -1,5 +1,7 @@
package fr.ajaury.gwenedeg.records.domain package fr.ajaury.gwenedeg.records.domain
data class Record( data class Record(
val index: Int,
val title: String, val title: String,
val audioResourcePath: String,
) )
@@ -16,7 +16,6 @@ import fr.ajaury.gwenedeg.records.domain.Record
@Composable @Composable
fun RecordView( fun RecordView(
index: Int,
record: Record, record: Record,
onClick: () -> Unit = {}, onClick: () -> Unit = {},
) { ) {
@@ -30,7 +29,7 @@ fun RecordView(
horizontalArrangement = Arrangement.spacedBy(16.dp), horizontalArrangement = Arrangement.spacedBy(16.dp),
) { ) {
Text( Text(
text = index.toString().padStart(2), text = record.index.toString().padStart(2),
fontFamily = FontFamily.Monospace, fontFamily = FontFamily.Monospace,
) )
Text(text = record.title) Text(text = record.title)
@@ -41,8 +40,7 @@ fun RecordView(
@Composable @Composable
private fun RecordViewPreview() { private fun RecordViewPreview() {
RecordView( RecordView(
index = 1, record = Record(index = 1, title = "Sample Record", audioResourcePath = "files/An onestiz.ogg"),
record = Record(title = "Sample Record"),
onClick = {}, onClick = {},
) )
} }
@@ -44,9 +44,11 @@ fun RecordsScreen(
.background(MaterialTheme.colorScheme.primaryContainer) .background(MaterialTheme.colorScheme.primaryContainer)
.fillMaxSize(), .fillMaxSize(),
) { ) {
itemsIndexed(records) { index, item -> itemsIndexed(
items = records,
key = { _, item -> item.index },
) { index, item ->
RecordView( RecordView(
index = index + 1,
record = item, record = item,
onClick = { onRecordClick(item) }, onClick = { onRecordClick(item) },
) )