Merge pull request #317 from Bnyro/share

Share to YouTube
This commit is contained in:
Bnyro 2022-05-26 19:30:51 +02:00 committed by GitHub
commit e9d57e31dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 9 deletions

View File

@ -688,19 +688,36 @@ class PlayerFragment : Fragment() {
view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(requireContext())
val intent = Intent()
intent.action = Intent.ACTION_SEND
var url = "https://piped.kavin.rocks/watch?v=$videoId"
val instance = sharedPreferences.getString(
val instancePref = sharedPreferences.getString(
"instance",
"https://pipedapi.kavin.rocks"
)!!
if (instance != "https://pipedapi.kavin.rocks")
url += "&instance=${URLEncoder.encode(instance, "UTF-8")}"
val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}"
val shareOptions = arrayOf(
getString(R.string.piped),
getString(R.string.instance),
getString(R.string.youtube)
)
MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.share))
.setItems(
shareOptions,
DialogInterface.OnClickListener { _, id ->
val url = when (id) {
0 -> "https://piped.kavin.rocks/watch?v=$videoId"
1 -> "https://piped.kavin.rocks/watch?v=$videoId$instance"
2 -> "https://youtu.be/$videoId"
else -> "https://piped.kavin.rocks/watch?v=$videoId"
}
val intent = Intent()
intent.action = Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT, url)
intent.type = "text/plain"
startActivity(Intent.createChooser(intent, "Share Url To:"))
}
)
.show()
}
// check if livestream
if (response.duration!! > 0) {
// download clicked

View File

@ -113,4 +113,6 @@
<string name="app_icon">App Icon</string>
<string name="enabled">Enabled</string>
<string name="disabled">Disabled</string>
<string name="piped">Piped</string>
<string name="youtube">YouTube</string>
</resources>