From f45eef43e44de7db2073eca968ebceb8353d71bc Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 23 Aug 2024 12:43:44 +0200 Subject: [PATCH] feat: use watch position as timestamp when sharing --- .../java/com/github/libretube/ui/dialogs/ShareDialog.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt index 08938b559..6e2a6ac32 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt @@ -82,7 +82,7 @@ class ShareDialog : DialogFragment() { binding.timeStamp.addTextChangedListener { 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) { binding.timeStampInputLayout.isVisible = true } @@ -145,6 +145,10 @@ class ShareDialog : DialogFragment() { return url } + private fun getWatchPosition(videoId: String) = runBlocking { + Database.watchPositionDao().findById(videoId) + }?.position?.div(1000) + companion object { const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" const val YOUTUBE_SHORT_URL = "https://youtu.be"