[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix crash on invalid value input #52

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Fix crash on invalid value input
  • Loading branch information
Myzel394 committed Nov 20, 2023
commit 2010d8ad94583fe65e3d79ed9b235eccb2ef5a0a
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ fun BitrateTile(
val bitRate = text?.toIntOrNull()

if (bitRate == null) {
ValidationResult.Invalid(notNumberLabel)
return@InputTextField ValidationResult.Invalid(notNumberLabel)
}

if (bitRate !in 1..320) {
ValidationResult.Invalid(notInRangeLabel)
return@InputTextField ValidationResult.Invalid(notInRangeLabel)
}

ValidationResult.Valid
Expand All @@ -92,7 +92,9 @@ fun BitrateTile(
)
),
) { result ->
val bitRate = result.getString("bitrate")?.toIntOrNull() ?: throw IllegalStateException("Bitrate is null")
val bitRate = result.getString("bitrate")?.toIntOrNull() ?: throw IllegalStateException(
"Bitrate is null"
)

updateValue(bitRate * 1000)
}
Expand Down Expand Up @@ -126,7 +128,7 @@ fun BitrateTile(
ExampleListRoulette(
items = AudioRecorderSettings.EXAMPLE_BITRATE_VALUES,
>
) {bitRate ->
) { bitRate ->
Text(
stringResource(
R.string.format_kbps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ fun SamplingRateTile(
header = Header.Default(
title = stringResource(R.string.ui_settings_option_samplingRate_title),
icon = IconSource(
painter = IconResource.fromImageVector(Icons.Default.RadioButtonChecked).asPainterResource(),
painter = IconResource.fromImageVector(Icons.Default.RadioButtonChecked)
.asPainterResource(),
contentDescription = null,
)
),
Expand All @@ -79,11 +80,11 @@ fun SamplingRateTile(
val samplingRate = text?.toIntOrNull()

if (samplingRate == null) {
ValidationResult.Invalid(notNumberLabel)
return@InputTextField ValidationResult.Invalid(notNumberLabel)
}

if (samplingRate!! <= 1000) {
ValidationResult.Invalid(mustBeGreaterThanLabel)
if (samplingRate <= 1000) {
return@InputTextField ValidationResult.Invalid(mustBeGreaterThanLabel)
}

ValidationResult.Valid
Expand All @@ -92,7 +93,8 @@ fun SamplingRateTile(
)
),
) { result ->
val samplingRate = result.getString("samplingRate")?.toIntOrNull() ?: throw IllegalStateException("SamplingRate is null")
val samplingRate = result.getString("samplingRate")?.toIntOrNull()
?: throw IllegalStateException("SamplingRate is null")

updateValue(samplingRate)
}
Expand All @@ -115,17 +117,19 @@ fun SamplingRateTile(
shape = MaterialTheme.shapes.medium,
) {
Text(
(settings.audioRecorderSettings.samplingRate ?: stringResource(R.string.ui_settings_value_auto_label)).toString()
(settings.audioRecorderSettings.samplingRate
?: stringResource(R.string.ui_settings_value_auto_label)).toString()
)
}
},
extra = {
ExampleListRoulette(
items = AudioRecorderSettings.EXAMPLE_SAMPLING_RATE,
>
) {samplingRate ->
) { samplingRate ->
Text(
(samplingRate ?: stringResource(R.string.ui_settings_value_auto_label)).toString()
(samplingRate
?: stringResource(R.string.ui_settings_value_auto_label)).toString()
)
}
}
Expand Down