new: pass audioResourcePath in navigation, update Record model and integrate index into UI
This commit is contained in:
@@ -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() },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ sealed interface Route : NavKey {
|
||||
@Serializable
|
||||
data class Player(
|
||||
val title: String,
|
||||
val audioResourcePath: String,
|
||||
) : Route
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
+7
-1
@@ -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<List<Record>> = flowOf(records)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package fr.ajaury.gwenedeg.records.domain
|
||||
|
||||
data class Record(
|
||||
val index: Int,
|
||||
val title: String,
|
||||
val audioResourcePath: String,
|
||||
)
|
||||
|
||||
@@ -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 = {},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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) },
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user