From 07494cba98f70f3f60972a9cb8a41fdbd110b67b Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 6 Aug 2023 00:04:29 +0200 Subject: [PATCH] feat: Add forceExactMaxDuration option to AppSettings --- .../myzel394/locationtest/db/AppSettings.kt | 5 ++ .../atoms/ForceExactMaxDurationTile.kt | 60 +++++++++++++++++++ .../locationtest/ui/screens/SettingsScreen.kt | 2 + 3 files changed, 67 insertions(+) create mode 100644 app/src/main/java/app/myzel394/locationtest/ui/components/SettingsScreen/atoms/ForceExactMaxDurationTile.kt diff --git a/app/src/main/java/app/myzel394/locationtest/db/AppSettings.kt b/app/src/main/java/app/myzel394/locationtest/db/AppSettings.kt index c81dee0..5138760 100644 --- a/app/src/main/java/app/myzel394/locationtest/db/AppSettings.kt +++ b/app/src/main/java/app/myzel394/locationtest/db/AppSettings.kt @@ -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( diff --git a/app/src/main/java/app/myzel394/locationtest/ui/components/SettingsScreen/atoms/ForceExactMaxDurationTile.kt b/app/src/main/java/app/myzel394/locationtest/ui/components/SettingsScreen/atoms/ForceExactMaxDurationTile.kt new file mode 100644 index 0000000..2105a54 --- /dev/null +++ b/app/src/main/java/app/myzel394/locationtest/ui/components/SettingsScreen/atoms/ForceExactMaxDurationTile.kt @@ -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, + ) + }, + ) +} \ No newline at end of file diff --git a/app/src/main/java/app/myzel394/locationtest/ui/screens/SettingsScreen.kt b/app/src/main/java/app/myzel394/locationtest/ui/screens/SettingsScreen.kt index f1e2f1c..56b050f 100644 --- a/app/src/main/java/app/myzel394/locationtest/ui/screens/SettingsScreen.kt +++ b/app/src/main/java/app/myzel394/locationtest/ui/screens/SettingsScreen.kt @@ -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(