Merge pull request #1671 from shantanu1k/fill-subject-with-title

Sharing video or channel via email
This commit is contained in:
Bnyro 2022-10-29 15:41:38 +02:00 committed by GitHub
commit f20f57795b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 66 additions and 16 deletions

View 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
)

View File

@ -66,8 +66,9 @@ class ChannelAdapter(
} }
val videoId = video.url!!.toID() val videoId = video.url!!.toID()
val videoName = video.title!!
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(videoId) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }

View File

@ -59,8 +59,9 @@ class PlaylistAdapter(
NavigationHelper.navigateVideo(root.context, streamItem.url, playlistId) NavigationHelper.navigateVideo(root.context, streamItem.url, playlistId)
} }
val videoId = streamItem.url!!.toID() val videoId = streamItem.url!!.toID()
val videoName = streamItem.title!!
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(videoId) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }

View File

@ -73,6 +73,7 @@ class PlaylistsAdapter(
root.setOnLongClickListener { root.setOnLongClickListener {
val playlistOptionsDialog = PlaylistOptionsBottomSheet( val playlistOptionsDialog = PlaylistOptionsBottomSheet(
playlistId = playlist.id!!, playlistId = playlist.id!!,
playlistName = playlist.name!!,
isOwner = true isOwner = true
) )
playlistOptionsDialog.show( playlistOptionsDialog.show(

View File

@ -100,8 +100,9 @@ class SearchAdapter(
NavigationHelper.navigateVideo(root.context, item.url) NavigationHelper.navigateVideo(root.context, item.url)
} }
val videoId = item.url!!.toID() val videoId = item.url!!.toID()
val videoName = item.title!!
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(videoId) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }
@ -181,7 +182,8 @@ class SearchAdapter(
} }
root.setOnLongClickListener { root.setOnLongClickListener {
val playlistId = item.url!!.toID() val playlistId = item.url!!.toID()
PlaylistOptionsBottomSheet(playlistId, false) val playlistName = item.name!!
PlaylistOptionsBottomSheet(playlistId, playlistName, false)
.show(childFragmentManager, PlaylistOptionsBottomSheet::class.java.name) .show(childFragmentManager, PlaylistOptionsBottomSheet::class.java.name)
true true
} }

View File

@ -68,8 +68,9 @@ class TrendingAdapter(
NavigationHelper.navigateVideo(root.context, trending.url) NavigationHelper.navigateVideo(root.context, trending.url)
} }
val videoId = trending.url!!.toID() val videoId = trending.url!!.toID()
val videoName = trending.title!!
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(videoId) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }

View File

@ -55,7 +55,7 @@ class WatchHistoryAdapter(
NavigationHelper.navigateVideo(root.context, video.videoId) NavigationHelper.navigateVideo(root.context, video.videoId)
} }
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(video.videoId) VideoOptionsBottomSheet(video.videoId, video.title!!)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }

View File

@ -13,12 +13,14 @@ import com.github.libretube.constants.YOUTUBE_FRONTEND_URL
import com.github.libretube.databinding.DialogShareBinding import com.github.libretube.databinding.DialogShareBinding
import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.awaitQuery
import com.github.libretube.obj.ShareData
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
class ShareDialog( class ShareDialog(
private val id: String, private val id: String,
private val shareObjectType: Int, private val shareObjectType: Int,
private val shareData: ShareData,
private val position: Long? = null private val position: Long? = null
) : DialogFragment() { ) : DialogFragment() {
private var binding: DialogShareBinding? = null private var binding: DialogShareBinding? = null
@ -29,7 +31,7 @@ class ShareDialog(
getString(R.string.youtube) getString(R.string.youtube)
) )
val instanceUrl = getCustomInstanceFrontendUrl() val instanceUrl = getCustomInstanceFrontendUrl()
val shareableTitle = getShareableTitle(shareData)
// add instanceUrl option if custom instance frontend url available // add instanceUrl option if custom instance frontend url available
if (instanceUrl != "") shareOptions += getString(R.string.instance) if (instanceUrl != "") shareOptions += getString(R.string.instance)
@ -63,6 +65,7 @@ class ShareDialog(
intent.apply { intent.apply {
action = Intent.ACTION_SEND action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url) putExtra(Intent.EXTRA_TEXT, url)
putExtra(Intent.EXTRA_SUBJECT, shareableTitle)
type = "text/plain" type = "text/plain"
} }
context?.startActivity( context?.startActivity(
@ -104,4 +107,18 @@ class ShareDialog(
} }
return "" return ""
} }
private fun getShareableTitle(shareData: ShareData): String {
shareData.apply {
currentChannel?.let {
return it
}
currentVideo?.let {
return it
}
currentPlaylist?.let {
return it
}
}
return ""
}
} }

