mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
share in videooptionsdialog
This commit is contained in:
parent
a42d5f64e2
commit
16cccc0a5d
@ -2,12 +2,14 @@ package com.github.libretube
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.net.URLEncoder
|
||||
|
||||
/**
|
||||
* Dialog with different options for a selected video.
|
||||
@ -20,7 +22,8 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
|
||||
*/
|
||||
private val list = listOf(
|
||||
context.getString(R.string.playOnBackground),
|
||||
context.getString(R.string.addToPlaylist)
|
||||
context.getString(R.string.addToPlaylist),
|
||||
context.getString(R.string.share)
|
||||
)
|
||||
|
||||
/**
|
||||
@ -61,6 +64,47 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
|
||||
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
2 -> {
|
||||
val sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val instancePref = sharedPreferences.getString(
|
||||
"instance",
|
||||
"https://pipedapi.kavin.rocks"
|
||||
)!!
|
||||
val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}"
|
||||
val shareOptions = arrayOf(
|
||||
getString(R.string.piped),
|
||||
getString(R.string.instance),
|
||||
getString(R.string.youtube)
|
||||
)
|
||||
/*
|
||||
// crashes
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(getString(R.string.share))
|
||||
.setItems(
|
||||
shareOptions
|
||||
) { _, 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"
|
||||
}
|
||||
dismiss()
|
||||
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()
|
||||
*/
|
||||
val intent = Intent()
|
||||
intent.action = Intent.ACTION_SEND
|
||||
intent.putExtra(Intent.EXTRA_TEXT, "https://piped.kavin.rocks/watch?v=$videoId")
|
||||
intent.type = "text/plain"
|
||||
startActivity(Intent.createChooser(intent, "Share Url To:"))
|
||||
}
|
||||
else -> {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user