fix: Improve formatDuration

This commit is contained in:
Myzel394 2023-08-06 14:44:14 +02:00
parent a8cb592632
commit f131f40ba1
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
2 changed files with 11 additions and 8 deletions

View File

@ -92,9 +92,7 @@ fun MaxDurationTile() {
),
shape = MaterialTheme.shapes.medium,
) {
Text(
text = formatDuration(settings.audioRecorderSettings.maxDuration),
)
Text(formatDuration(settings.audioRecorderSettings.maxDuration))
}
},
extra = {
@ -102,9 +100,7 @@ fun MaxDurationTile() {
items = AudioRecorderSettings.EXAMPLE_MAX_DURATIONS,
onItemSelected = ::updateValue,
) {maxDuration ->
Text(
text = formatDuration(maxDuration),
)
Text(formatDuration(maxDuration))
}
}
)

View File

@ -11,7 +11,7 @@ fun formatDuration(
val hours = floor(totalSeconds / 3600.0).toInt()
val minutes = floor(totalSeconds / 60.0).toInt() % 60
val seconds = totalSeconds - (minutes * 60)
val seconds = totalSeconds - (minutes * 60) - (hours * 3600)
if (formatFull) {
return "" +
@ -29,5 +29,12 @@ fun formatDuration(
return "00:${totalSeconds.toString().padStart(2, '0')}"
}
return "${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}"
if (hours <= 0) {
return "${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}"
}
return "" +
hours.toString().padStart(2, '0') +
":" + minutes.toString().padStart(2, '0') +
":" + seconds.toString().padStart(2, '0')
}