mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #1671 from shantanu1k/fill-subject-with-title
Sharing video or channel via email
This commit is contained in:
commit
f20f57795b
7
app/src/main/java/com/github/libretube/obj/ShareData.kt
Normal file
7
app/src/main/java/com/github/libretube/obj/ShareData.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
data class ShareData(
|
||||
val currentChannel: String ? = null,
|
||||
val currentVideo: String ? = null,
|
||||
val currentPlaylist: String ? = null
|
||||
)
|
@ -66,8 +66,9 @@ class ChannelAdapter(
|
||||
}
|
||||
|
||||
val videoId = video.url!!.toID()
|
||||
val videoName = video.title!!
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(videoId)
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
|
@ -59,8 +59,9 @@ class PlaylistAdapter(
|
||||
NavigationHelper.navigateVideo(root.context, streamItem.url, playlistId)
|
||||
}
|
||||
val videoId = streamItem.url!!.toID()
|
||||
val videoName = streamItem.title!!
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(videoId)
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ class PlaylistsAdapter(
|
||||
root.setOnLongClickListener {
|
||||
val playlistOptionsDialog = PlaylistOptionsBottomSheet(
|
||||
playlistId = playlist.id!!,
|
||||
playlistName = playlist.name!!,
|
||||
isOwner = true
|
||||
)
|
||||
playlistOptionsDialog.show(
|
||||
|
@ -100,8 +100,9 @@ class SearchAdapter(
|
||||
NavigationHelper.navigateVideo(root.context, item.url)
|
||||
}
|
||||
val videoId = item.url!!.toID()
|
||||
val videoName = item.title!!
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(videoId)
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
@ -181,7 +182,8 @@ class SearchAdapter(
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
val playlistId = item.url!!.toID()
|
||||
PlaylistOptionsBottomSheet(playlistId, false)
|
||||
val playlistName = item.name!!
|
||||
PlaylistOptionsBottomSheet(playlistId, playlistName, false)
|
||||
.show(childFragmentManager, PlaylistOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
|
@ -68,8 +68,9 @@ class TrendingAdapter(
|
||||
NavigationHelper.navigateVideo(root.context, trending.url)
|
||||
}
|
||||
val videoId = trending.url!!.toID()
|
||||
val videoName = trending.title!!
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(videoId)
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class WatchHistoryAdapter(
|
||||
NavigationHelper.navigateVideo(root.context, video.videoId)
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(video.videoId)
|
||||
VideoOptionsBottomSheet(video.videoId, video.title!!)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
|
@ -13,12 +13,14 @@ import com.github.libretube.constants.YOUTUBE_FRONTEND_URL
|
||||
import com.github.libretube.databinding.DialogShareBinding
|
||||
import com.github.libretube.db.DatabaseHolder.Companion.Database
|
||||
import com.github.libretube.extensions.awaitQuery
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class ShareDialog(
|
||||
private val id: String,
|
||||
private val shareObjectType: Int,
|
||||
private val shareData: ShareData,
|
||||
private val position: Long? = null
|
||||
) : DialogFragment() {
|
||||
private var binding: DialogShareBinding? = null
|
||||
@ -29,7 +31,7 @@ class ShareDialog(
|
||||
getString(R.string.youtube)
|
||||
)
|
||||
val instanceUrl = getCustomInstanceFrontendUrl()
|
||||
|
||||
val shareableTitle = getShareableTitle(shareData)
|
||||
// add instanceUrl option if custom instance frontend url available
|
||||
if (instanceUrl != "") shareOptions += getString(R.string.instance)
|
||||
|
||||
@ -63,6 +65,7 @@ class ShareDialog(
|
||||
intent.apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, url)
|
||||
putExtra(Intent.EXTRA_SUBJECT, shareableTitle)
|
||||
type = "text/plain"
|
||||
}
|
||||
context?.startActivity(
|
||||
@ -104,4 +107,18 @@ class ShareDialog(
|
||||
}
|
||||
return ""
|
||||
}
|
||||
private fun getShareableTitle(shareData: ShareData): String {
|
||||
shareData.apply {
|
||||
currentChannel?.let {
|
||||
return it
|
||||
}
|
||||
currentVideo?.let {
|
||||
return it
|
||||
}
|
||||
currentPlaylist?.let {
|
||||
return it
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import com.github.libretube.databinding.FragmentChannelBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.formatShort
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.ui.adapters.ChannelAdapter
|
||||
import com.github.libretube.ui.adapters.SearchAdapter
|
||||
import com.github.libretube.ui.base.BaseFragment
|
||||
@ -36,7 +37,6 @@ class ChannelFragment : BaseFragment() {
|
||||
|
||||
private var channelId: String? = null
|
||||
private var channelName: String? = null
|
||||
|
||||
private var nextPage: String? = null
|
||||
private var channelAdapter: ChannelAdapter? = null
|
||||
private var isLoading = true
|
||||
@ -112,6 +112,7 @@ class ChannelFragment : BaseFragment() {
|
||||
}
|
||||
// needed if the channel gets loaded by the ID
|
||||
channelId = response.id
|
||||
val shareData = ShareData(currentChannel = response.name)
|
||||
|
||||
onScrollEnd = {
|
||||
if (nextPage != null && !isLoading) {
|
||||
@ -143,7 +144,11 @@ class ChannelFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
binding.channelShare.setOnClickListener {
|
||||
val shareDialog = ShareDialog(response.id!!.toID(), ShareObjectType.CHANNEL)
|
||||
val shareDialog = ShareDialog(
|
||||
response.id!!.toID(),
|
||||
ShareObjectType.CHANNEL,
|
||||
shareData
|
||||
)
|
||||
shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.extensions.toStreamItem
|
||||
import com.github.libretube.models.PlayerViewModel
|
||||
import com.github.libretube.models.interfaces.OnlinePlayerOptions
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.services.BackgroundMode
|
||||
import com.github.libretube.services.DownloadService
|
||||
import com.github.libretube.ui.activities.MainActivity
|
||||
@ -161,6 +162,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
*/
|
||||
private lateinit var nowPlayingNotification: NowPlayingNotification
|
||||
|
||||
private lateinit var shareData: ShareData
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
arguments?.let {
|
||||
@ -360,7 +363,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
// share button
|
||||
binding.relPlayerShare.setOnClickListener {
|
||||
val shareDialog =
|
||||
ShareDialog(videoId!!, ShareObjectType.VIDEO, exoPlayer.currentPosition / 1000)
|
||||
ShareDialog(
|
||||
videoId!!,
|
||||
ShareObjectType.VIDEO,
|
||||
shareData,
|
||||
exoPlayer.currentPosition / 1000
|
||||
)
|
||||
shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
||||
@ -762,6 +770,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
titleTextView.text = response.title
|
||||
|
||||
playerTitle.text = response.title
|
||||
shareData = ShareData(currentVideo = response.title)
|
||||
playerDescription.text = response.description
|
||||
|
||||
playerChannelSubCount.text = context?.getString(
|
||||
|
@ -25,6 +25,7 @@ class PlaylistFragment : BaseFragment() {
|
||||
private lateinit var binding: FragmentPlaylistBinding
|
||||
|
||||
private var playlistId: String? = null
|
||||
private var playlistName: String? = null
|
||||
private var isOwner: Boolean = false
|
||||
private var nextPage: String? = null
|
||||
private var playlistAdapter: PlaylistAdapter? = null
|
||||
@ -75,6 +76,7 @@ class PlaylistFragment : BaseFragment() {
|
||||
return@launchWhenCreated
|
||||
}
|
||||
nextPage = response.nextpage
|
||||
playlistName = response.name
|
||||
isLoading = false
|
||||
runOnUiThread {
|
||||
binding.playlistProgress.visibility = View.GONE
|
||||
@ -86,7 +88,7 @@ class PlaylistFragment : BaseFragment() {
|
||||
// show playlist options
|
||||
binding.optionsMenu.setOnClickListener {
|
||||
val optionsDialog =
|
||||
PlaylistOptionsBottomSheet(playlistId!!, isOwner)
|
||||
PlaylistOptionsBottomSheet(playlistId!!, playlistName!!, isOwner)
|
||||
optionsDialog.show(
|
||||
childFragmentManager,
|
||||
PlaylistOptionsBottomSheet::class.java.name
|
||||
|
@ -11,6 +11,7 @@ import com.github.libretube.constants.ShareObjectType
|
||||
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.ui.dialogs.ShareDialog
|
||||
import com.github.libretube.ui.views.BottomSheet
|
||||
import com.github.libretube.util.BackgroundHelper
|
||||
@ -25,9 +26,10 @@ import java.io.IOException
|
||||
|
||||
class PlaylistOptionsBottomSheet(
|
||||
private val playlistId: String,
|
||||
private val playlistName: String,
|
||||
private val isOwner: Boolean
|
||||
) : BottomSheet() {
|
||||
|
||||
private val shareData = ShareData(currentPlaylist = playlistName)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// options for the dialog
|
||||
var optionsList = listOf(
|
||||
@ -76,7 +78,7 @@ class PlaylistOptionsBottomSheet(
|
||||
}
|
||||
// share the playlist
|
||||
context?.getString(R.string.share) -> {
|
||||
val shareDialog = ShareDialog(playlistId, ShareObjectType.PLAYLIST)
|
||||
val shareDialog = ShareDialog(playlistId, ShareObjectType.PLAYLIST, shareData)
|
||||
// using parentFragmentManager, childFragmentManager doesn't work here
|
||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.ShareObjectType
|
||||
import com.github.libretube.extensions.toStreamItem
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
||||
import com.github.libretube.ui.dialogs.DownloadDialog
|
||||
import com.github.libretube.ui.dialogs.ShareDialog
|
||||
@ -24,9 +25,10 @@ import kotlinx.coroutines.launch
|
||||
* Needs the [videoId] to load the content from the right video.
|
||||
*/
|
||||
class VideoOptionsBottomSheet(
|
||||
private val videoId: String
|
||||
private val videoId: String,
|
||||
private val videoName: String
|
||||
) : BottomSheet() {
|
||||
|
||||
private val shareData = ShareData(currentVideo = videoName)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
// List that stores the different menu options. In the future could be add more options here.
|
||||
val optionsList = mutableListOf(
|
||||
@ -79,7 +81,7 @@ class VideoOptionsBottomSheet(
|
||||
downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name)
|
||||
}
|
||||
context?.getString(R.string.share) -> {
|
||||
val shareDialog = ShareDialog(videoId, ShareObjectType.VIDEO)
|
||||
val shareDialog = ShareDialog(videoId, ShareObjectType.VIDEO, shareData)
|
||||
// using parentFragmentManager is important here
|
||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user