mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
fix: handle duration string timestamps (#1275)
This commit is contained in:
parent
bcd33bf23e
commit
3de1836a2f
@ -10,6 +10,7 @@ import com.github.libretube.constants.IntentData
|
|||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
import com.github.libretube.ui.base.BaseActivity
|
import com.github.libretube.ui.base.BaseActivity
|
||||||
import com.github.libretube.util.NavigationHelper
|
import com.github.libretube.util.NavigationHelper
|
||||||
|
import kotlin.time.Duration
|
||||||
|
|
||||||
class RouterActivity : BaseActivity() {
|
class RouterActivity : BaseActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -75,14 +76,14 @@ class RouterActivity : BaseActivity() {
|
|||||||
|
|
||||||
intent.putExtra(IntentData.videoId, videoId)
|
intent.putExtra(IntentData.videoId, videoId)
|
||||||
uri.getQueryParameter("t")
|
uri.getQueryParameter("t")
|
||||||
?.let { intent.putExtra(IntentData.timeStamp, it.toLong()) }
|
?.let { intent.putExtra(IntentData.timeStamp, parseTimestamp(it)) }
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val videoId = uri.path!!.replace("/", "")
|
val videoId = uri.path!!.replace("/", "")
|
||||||
|
|
||||||
intent.putExtra(IntentData.videoId, videoId)
|
intent.putExtra(IntentData.videoId, videoId)
|
||||||
uri.getQueryParameter("t")
|
uri.getQueryParameter("t")
|
||||||
?.let { intent.putExtra(IntentData.timeStamp, it.toLong()) }
|
?.let { intent.putExtra(IntentData.timeStamp, parseTimestamp(it)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return intent
|
return intent
|
||||||
@ -99,4 +100,12 @@ class RouterActivity : BaseActivity() {
|
|||||||
)
|
)
|
||||||
this.finishAndRemoveTask()
|
this.finishAndRemoveTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseTimestamp(t: String): Long? {
|
||||||
|
if (t.all { c -> c.isDigit() }) {
|
||||||
|
return t.toLong()
|
||||||
|
}
|
||||||
|
|
||||||
|
return Duration.parseOrNull(t)?.inWholeSeconds
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user