mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
seperated sharedialog
This commit is contained in:
parent
e71ea43a6e
commit
3c3549b56f
@ -0,0 +1,41 @@
|
||||
package com.github.libretube.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.github.libretube.R
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.net.URLEncoder
|
||||
|
||||
fun showShareDialog(context: Context, videoId: String) {
|
||||
val sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val instancePref = sharedPreferences.getString(
|
||||
"instance",
|
||||
"https://pipedapi.kavin.rocks"
|
||||
)!!
|
||||
val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}"
|
||||
val shareOptions = arrayOf(
|
||||
context.getString(R.string.piped),
|
||||
context.getString(R.string.instance),
|
||||
context.getString(R.string.youtube)
|
||||
)
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(context.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"
|
||||
}
|
||||
val intent = Intent()
|
||||
intent.action = Intent.ACTION_SEND
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url)
|
||||
intent.type = "text/plain"
|
||||
context.startActivity(Intent.createChooser(intent, "Share Url To:"))
|
||||
}
|
||||
.show()
|
||||
}
|
@ -2,7 +2,6 @@ package com.github.libretube.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
@ -67,47 +66,7 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
|
||||
}
|
||||
}
|
||||
2 -> {
|
||||
/* crashes
|
||||
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)
|
||||
)
|
||||
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:"))
|
||||
showShareDialog(requireContext(), videoId)
|
||||
}
|
||||
else -> {
|
||||
dialog.dismiss()
|
||||
|
@ -52,6 +52,7 @@ import com.github.libretube.adapters.CommentsAdapter
|
||||
import com.github.libretube.adapters.TrendingAdapter
|
||||
import com.github.libretube.dialogs.AddtoPlaylistDialog
|
||||
import com.github.libretube.dialogs.DownloadDialog
|
||||
import com.github.libretube.dialogs.showShareDialog
|
||||
import com.github.libretube.formatShort
|
||||
import com.github.libretube.hideKeyboard
|
||||
import com.github.libretube.obj.PipedStream
|
||||
@ -83,12 +84,11 @@ import com.google.android.exoplayer2.util.RepeatModeUtil
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.squareup.picasso.Picasso
|
||||
import java.io.IOException
|
||||
import java.net.URLEncoder
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.abs
|
||||
import org.chromium.net.CronetEngine
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.abs
|
||||
|
||||
var isFullScreen = false
|
||||
|
||||
@ -419,6 +419,16 @@ class PlayerFragment : Fragment() {
|
||||
private fun initializePlayerView(view: View, response: Streams) {
|
||||
isLoading = false
|
||||
runOnUiThread {
|
||||
createExoPlayer(view)
|
||||
|
||||
exoPlayerView.setShowSubtitleButton(true)
|
||||
exoPlayerView.setShowNextButton(false)
|
||||
exoPlayerView.setShowPreviousButton(false)
|
||||
exoPlayerView.setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL)
|
||||
// exoPlayerView.controllerShowTimeoutMs = 1500
|
||||
exoPlayerView.controllerHideOnTouch = true
|
||||
exoPlayerView.player = exoPlayer
|
||||
|
||||
var videosNameArray: Array<CharSequence> = arrayOf()
|
||||
videosNameArray += "HLS"
|
||||
for (vid in response.videoStreams!!) {
|
||||
@ -434,16 +444,6 @@ class PlayerFragment : Fragment() {
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
createExoPlayer(view)
|
||||
|
||||
exoPlayerView.setShowSubtitleButton(true)
|
||||
exoPlayerView.setShowNextButton(false)
|
||||
exoPlayerView.setShowPreviousButton(false)
|
||||
exoPlayerView.setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL)
|
||||
// exoPlayerView.controllerShowTimeoutMs = 1500
|
||||
exoPlayerView.controllerHideOnTouch = true
|
||||
exoPlayerView.player = exoPlayer
|
||||
val sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
val defres = sharedPreferences.getString("default_res", "")!!
|
||||
@ -709,37 +709,7 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
// share button
|
||||
view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
|
||||
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)
|
||||
)
|
||||
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()
|
||||
showShareDialog(requireContext(), videoId!!)
|
||||
}
|
||||
// check if livestream
|
||||
if (response.duration!! > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user