fix: Use duration dialog for MaxDurationTile

This commit is contained in:
Myzel394 2023-08-05 15:15:37 +02:00
parent 346d68ac4c
commit cabca2bb54
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B

View File

@ -28,6 +28,10 @@ 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.IconSource import com.maxkeppeker.sheets.core.models.base.IconSource
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.maxkeppeler.sheets.duration.DurationDialog
import com.maxkeppeler.sheets.duration.models.DurationConfig
import com.maxkeppeler.sheets.duration.models.DurationFormat
import com.maxkeppeler.sheets.duration.models.DurationSelection
import com.maxkeppeler.sheets.input.InputDialog import com.maxkeppeler.sheets.input.InputDialog
import com.maxkeppeler.sheets.input.models.InputHeader import com.maxkeppeler.sheets.input.models.InputHeader
import com.maxkeppeler.sheets.input.models.InputSelection import com.maxkeppeler.sheets.input.models.InputSelection
@ -57,41 +61,17 @@ fun MaxDurationTile() {
} }
} }
InputDialog( DurationDialog(
state = showDialog, state = showDialog,
selection = InputSelection( selection = DurationSelection { newTimeInSeconds ->
input = listOf( updateValue(newTimeInSeconds * 1000L)
InputTextField( },
header = InputHeader( config = DurationConfig(
title = "Set the maximum duration", timeFormat = DurationFormat.MM_SS,
icon = IconSource(Icons.Default.Timer), currentTime = settings.audioRecorderSettings.maxDuration / 1000,
), minTime = 60,
keyboardOptions = KeyboardOptions( maxTime = 24 * 60 * 60,
keyboardType = KeyboardType.Number, )
),
type = InputTextFieldType.OUTLINED,
text = settings.audioRecorderSettings.maxDuration.toString(),
validationListener = { text ->
val maxDuration = text?.toLongOrNull()
if (maxDuration == null) {
ValidationResult.Invalid("Please enter a valid number")
}
if (maxDuration !in (60 * 1000L)..(60 * 60 * 1000L)) {
ValidationResult.Invalid("Please enter a number between 1 minute and 1 hour")
}
ValidationResult.Valid
},
key = "maxDuration",
)
),
) { result ->
val maxDuration = result.getString("maxDuration")?.toLongOrNull() ?: throw IllegalStateException("Invalid maxDuration")
updateValue(maxDuration)
}
) )
SettingsTile( SettingsTile(
title = "Max duration", title = "Max duration",