feat: Add forceExactMaxDuration option to AppSettings

This commit is contained in:
Myzel394 2023-08-06 00:04:29 +02:00
parent 5620ff9625
commit 07494cba98
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
3 changed files with 67 additions and 0 deletions

View File

@ -35,6 +35,7 @@ data class AudioRecorderSettings(
val maxDuration: Long = 30 * 60 * 1000L,
// 60 seconds
val intervalDuration: Long = 60 * 1000L,
val forceExactMaxDuration: Boolean = true,
// 320 Kbps
val bitRate: Int = 320000,
val samplingRate: Int? = null,
@ -122,6 +123,10 @@ data class AudioRecorderSettings(
return copy(maxDuration = duration)
}
fun setForceExactMaxDuration(forceExactMaxDuration: Boolean): AudioRecorderSettings {
return copy(forceExactMaxDuration = forceExactMaxDuration)
}
companion object {
fun getDefaultInstance(): AudioRecorderSettings = AudioRecorderSettings()
val EXAMPLE_MAX_DURATIONS = listOf(

View File

@ -0,0 +1,60 @@
package app.myzel394.locationtest.ui.components.SettingsScreen.atoms
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.GraphicEq
import androidx.compose.material.icons.filled.Memory
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import app.myzel394.locationtest.dataStore
import app.myzel394.locationtest.db.AppSettings
import app.myzel394.locationtest.db.AudioRecorderSettings
import app.myzel394.locationtest.ui.components.atoms.ExampleListRoulette
import app.myzel394.locationtest.ui.components.atoms.SettingsTile
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import kotlinx.coroutines.launch
@Composable
fun ForceExactMaxDurationTile() {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value
fun updateValue(forceExactMaxDuration: Boolean) {
scope.launch {
dataStore.updateData {
it.setAudioRecorderSettings(
it.audioRecorderSettings.setForceExactMaxDuration(forceExactMaxDuration)
)
}
}
}
SettingsTile(
title = "Force exact duration",
description = "Force to strip the output file to be the exactly specified duration. If this is disabled, the output file may be a bit longer due to batches of audio samples being encoded together.",
leading = {
Icon(
Icons.Default.GraphicEq,
contentDescription = null,
)
},
trailing = {
Switch(
checked = settings.audioRecorderSettings.forceExactMaxDuration,
onCheckedChange = ::updateValue,
)
},
)
}

View File

@ -40,6 +40,7 @@ import app.myzel394.locationtest.db.AppSettings
import app.myzel394.locationtest.db.AudioRecorderSettings
import app.myzel394.locationtest.ui.components.SettingsScreen.atoms.BitrateTile
import app.myzel394.locationtest.ui.components.SettingsScreen.atoms.EncoderTile
import app.myzel394.locationtest.ui.components.SettingsScreen.atoms.ForceExactMaxDurationTile
import app.myzel394.locationtest.ui.components.SettingsScreen.atoms.IntervalDurationTile
import app.myzel394.locationtest.ui.components.SettingsScreen.atoms.MaxDurationTile
import app.myzel394.locationtest.ui.components.SettingsScreen.atoms.OutputFormatTile
@ -110,6 +111,7 @@ fun SettingsScreen(
)
MaxDurationTile()
IntervalDurationTile()
ForceExactMaxDurationTile()
AnimatedVisibility(visible = settings.showAdvancedSettings) {
Column {
Divider(