From 503fe186bbdcee8f3c8f887b49b254866c433877 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 3 Aug 2022 13:49:57 +0200 Subject: [PATCH] share with time code --- .../java/com/github/libretube/dialogs/ShareDialog.kt | 12 ++++++++++-- .../com/github/libretube/fragments/PlayerFragment.kt | 2 +- .../github/libretube/preferences/PreferenceKeys.kt | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/advanced_settings.xml | 10 ++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt index dd81f0e96..7509229ce 100644 --- a/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/ShareDialog.kt @@ -13,7 +13,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder class ShareDialog( private val id: String, - private val isPlaylist: Boolean + private val isPlaylist: Boolean, + private val position: Long = 0L ) : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { @@ -39,7 +40,14 @@ class ShareDialog( else -> instanceUrl } val path = if (!isPlaylist) "/watch?v=$id" else "/playlist?list=$id" - val url = "$host$path" + var url = "$host$path" + if (PreferenceHelper.getBoolean( + PreferenceKeys.SHARE_WITH_TIME_CODE, + true + ) + ) { + url += "?t=$position" + } val intent = Intent() intent.apply { diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 479c76ece..898d968eb 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -540,7 +540,7 @@ class PlayerFragment : Fragment() { // share button binding.relPlayerShare.setOnClickListener { - val shareDialog = ShareDialog(videoId!!, false) + val shareDialog = ShareDialog(videoId!!, false, exoPlayer.currentPosition) shareDialog.show(childFragmentManager, "ShareDialog") } diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt index f136d6f96..18ad2c013 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -80,6 +80,7 @@ object PreferenceKeys { const val CLEAR_SEARCH_HISTORY = "clear_search_history" const val CLEAR_WATCH_HISTORY = "clear_watch_history" const val CLEAR_WATCH_POSITIONS = "clear_watch_positions" + const val SHARE_WITH_TIME_CODE = "share_with_time_code" /** * Error logs diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4218711b7..9824e73f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -290,4 +290,5 @@ Error occurred Copied Download succeeded + Share with time code \ No newline at end of file diff --git a/app/src/main/res/xml/advanced_settings.xml b/app/src/main/res/xml/advanced_settings.xml index 7e0114b62..241e2c19b 100644 --- a/app/src/main/res/xml/advanced_settings.xml +++ b/app/src/main/res/xml/advanced_settings.xml @@ -22,6 +22,16 @@ + + + + + +