View File

@ -19,6 +19,7 @@ import com.github.libretube.databinding.FragmentChannelBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID 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.ChannelAdapter
import com.github.libretube.ui.adapters.SearchAdapter import com.github.libretube.ui.adapters.SearchAdapter
import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.base.BaseFragment
@ -36,7 +37,6 @@ class ChannelFragment : BaseFragment() {
private var channelId: String? = null private var channelId: String? = null
private var channelName: String? = null private var channelName: String? = null
private var nextPage: String? = null private var nextPage: String? = null
private var channelAdapter: ChannelAdapter? = null private var channelAdapter: ChannelAdapter? = null
private var isLoading = true private var isLoading = true
@ -112,6 +112,7 @@ class ChannelFragment : BaseFragment() {
} }
// needed if the channel gets loaded by the ID // needed if the channel gets loaded by the ID
channelId = response.id channelId = response.id
val shareData = ShareData(currentChannel = response.name)
onScrollEnd = { onScrollEnd = {
if (nextPage != null && !isLoading) { if (nextPage != null && !isLoading) {
@ -143,7 +144,11 @@ class ChannelFragment : BaseFragment() {
} }
binding.channelShare.setOnClickListener { 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) shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
} }
} }

View File

@ -57,6 +57,7 @@ import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toStreamItem import com.github.libretube.extensions.toStreamItem
import com.github.libretube.models.PlayerViewModel import com.github.libretube.models.PlayerViewModel
import com.github.libretube.models.interfaces.OnlinePlayerOptions import com.github.libretube.models.interfaces.OnlinePlayerOptions
import com.github.libretube.obj.ShareData
import com.github.libretube.services.BackgroundMode import com.github.libretube.services.BackgroundMode
import com.github.libretube.services.DownloadService import com.github.libretube.services.DownloadService
import com.github.libretube.ui.activities.MainActivity import com.github.libretube.ui.activities.MainActivity
@ -161,6 +162,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
*/ */
private lateinit var nowPlayingNotification: NowPlayingNotification private lateinit var nowPlayingNotification: NowPlayingNotification
private lateinit var shareData: ShareData
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { arguments?.let {
@ -360,7 +363,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
// share button // share button
binding.relPlayerShare.setOnClickListener { binding.relPlayerShare.setOnClickListener {
val shareDialog = val shareDialog =
ShareDialog(videoId!!, ShareObjectType.VIDEO, exoPlayer.currentPosition / 1000) ShareDialog(
videoId!!,
ShareObjectType.VIDEO,
shareData,
exoPlayer.currentPosition / 1000
)
shareDialog.show(childFragmentManager, ShareDialog::class.java.name) shareDialog.show(childFragmentManager, ShareDialog::class.java.name)
} }
@ -762,6 +770,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
titleTextView.text = response.title titleTextView.text = response.title
playerTitle.text = response.title playerTitle.text = response.title
shareData = ShareData(currentVideo = response.title)
playerDescription.text = response.description playerDescription.text = response.description
playerChannelSubCount.text = context?.getString( playerChannelSubCount.text = context?.getString(

View File

@ -25,6 +25,7 @@ class PlaylistFragment : BaseFragment() {
private lateinit var binding: FragmentPlaylistBinding private lateinit var binding: FragmentPlaylistBinding
private var playlistId: String? = null private var playlistId: String? = null
private var playlistName: String? = null
private var isOwner: Boolean = false private var isOwner: Boolean = false
private var nextPage: String? = null private var nextPage: String? = null
private var playlistAdapter: PlaylistAdapter? = null private var playlistAdapter: PlaylistAdapter? = null
@ -75,6 +76,7 @@ class PlaylistFragment : BaseFragment() {
return@launchWhenCreated return@launchWhenCreated
} }
nextPage = response.nextpage nextPage = response.nextpage
playlistName = response.name
isLoading = false isLoading = false
runOnUiThread { runOnUiThread {
binding.playlistProgress.visibility = View.GONE binding.playlistProgress.visibility = View.GONE
@ -86,7 +88,7 @@ class PlaylistFragment : BaseFragment() {
// show playlist options // show playlist options
binding.optionsMenu.setOnClickListener { binding.optionsMenu.setOnClickListener {
val optionsDialog = val optionsDialog =
PlaylistOptionsBottomSheet(playlistId!!, isOwner) PlaylistOptionsBottomSheet(playlistId!!, playlistName!!, isOwner)
optionsDialog.show( optionsDialog.show(
childFragmentManager, childFragmentManager,
PlaylistOptionsBottomSheet::class.java.name PlaylistOptionsBottomSheet::class.java.name

View File

@ -11,6 +11,7 @@ import com.github.libretube.constants.ShareObjectType
import com.github.libretube.databinding.DialogTextPreferenceBinding import com.github.libretube.databinding.DialogTextPreferenceBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.obj.ShareData
import com.github.libretube.ui.dialogs.ShareDialog import com.github.libretube.ui.dialogs.ShareDialog
import com.github.libretube.ui.views.BottomSheet import com.github.libretube.ui.views.BottomSheet
import com.github.libretube.util.BackgroundHelper import com.github.libretube.util.BackgroundHelper
@ -25,9 +26,10 @@ import java.io.IOException
class PlaylistOptionsBottomSheet( class PlaylistOptionsBottomSheet(
private val playlistId: String, private val playlistId: String,
private val playlistName: String,
private val isOwner: Boolean private val isOwner: Boolean
) : BottomSheet() { ) : BottomSheet() {
private val shareData = ShareData(currentPlaylist = playlistName)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
// options for the dialog // options for the dialog
var optionsList = listOf( var optionsList = listOf(
@ -76,7 +78,7 @@ class PlaylistOptionsBottomSheet(
} }
// share the playlist // share the playlist
context?.getString(R.string.share) -> { 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 // using parentFragmentManager, childFragmentManager doesn't work here
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
} }

View File

@ -7,6 +7,7 @@ import com.github.libretube.api.RetrofitInstance
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.ShareObjectType import com.github.libretube.constants.ShareObjectType
import com.github.libretube.extensions.toStreamItem 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.AddToPlaylistDialog
import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.DownloadDialog
import com.github.libretube.ui.dialogs.ShareDialog 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. * Needs the [videoId] to load the content from the right video.
*/ */
class VideoOptionsBottomSheet( class VideoOptionsBottomSheet(
private val videoId: String private val videoId: String,
private val videoName: String
) : BottomSheet() { ) : BottomSheet() {
private val shareData = ShareData(currentVideo = videoName)
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
// List that stores the different menu options. In the future could be add more options here. // List that stores the different menu options. In the future could be add more options here.
val optionsList = mutableListOf( val optionsList = mutableListOf(
@ -79,7 +81,7 @@ class VideoOptionsBottomSheet(
downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name) downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name)
} }
context?.getString(R.string.share) -> { context?.getString(R.string.share) -> {
val shareDialog = ShareDialog(videoId, ShareObjectType.VIDEO) val shareDialog = ShareDialog(videoId, ShareObjectType.VIDEO, shareData)
// using parentFragmentManager is important here // using parentFragmentManager is important here
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
} }