From 03b3ab19655276a6237cae799b9a5beeb395fff8 Mon Sep 17 00:00:00 2001 From: Antoine Jaury Date: Fri, 19 Jun 2026 10:36:25 +0200 Subject: [PATCH] new: pass audioResourcePath in navigation, update Record model and integrate index into UI --- shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/App.kt | 8 +++++++- .../kotlin/fr/ajaury/gwenedeg/navigation/Route.kt | 1 + .../kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt | 5 +++-- .../gwenedeg/records/data/InMemoryRecordRepository.kt | 8 +++++++- .../kotlin/fr/ajaury/gwenedeg/records/domain/Record.kt | 2 ++ .../kotlin/fr/ajaury/gwenedeg/records/ui/RecordView.kt | 6 ++---- .../kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt | 6 ++++-- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/App.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/App.kt index b484d28..40e390c 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/App.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/App.kt @@ -41,7 +41,12 @@ fun App() { is Route.Records -> NavEntry(key) { RecordsScreen( 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) { PlayerScreen( recordTitle = key.title, + audioResourcePath = key.audioResourcePath, onBackClicked = { backStack.removeLastOrNull() }, ) } diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/navigation/Route.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/navigation/Route.kt index d348f96..04536b3 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/navigation/Route.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/navigation/Route.kt @@ -11,5 +11,6 @@ sealed interface Route : NavKey { @Serializable data class Player( val title: String, + val audioResourcePath: String, ) : Route } diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt index b71b253..4ce093c 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/player/ui/PlayerScreen.kt @@ -38,13 +38,14 @@ import org.koin.compose.viewmodel.koinViewModel @Composable fun PlayerScreen( recordTitle: String, + audioResourcePath: String, onBackClicked: () -> Unit, viewModel: PlayerViewModel = koinViewModel(), ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() - DisposableEffect(Unit) { - viewModel.play(filePath = "files/demat.ogg") + DisposableEffect(audioResourcePath) { + viewModel.play(filePath = audioResourcePath) onDispose { viewModel.stop() } diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/data/InMemoryRecordRepository.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/data/InMemoryRecordRepository.kt index f60794d..e9856d8 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/data/InMemoryRecordRepository.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/data/InMemoryRecordRepository.kt @@ -31,7 +31,13 @@ class InMemoryRecordRepository : RecordRepository { "Stad a vuhez (1)", "Stad a vuhez (2)", "Lec'hiiƱ", - ).map { Record(it) } + ).mapIndexed { index, title -> + Record( + index = index + 1, + title = title, + audioResourcePath = "files/$title.ogg", + ) + } override fun getRecords(): Flow> = flowOf(records) } diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/domain/Record.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/domain/Record.kt index b238cc3..061740b 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/domain/Record.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/domain/Record.kt @@ -1,5 +1,7 @@ package fr.ajaury.gwenedeg.records.domain data class Record( + val index: Int, val title: String, + val audioResourcePath: String, ) diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordView.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordView.kt index 28eb452..85f1d47 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordView.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordView.kt @@ -16,7 +16,6 @@ import fr.ajaury.gwenedeg.records.domain.Record @Composable fun RecordView( - index: Int, record: Record, onClick: () -> Unit = {}, ) { @@ -30,7 +29,7 @@ fun RecordView( horizontalArrangement = Arrangement.spacedBy(16.dp), ) { Text( - text = index.toString().padStart(2), + text = record.index.toString().padStart(2), fontFamily = FontFamily.Monospace, ) Text(text = record.title) @@ -41,8 +40,7 @@ fun RecordView( @Composable private fun RecordViewPreview() { RecordView( - index = 1, - record = Record(title = "Sample Record"), + record = Record(index = 1, title = "Sample Record", audioResourcePath = "files/An onestiz.ogg"), onClick = {}, ) } diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt index cf76107..548d1e3 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt @@ -44,9 +44,11 @@ fun RecordsScreen( .background(MaterialTheme.colorScheme.primaryContainer) .fillMaxSize(), ) { - itemsIndexed(records) { index, item -> + itemsIndexed( + items = records, + key = { _, item -> item.index }, + ) { index, item -> RecordView( - index = index + 1, record = item, onClick = { onRecordClick(item) }, )