mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
refactor: Add ExampleListRoulette
This commit is contained in:
parent
dcdb624e5d
commit
57e4b4ec88
@ -21,6 +21,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import app.myzel394.locationtest.dataStore
|
import app.myzel394.locationtest.dataStore
|
||||||
import app.myzel394.locationtest.db.AppSettings
|
import app.myzel394.locationtest.db.AppSettings
|
||||||
import app.myzel394.locationtest.db.AudioRecorderSettings
|
import app.myzel394.locationtest.db.AudioRecorderSettings
|
||||||
|
import app.myzel394.locationtest.ui.components.atoms.ExampleListRoulette
|
||||||
import app.myzel394.locationtest.ui.components.atoms.SettingsTile
|
import app.myzel394.locationtest.ui.components.atoms.SettingsTile
|
||||||
import app.myzel394.locationtest.ui.utils.formatDuration
|
import app.myzel394.locationtest.ui.utils.formatDuration
|
||||||
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
|
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
|
||||||
@ -35,7 +36,7 @@ import kotlinx.coroutines.launch
|
|||||||
@Composable
|
@Composable
|
||||||
fun IntervalDurationTile() {
|
fun IntervalDurationTile() {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val showDurationPicker = rememberUseCaseState()
|
val showDialog = rememberUseCaseState()
|
||||||
val dataStore = LocalContext.current.dataStore
|
val dataStore = LocalContext.current.dataStore
|
||||||
val settings = dataStore
|
val settings = dataStore
|
||||||
.data
|
.data
|
||||||
@ -43,7 +44,7 @@ fun IntervalDurationTile() {
|
|||||||
.value
|
.value
|
||||||
|
|
||||||
DurationDialog(
|
DurationDialog(
|
||||||
state = showDurationPicker,
|
state = showDialog,
|
||||||
selection = DurationSelection { newTimeInSeconds ->
|
selection = DurationSelection { newTimeInSeconds ->
|
||||||
scope.launch {
|
scope.launch {
|
||||||
dataStore.updateData {
|
dataStore.updateData {
|
||||||
@ -71,7 +72,7 @@ fun IntervalDurationTile() {
|
|||||||
},
|
},
|
||||||
trailing = {
|
trailing = {
|
||||||
Button(
|
Button(
|
||||||
onClick = showDurationPicker::show,
|
onClick = showDialog::show,
|
||||||
colors = ButtonDefaults.filledTonalButtonColors(
|
colors = ButtonDefaults.filledTonalButtonColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||||
),
|
),
|
||||||
@ -83,19 +84,9 @@ fun IntervalDurationTile() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
extra = {
|
extra = {
|
||||||
LazyRow(
|
ExampleListRoulette(
|
||||||
modifier = Modifier
|
items = AudioRecorderSettings.EXAMPLE_DURATION_TIMES,
|
||||||
.fillMaxWidth(),
|
onItemSelected = {duration ->
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
|
||||||
contentPadding = PaddingValues(
|
|
||||||
horizontal = 32.dp,
|
|
||||||
),
|
|
||||||
) {
|
|
||||||
items(AudioRecorderSettings.EXAMPLE_DURATION_TIMES.size) {
|
|
||||||
val duration = AudioRecorderSettings.EXAMPLE_DURATION_TIMES[it]
|
|
||||||
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
dataStore.updateData {
|
dataStore.updateData {
|
||||||
it.setAudioRecorderSettings(
|
it.setAudioRecorderSettings(
|
||||||
@ -103,17 +94,12 @@ fun IntervalDurationTile() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
colors = ButtonDefaults.textButtonColors(),
|
) {duration ->
|
||||||
shape = ButtonDefaults.textShape,
|
|
||||||
contentPadding = ButtonDefaults.TextButtonContentPadding,
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = formatDuration(duration),
|
text = formatDuration(duration),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package app.myzel394.locationtest.ui.components.atoms
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun<T> ExampleListRoulette(
|
||||||
|
items: List<T>,
|
||||||
|
onItemSelected: (T) -> Unit,
|
||||||
|
renderValue: @Composable (T) -> Unit,
|
||||||
|
) {
|
||||||
|
LazyRow(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
contentPadding = PaddingValues(
|
||||||
|
horizontal = 32.dp,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
items(items.size) {
|
||||||
|
val item = items[it]
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
onItemSelected(item)
|
||||||
|
},
|
||||||
|
colors = ButtonDefaults.textButtonColors(),
|
||||||
|
shape = ButtonDefaults.textShape,
|
||||||
|
contentPadding = ButtonDefaults.TextButtonContentPadding,
|
||||||
|
) {
|
||||||
|
renderValue(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user