fix: Improve AppSettings structure

This commit is contained in:
Myzel394 2023-12-02 16:34:15 +01:00
parent 5f7c6a9140
commit b98718214c
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
2 changed files with 47 additions and 40 deletions

View File

@ -16,11 +16,21 @@ import java.time.LocalDateTime
data class AppSettings(
val audioRecorderSettings: AudioRecorderSettings = AudioRecorderSettings.getDefaultInstance(),
val videoRecorderSettings: VideoRecorderSettings = VideoRecorderSettings.getDefaultInstance(),
val notificationSettings: NotificationSettings? = null,
val hasSeenOnboarding: Boolean = false,
val showAdvancedSettings: Boolean = false,
val theme: Theme = Theme.SYSTEM,
val lastRecording: RecordingInformation? = null,
/// Recording information
// 30 minutes
val maxDuration: Long = 30 * 60 * 1000L,
// 60 seconds
val intervalDuration: Long = 60 * 1000L,
val notificationSettings: NotificationSettings? = null,
val deleteRecordingsImmediately: Boolean = false,
val saveFolder: String? = null,
) {
fun setShowAdvancedSettings(showAdvancedSettings: Boolean): AppSettings {
return copy(showAdvancedSettings = showAdvancedSettings)
@ -46,6 +56,38 @@ data class AppSettings(
return copy(lastRecording = lastRecording)
}
fun setMaxDuration(duration: Long): AppSettings {
if (duration < 60 * 1000L || duration > 10 * 24 * 60 * 60 * 1000L) {
throw Exception("Max duration must be between 1 minute and 10 days")
}
if (duration < intervalDuration) {
throw Exception("Max duration must be greater than interval duration")
}
return copy(maxDuration = duration)
}
fun setIntervalDuration(duration: Long): AppSettings {
if (duration < 10 * 1000L || duration > 60 * 60 * 1000L) {
throw Exception("Interval duration must be between 10 seconds and 1 hour")
}
if (duration > maxDuration) {
throw Exception("Interval duration must be less than max duration")
}
return copy(intervalDuration = duration)
}
fun setDeleteRecordingsImmediately(deleteRecordingsImmediately: Boolean): AppSettings {
return copy(deleteRecordingsImmediately = deleteRecordingsImmediately)
}
fun setSaveFolder(saveFolder: String?): AppSettings {
return copy(saveFolder = saveFolder)
}
enum class Theme {
SYSTEM,
LIGHT,
@ -95,18 +137,12 @@ data class RecordingInformation(
@Serializable
data class AudioRecorderSettings(
// 30 minutes
val maxDuration: Long = 30 * 60 * 1000L,
// 60 seconds
val intervalDuration: Long = 60 * 1000L,
// 320 Kbps
val bitRate: Int = 320000,
val samplingRate: Int? = null,
val outputFormat: Int? = null,
val encoder: Int? = null,
val showAllMicrophones: Boolean = false,
val deleteRecordingsImmediately: Boolean = false,
val saveFolder: String? = null,
) {
fun getOutputFormat(): Int {
if (outputFormat != null) {
@ -174,18 +210,6 @@ data class AudioRecorderSettings(
else
MediaRecorder.AudioEncoder.AMR_NB
fun setIntervalDuration(duration: Long): AudioRecorderSettings {
if (duration < 10 * 1000L || duration > 60 * 60 * 1000L) {
throw Exception("Interval duration must be between 10 seconds and 1 hour")
}
if (duration > maxDuration) {
throw Exception("Interval duration must be less than max duration")
}
return copy(intervalDuration = duration)
}
fun setBitRate(bitRate: Int): AudioRecorderSettings {
if (bitRate !in 1000..320000) {
throw Exception("Bit rate must be between 1000 and 320000")
@ -218,30 +242,10 @@ data class AudioRecorderSettings(
return copy(encoder = encoder)
}
fun setMaxDuration(duration: Long): AudioRecorderSettings {
if (duration < 60 * 1000L || duration > 10 * 24 * 60 * 60 * 1000L) {
throw Exception("Max duration must be between 1 minute and 10 days")
}
if (duration < intervalDuration) {
throw Exception("Max duration must be greater than interval duration")
}
return copy(maxDuration = duration)
}
fun setShowAllMicrophones(showAllMicrophones: Boolean): AudioRecorderSettings {
return copy(showAllMicrophones = showAllMicrophones)
}
fun setDeleteRecordingsImmediately(deleteRecordingsImmediately: Boolean): AudioRecorderSettings {
return copy(deleteRecordingsImmediately = deleteRecordingsImmediately)
}
fun setSaveFolder(saveFolder: String?): AudioRecorderSettings {
return copy(saveFolder = saveFolder)
}
fun isEncoderCompatible(encoder: Int): Boolean {
if (outputFormat == null || outputFormat == MediaRecorder.OutputFormat.DEFAULT) {
return true

View File

@ -73,7 +73,10 @@ fun Navigation(
scaleOut(targetScale = SCALE_IN) + fadeOut(tween(durationMillis = 150))
}
) {
POCVideo(videoRecorder = videoRecorder, settings = settings)
AudioRecorderScreen(
navController = navController,
audioRecorder = audioRecorder,
)
}
composable(
Screen.Settings.route,