mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
share dialog rewrite
This commit is contained in:
parent
14e326e61b
commit
55688921a0
@ -1,27 +1,32 @@
|
|||||||
package com.github.libretube.dialogs
|
package com.github.libretube.dialogs
|
||||||
|
|
||||||
import android.content.Context
|
import android.app.Dialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
|
||||||
fun showShareDialog(context: Context, videoId: String) {
|
class ShareDialog(private val videoId: String) : DialogFragment() {
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
return activity?.let {
|
||||||
val sharedPreferences =
|
val sharedPreferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(context)
|
PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
val instancePref = sharedPreferences.getString(
|
val instancePref = sharedPreferences.getString(
|
||||||
"instance",
|
"instance",
|
||||||
"https://pipedapi.kavin.rocks"
|
"https://pipedapi.kavin.rocks"
|
||||||
)!!
|
)!!
|
||||||
val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}"
|
val instance = "&instance=${URLEncoder.encode(instancePref, "UTF-8")}"
|
||||||
val shareOptions = arrayOf(
|
val shareOptions = arrayOf(
|
||||||
context.getString(R.string.piped),
|
context?.getString(R.string.piped),
|
||||||
context.getString(R.string.instance),
|
context?.getString(R.string.instance),
|
||||||
context.getString(R.string.youtube)
|
context?.getString(R.string.youtube)
|
||||||
)
|
)
|
||||||
MaterialAlertDialogBuilder(context)
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(context.getString(R.string.share))
|
.setTitle(context?.getString(R.string.share))
|
||||||
.setItems(
|
.setItems(
|
||||||
shareOptions
|
shareOptions
|
||||||
) { _, id ->
|
) { _, id ->
|
||||||
@ -35,7 +40,9 @@ fun showShareDialog(context: Context, videoId: String) {
|
|||||||
intent.action = Intent.ACTION_SEND
|
intent.action = Intent.ACTION_SEND
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, url)
|
intent.putExtra(Intent.EXTRA_TEXT, url)
|
||||||
intent.type = "text/plain"
|
intent.type = "text/plain"
|
||||||
context.startActivity(Intent.createChooser(intent, "Share Url To:"))
|
context?.startActivity(Intent.createChooser(intent, "Share Url To:"))
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
|
} ?: throw IllegalStateException("Activity cannot be null")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,8 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
2 -> {
|
2 -> {
|
||||||
showShareDialog(requireContext(), videoId)
|
val shareDialog = ShareDialog(videoId)
|
||||||
|
shareDialog.show(childFragmentManager, "ShareDialog")
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
|
@ -48,7 +48,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.dialogs.ShareDialog
|
||||||
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
|
||||||
@ -493,7 +493,8 @@ class PlayerFragment : Fragment() {
|
|||||||
|
|
||||||
// share button
|
// share button
|
||||||
view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
|
view.findViewById<LinearLayout>(R.id.relPlayer_share).setOnClickListener {
|
||||||
showShareDialog(requireContext(), videoId!!)
|
val shareDialog = ShareDialog(videoId!!)
|
||||||
|
shareDialog.show(childFragmentManager, "ShareDialog")
|
||||||
}
|
}
|
||||||
// check if livestream
|
// check if livestream
|
||||||
if (response.duration!! > 0) {
|
if (response.duration!! > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user