mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Merge pull request #4743 from Bnyro/master
fix: remove fragment constructors from video and channel options bott…
This commit is contained in:
commit
c11cb94f6d
@ -1,10 +1,13 @@
|
||||
package com.github.libretube.api.obj
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.github.libretube.db.obj.LocalPlaylistItem
|
||||
import com.github.libretube.extensions.toID
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@Parcelize
|
||||
data class StreamItem(
|
||||
val url: String? = null,
|
||||
val type: String? = null,
|
||||
@ -20,7 +23,7 @@ data class StreamItem(
|
||||
val uploaded: Long? = null,
|
||||
val shortDescription: String? = null,
|
||||
val isShort: Boolean = false
|
||||
) {
|
||||
): Parcelable {
|
||||
fun toLocalPlaylistItem(playlistId: String): LocalPlaylistItem {
|
||||
return LocalPlaylistItem(
|
||||
playlistId = playlistId.toInt(),
|
||||
|
@ -28,4 +28,5 @@ object IntentData {
|
||||
const val loginTask = "loginTask"
|
||||
const val logoutTask = "logoutTask"
|
||||
const val color = "color"
|
||||
const val streamItem = "streamItem"
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.LegacySubscriptionChannelBinding
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.helpers.ImageHelper
|
||||
@ -40,8 +42,12 @@ class LegacySubscriptionAdapter(
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
ChannelOptionsBottomSheet(subscription.url.toID(), subscription.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager)
|
||||
val channelOptionsSheet = ChannelOptionsBottomSheet()
|
||||
channelOptionsSheet.arguments = bundleOf(
|
||||
IntentData.channelId to subscription.url.toID(),
|
||||
IntentData.channelName to subscription.name
|
||||
)
|
||||
channelOptionsSheet.show((root.context as BaseActivity).supportFragmentManager)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,14 @@ import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.PlaylistsHelper
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.VideoRowBinding
|
||||
import com.github.libretube.enums.PlaylistType
|
||||
import com.github.libretube.extensions.TAG
|
||||
@ -23,6 +25,7 @@ import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.ui.extensions.setFormattedDuration
|
||||
import com.github.libretube.ui.extensions.setWatchProgressLength
|
||||
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
|
||||
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet.Companion.VIDEO_OPTIONS_SHEET_REQUEST_KEY
|
||||
import com.github.libretube.ui.viewholders.PlaylistViewHolder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -80,14 +83,16 @@ class PlaylistAdapter(
|
||||
NavigationHelper.navigateVideo(root.context, streamItem.url, playlistId)
|
||||
}
|
||||
val videoId = streamItem.url!!.toID()
|
||||
|
||||
val activity = (root.context as BaseActivity)
|
||||
val fragmentManager = activity.supportFragmentManager
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(streamItem) {
|
||||
fragmentManager.setFragmentResultListener(VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ ->
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
VideoOptionsBottomSheet::class.java.name
|
||||
)
|
||||
val sheet = VideoOptionsBottomSheet()
|
||||
sheet.arguments = bundleOf(IntentData.streamItem to streamItem)
|
||||
sheet.show(fragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -53,34 +53,34 @@ class PlaylistsAdapter(
|
||||
}
|
||||
|
||||
val fragmentManager = (root.context as BaseActivity).supportFragmentManager
|
||||
fragmentManager.setFragmentResultListener(
|
||||
PLAYLISTS_ADAPTER_REQUEST_KEY,
|
||||
(root.context as BaseActivity)
|
||||
) { _, resultBundle ->
|
||||
val newPlaylistDescription =
|
||||
resultBundle.getString(IntentData.playlistDescription)
|
||||
val newPlaylistName =
|
||||
resultBundle.getString(IntentData.playlistName)
|
||||
val isPlaylistToBeDeleted =
|
||||
resultBundle.getBoolean(IntentData.playlistTask)
|
||||
|
||||
newPlaylistDescription?.let {
|
||||
playlistDescription.text = it
|
||||
playlist.shortDescription = it
|
||||
}
|
||||
|
||||
newPlaylistName?.let {
|
||||
playlistTitle.text = it
|
||||
playlist.name = it
|
||||
}
|
||||
|
||||
if (isPlaylistToBeDeleted) {
|
||||
// try to refresh the playlists in the library on deletion success
|
||||
onDelete(position, root.context as BaseActivity)
|
||||
}
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
fragmentManager.setFragmentResultListener(
|
||||
PLAYLISTS_ADAPTER_REQUEST_KEY,
|
||||
(root.context as BaseActivity)
|
||||
) { _, resultBundle ->
|
||||
val newPlaylistDescription =
|
||||
resultBundle.getString(IntentData.playlistDescription)
|
||||
val newPlaylistName =
|
||||
resultBundle.getString(IntentData.playlistName)
|
||||
val isPlaylistToBeDeleted =
|
||||
resultBundle.getBoolean(IntentData.playlistTask)
|
||||
|
||||
newPlaylistDescription?.let {
|
||||
playlistDescription.text = it
|
||||
playlist.shortDescription = it
|
||||
}
|
||||
|
||||
newPlaylistName?.let {
|
||||
playlistTitle.text = it
|
||||
playlist.name = it
|
||||
}
|
||||
|
||||
if (isPlaylistToBeDeleted) {
|
||||
// try to refresh the playlists in the library on deletion success
|
||||
onDelete(position, root.context as BaseActivity)
|
||||
}
|
||||
}
|
||||
|
||||
val playlistOptionsDialog = PlaylistOptionsBottomSheet(
|
||||
playlistId = playlist.id!!,
|
||||
playlistName = playlist.name!!,
|
||||
|
@ -2,11 +2,13 @@ package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.obj.ContentItem
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.ChannelRowBinding
|
||||
import com.github.libretube.databinding.PlaylistsRowBinding
|
||||
import com.github.libretube.databinding.VideoRowBinding
|
||||
@ -96,14 +98,16 @@ class SearchAdapter(
|
||||
NavigationHelper.navigateVideo(root.context, item.url)
|
||||
}
|
||||
val videoId = item.url.toID()
|
||||
|
||||
val activity = (root.context as BaseActivity)
|
||||
val fragmentManager = activity.supportFragmentManager
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(item.toStreamItem()) {
|
||||
fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ ->
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
VideoOptionsBottomSheet::class.java.name
|
||||
)
|
||||
val sheet = VideoOptionsBottomSheet()
|
||||
sheet.arguments = bundleOf(IntentData.streamItem to item)
|
||||
sheet.show(fragmentManager, SearchAdapter::class.java.name)
|
||||
true
|
||||
}
|
||||
channelContainer.setOnClickListener {
|
||||
@ -134,8 +138,12 @@ class SearchAdapter(
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
ChannelOptionsBottomSheet(item.url.toID(), item.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager)
|
||||
val channelOptionsSheet = ChannelOptionsBottomSheet()
|
||||
channelOptionsSheet.arguments = bundleOf(
|
||||
IntentData.channelId to item.url.toID(),
|
||||
IntentData.channelName to item.name
|
||||
)
|
||||
channelOptionsSheet.show((root.context as BaseActivity).supportFragmentManager)
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,10 @@ package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.api.obj.Subscription
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.ChannelSubscriptionRowBinding
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.helpers.ImageHelper
|
||||
@ -47,8 +49,12 @@ class SubscriptionChannelAdapter(
|
||||
NavigationHelper.navigateChannel(root.context, subscription.url)
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
ChannelOptionsBottomSheet(subscription.url.toID(), subscription.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager)
|
||||
val channelOptionsSheet = ChannelOptionsBottomSheet()
|
||||
channelOptionsSheet.arguments = bundleOf(
|
||||
IntentData.channelId to subscription.url.toID(),
|
||||
IntentData.channelName to subscription.name
|
||||
)
|
||||
channelOptionsSheet.show((root.context as BaseActivity).supportFragmentManager)
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
@ -13,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.LayoutManager
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.AllCaughtUpRowBinding
|
||||
import com.github.libretube.databinding.TrendingRowBinding
|
||||
@ -103,9 +105,7 @@ class VideosAdapter(
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBindViewHolder(holder: VideosViewHolder, position: Int) {
|
||||
val video = streamItems[position]
|
||||
|
||||
val videoId = video.url?.toID()
|
||||
val videoName = video.title
|
||||
|
||||
videoId?.let {
|
||||
(holder.trendingRowBinding?.watchProgress ?: holder.videoRowBinding!!.watchProgress)
|
||||
@ -116,6 +116,9 @@ class VideosAdapter(
|
||||
holder.videoRowBinding ?: holder.trendingRowBinding
|
||||
?: holder.allCaughtUpBinding
|
||||
)!!.root.context
|
||||
val activity = (context as BaseActivity)
|
||||
val fragmentManager = activity.supportFragmentManager
|
||||
|
||||
val uploadDate =
|
||||
video.uploaded?.takeIf { it > 0 }?.let { TextUtils.formatRelativeDate(context, it) }
|
||||
|
||||
@ -146,17 +149,14 @@ class VideosAdapter(
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigateVideo(root.context, video.url)
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
if (videoId == null || videoName == null) return@setOnLongClickListener true
|
||||
|
||||
VideoOptionsBottomSheet(video) {
|
||||
root.setOnLongClickListener {
|
||||
fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ ->
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
VideoOptionsBottomSheet::class.java.name
|
||||
)
|
||||
|
||||
val sheet = VideoOptionsBottomSheet()
|
||||
sheet.arguments = bundleOf(IntentData.streamItem to video)
|
||||
sheet.show(fragmentManager, VideosAdapter::class.java.name)
|
||||
true
|
||||
}
|
||||
}
|
||||
@ -191,14 +191,12 @@ class VideosAdapter(
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
if (videoId == null || videoName == null) return@setOnLongClickListener true
|
||||
VideoOptionsBottomSheet(video) {
|
||||
fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ ->
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
VideoOptionsBottomSheet::class.java.name
|
||||
)
|
||||
val sheet = VideoOptionsBottomSheet()
|
||||
sheet.arguments = bundleOf(IntentData.streamItem to video)
|
||||
sheet.show(fragmentManager, VideosAdapter::class.java.name)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.VideoRowBinding
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.db.obj.WatchHistoryItem
|
||||
@ -67,14 +69,16 @@ class WatchHistoryAdapter(
|
||||
root.setOnClickListener {
|
||||
NavigationHelper.navigateVideo(root.context, video.videoId)
|
||||
}
|
||||
|
||||
val activity = (root.context as BaseActivity)
|
||||
val fragmentManager = activity.supportFragmentManager
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(video.toStreamItem()) {
|
||||
fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ ->
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
VideoOptionsBottomSheet::class.java.name
|
||||
)
|
||||
val sheet = VideoOptionsBottomSheet()
|
||||
sheet.arguments = bundleOf(IntentData.streamItem to video)
|
||||
sheet.show(fragmentManager, WatchHistoryAdapter::class.java.name)
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -397,9 +397,8 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
|
||||
override fun onLongTap() {
|
||||
val current = PlayingQueue.getCurrent() ?: return
|
||||
VideoOptionsBottomSheet(
|
||||
current
|
||||
)
|
||||
VideoOptionsBottomSheet()
|
||||
.apply { arguments = bundleOf(IntentData.shareData to current) }
|
||||
.show(childFragmentManager)
|
||||
}
|
||||
|
||||
|
@ -21,14 +21,16 @@ import kotlinx.coroutines.withContext
|
||||
*
|
||||
* Needs the [channelId] to load the content from the right video.
|
||||
*/
|
||||
class ChannelOptionsBottomSheet(
|
||||
private val channelId: String,
|
||||
channelName: String?
|
||||
) : BaseBottomSheet() {
|
||||
private val shareData = ShareData(currentChannel = channelName)
|
||||
class ChannelOptionsBottomSheet : BaseBottomSheet() {
|
||||
private lateinit var channelId: String
|
||||
private var channelName: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
channelId = arguments?.getString(IntentData.channelId)!!
|
||||
channelName = arguments?.getString(IntentData.channelName)
|
||||
|
||||
// List that stores the different menu options. In the future could be add more options here.
|
||||
val optionsList = mutableListOf(
|
||||
getString(R.string.share),
|
||||
@ -42,7 +44,7 @@ class ChannelOptionsBottomSheet(
|
||||
val bundle = bundleOf(
|
||||
IntentData.id to channelId,
|
||||
IntentData.shareObjectType to ShareObjectType.CHANNEL,
|
||||
IntentData.shareData to shareData
|
||||
IntentData.shareData to ShareData(currentChannel = channelName)
|
||||
)
|
||||
val newShareDialog = ShareDialog()
|
||||
newShareDialog.arguments = bundle
|
||||
|
@ -40,9 +40,7 @@ class StatsSheet(
|
||||
)
|
||||
binding.audioInfo.setText(
|
||||
"${player.audioFormat?.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(
|
||||
player.audioFormat?.bitrate
|
||||
)
|
||||
TextUtils.formatBitrate(player.audioFormat?.bitrate)
|
||||
}"
|
||||
)
|
||||
binding.videoQuality.setText(
|
||||
|
@ -2,6 +2,7 @@ package com.github.libretube.ui.sheets
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
@ -11,6 +12,7 @@ import com.github.libretube.db.DatabaseHelper
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
import com.github.libretube.db.obj.WatchPosition
|
||||
import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.parcelable
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.helpers.BackgroundHelper
|
||||
import com.github.libretube.helpers.NavigationHelper
|
||||
@ -32,12 +34,12 @@ import kotlinx.coroutines.withContext
|
||||
*
|
||||
* Needs the [streamItem] to load the content from the right video.
|
||||
*/
|
||||
class VideoOptionsBottomSheet(
|
||||
private val streamItem: StreamItem,
|
||||
private val onVideoChanged: () -> Unit = {}
|
||||
) : BaseBottomSheet() {
|
||||
private val shareData = ShareData(currentVideo = streamItem.title)
|
||||
class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
private lateinit var streamItem: StreamItem
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
streamItem = arguments?.parcelable(IntentData.streamItem)!!
|
||||
|
||||
val videoId = streamItem.url?.toID() ?: return
|
||||
// List that stores the different menu options. In the future could be add more options here.
|
||||
val optionsList = mutableListOf(
|
||||
@ -64,7 +66,7 @@ class VideoOptionsBottomSheet(
|
||||
|
||||
if (streamItem.duration == null ||
|
||||
watchPositionEntry == null ||
|
||||
watchPositionEntry.position < streamItem.duration * 1000 * 0.9
|
||||
watchPositionEntry.position < streamItem.duration!! * 1000 * 0.9
|
||||
) {
|
||||
optionsList += getString(R.string.mark_as_watched)
|
||||
}
|
||||
@ -101,7 +103,7 @@ class VideoOptionsBottomSheet(
|
||||
val bundle = bundleOf(
|
||||
IntentData.id to videoId,
|
||||
IntentData.shareObjectType to ShareObjectType.VIDEO,
|
||||
IntentData.shareData to shareData
|
||||
IntentData.shareData to ShareData(currentVideo = streamItem.title)
|
||||
)
|
||||
val newShareDialog = ShareDialog()
|
||||
newShareDialog.arguments = bundle
|
||||
@ -134,7 +136,7 @@ class VideoOptionsBottomSheet(
|
||||
?.firstOrNull() as? SubscriptionsFragment
|
||||
fragment?.feedAdapter?.removeItemById(videoId)
|
||||
}
|
||||
onVideoChanged()
|
||||
setFragmentResult(VIDEO_OPTIONS_SHEET_REQUEST_KEY, bundleOf())
|
||||
}
|
||||
|
||||
getString(R.string.mark_as_unwatched) -> {
|
||||
@ -142,11 +144,15 @@ class VideoOptionsBottomSheet(
|
||||
DatabaseHolder.Database.watchPositionDao().deleteByVideoId(videoId)
|
||||
DatabaseHolder.Database.watchHistoryDao().deleteByVideoId(videoId)
|
||||
}
|
||||
onVideoChanged()
|
||||
setFragmentResult(VIDEO_OPTIONS_SHEET_REQUEST_KEY, bundleOf())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VIDEO_OPTIONS_SHEET_REQUEST_KEY = "video_options_sheet_request_key"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user