seperated sharedialog

This commit is contained in:
Bnyro 2022-06-02 21:40:36 +02:00
parent e71ea43a6e
commit 3c3549b56f
3 changed files with 57 additions and 87 deletions

View File

@ -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()
}

View File

@ -2,7 +2,6 @@ package com.github.libretube.dialogs
import android.app.Dialog import android.app.Dialog
import android.content.Context import android.content.Context
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.Toast import android.widget.Toast
@ -67,47 +66,7 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
} }
} }
2 -> { 2 -> {
/* crashes showShareDialog(requireContext(), videoId)
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:"))
} }
else -> { else -> {
dialog.dismiss() dialog.dismiss()

View File

@ -52,6 +52,7 @@ import com.github.libretube.adapters.CommentsAdapter
import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.dialogs.AddtoPlaylistDialog import com.github.libretube.dialogs.AddtoPlaylistDialog
import com.github.libretube.dialogs.DownloadDialog import com.github.libretube.dialogs.DownloadDialog
import com.github.libretube.dialogs.showShareDialog
import com.github.libretube.formatShort import com.github.libretube.formatShort
import com.github.libretube.hideKeyboard import com.github.libretube.hideKeyboard
import com.github.libretube.obj.PipedStream 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.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.squareup.picasso.Picasso 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 org.chromium.net.CronetEngine
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException
import java.util.concurrent.Executors
import kotlin.math.abs
var isFullScreen = false var isFullScreen = false
@ -419,6 +419,16 @@ class PlayerFragment : Fragment() {
private fun initializePlayerView(view: View, response: Streams) { private fun initializePlayerView(view: View, response: Streams) {
isLoading = false isLoading = false
runOnUiThread { 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() var videosNameArray: Array<CharSequence> = arrayOf()
videosNameArray += "HLS" videosNameArray += "HLS"
for (vid in response.videoStreams!!) { for (vid in response.videoStreams!!) {
@ -434,16 +444,6 @@ class PlayerFragment : Fragment() {
.build() .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 = val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(requireContext()) PreferenceManager.getDefaultSharedPreferences(requireContext())
val defres = sharedPreferences.getString("default_res", "")!! val defres = sharedPreferences.getString("default_res", "")!!
@ -709,37 +709,7 @@ class PlayerFragment : Fragment() {
} }
// share button // share button
view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener { view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
val sharedPreferences = showShareDialog(requireContext(), videoId!!)
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()
} }
// check if livestream // check if livestream
if (response.duration!! > 0) { if (response.duration!! > 0) {