Merge pull request #6382 from Bnyro/master

feat: use watch position as timestamp when sharing
This commit is contained in:
Bnyro 2024-08-23 12:44:07 +02:00 committed by GitHub
commit f30a37fab6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,7 +82,7 @@ class ShareDialog : DialogFragment() {
binding.timeStamp.addTextChangedListener { binding.timeStamp.addTextChangedListener {
binding.linkPreview.text = generateLinkText(binding, customInstanceUrl) binding.linkPreview.text = generateLinkText(binding, customInstanceUrl)
} }
binding.timeStamp.setText((shareData.currentPosition ?: 0L).toString()) binding.timeStamp.setText((shareData.currentPosition ?: getWatchPosition(id) ?: 0L).toString())
if (binding.timeCodeSwitch.isChecked) { if (binding.timeCodeSwitch.isChecked) {
binding.timeStampInputLayout.isVisible = true binding.timeStampInputLayout.isVisible = true
} }
@ -145,6 +145,10 @@ class ShareDialog : DialogFragment() {
return url return url
} }
private fun getWatchPosition(videoId: String) = runBlocking {
Database.watchPositionDao().findById(videoId)
}?.position?.div(1000)
companion object { companion object {
const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com"
const val YOUTUBE_SHORT_URL = "https://youtu.be" const val YOUTUBE_SHORT_URL = "https://youtu.be"