mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
fix: bugs in time parsing logic causing false (milli) second count
This commit is contained in:
parent
0a00d9c0b1
commit
0ebba0d10c
@ -145,5 +145,5 @@ dependencies {
|
||||
implementation(libs.androidx.paging)
|
||||
|
||||
/* Testing */
|
||||
testImplementation(libs.testng)
|
||||
testImplementation(libs.junit)
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class SubmitSegmentDialog : DialogFragment() {
|
||||
|
||||
requireDialog().hide()
|
||||
|
||||
val startTime = binding.startTime.text.toString().parseDurationString()
|
||||
var startTime = binding.startTime.text.toString().parseDurationString()
|
||||
var endTime = binding.endTime.text.toString().parseDurationString()
|
||||
|
||||
if (endTime == null || startTime == null || startTime > endTime) {
|
||||
@ -87,6 +87,7 @@ class SubmitSegmentDialog : DialogFragment() {
|
||||
return
|
||||
}
|
||||
|
||||
startTime = maxOf(startTime, 0f)
|
||||
if (duration != null) {
|
||||
// the end time can't be greater than the video duration
|
||||
endTime = minOf(endTime, duration!!.toFloat())
|
||||
|
@ -63,6 +63,7 @@ object TextUtils {
|
||||
|
||||
var milliseconds = 0
|
||||
var inMillis = false
|
||||
var millisLength = 0
|
||||
|
||||
for (char in timeString) {
|
||||
if (inMillis) {
|
||||
@ -70,6 +71,7 @@ object TextUtils {
|
||||
|
||||
milliseconds *= 10
|
||||
milliseconds += char.digitToInt()
|
||||
millisLength++
|
||||
} else if (char.isDigit()) {
|
||||
secondsScoped *= 10
|
||||
secondsScoped += char.digitToInt()
|
||||
@ -82,8 +84,9 @@ object TextUtils {
|
||||
inMillis = true
|
||||
}
|
||||
}
|
||||
secondsTotal += secondsScoped
|
||||
|
||||
val millisDecimal = milliseconds.toFloat() / pow(10, milliseconds.toString().length)
|
||||
val millisDecimal = milliseconds.toFloat() / pow(10, millisLength)
|
||||
return secondsTotal.toFloat() + millisDecimal
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ package com.github.libretube
|
||||
|
||||
import com.github.libretube.util.TextUtils.parseDurationString
|
||||
import com.github.libretube.util.TextUtils.toTimeInSeconds
|
||||
import org.junit.Test
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class TextParserTest {
|
||||
@Test
|
||||
@ -12,5 +12,7 @@ class TextParserTest {
|
||||
assertEquals(1520L, "1520".toTimeInSeconds())
|
||||
assertEquals(15L * 60 + 20, "15:20.25".toTimeInSeconds())
|
||||
assertEquals(15f * 60 + 20 + 0.25f, "15:20.25".parseDurationString())
|
||||
assertEquals(20f, "00:20".parseDurationString())
|
||||
assertEquals(60.02503f, "1:00.02503".parseDurationString())
|
||||
}
|
||||
}
|
@ -35,7 +35,6 @@ profileinstaller = "1.3.1"
|
||||
paging = "3.3.0"
|
||||
collection = "1.4.1"
|
||||
swiperefreshlayout = "1.1.0"
|
||||
testng = "7.10.2"
|
||||
|
||||
[libraries]
|
||||
androidx-activity = { group = "androidx.activity", name = "activity-ktx", version.ref = "activity" }
|
||||
@ -84,7 +83,6 @@ androidx-profileinstaller = { group = "androidx.profileinstaller", name = "profi
|
||||
androidx-paging = { group = "androidx.paging", name = "paging-runtime-ktx", version.ref = "paging" }
|
||||
androidx-collection = { group = "androidx.collection", name = "collection", version.ref = "collection" }
|
||||
androidx-swiperefreshlayout = { group = "androidx.swiperefreshlayout", name = "swiperefreshlayout", version.ref = "swiperefreshlayout" }
|
||||
testng = { group = "org.testng", name = "testng", version.ref = "testng" }
|
||||
|
||||
[plugins]
|
||||
androidTest = { id = "com.android.test", version.ref = "gradle" }
|
||||
|
Loading…
x
Reference in New Issue
Block a user