fix: can't open playlists

This commit is contained in:
Bnyro 2024-01-06 14:19:17 +01:00
parent 9c2abeeca1
commit 3661cd82f7
11 changed files with 26 additions and 26 deletions

View File

@ -26,11 +26,11 @@ import com.github.libretube.ui.views.SingleViewTouchableMotionLayout
object NavigationHelper {
private val handler = Handler(Looper.getMainLooper())
fun navigateChannel(context: Context, channelId: String?) {
if (channelId == null) return
fun navigateChannel(context: Context, channelUrlOrId: String?) {
if (channelUrlOrId == null) return
val activity = ContextHelper.unwrapActivity(context)
activity.navController.navigate(NavDirections.openChannel(channelId))
activity.navController.navigate(NavDirections.openChannel(channelUrlOrId.toID()))
try {
if (activity.binding.mainMotionLayout.progress == 0.toFloat()) {
activity.binding.mainMotionLayout.transitionToEnd()
@ -48,20 +48,20 @@ object NavigationHelper {
*/
fun navigateVideo(
context: Context,
videoId: String?,
videoUrlOrId: String?,
playlistId: String? = null,
channelId: String? = null,
keepQueue: Boolean = false,
timestamp: Long = 0,
forceVideo: Boolean = false
) {
if (videoId == null) return
if (videoUrlOrId == null) return
BackgroundHelper.stopBackgroundPlay(context)
if (PreferenceHelper.getBoolean(PreferenceKeys.AUDIO_ONLY_MODE, false) && !forceVideo) {
BackgroundHelper.playOnBackground(
context,
videoId.toID(),
videoUrlOrId.toID(),
timestamp,
playlistId,
channelId,
@ -73,7 +73,7 @@ object NavigationHelper {
return
}
val playerData = PlayerData(videoId.toID(), playlistId, channelId, keepQueue, timestamp)
val playerData = PlayerData(videoUrlOrId.toID(), playlistId, channelId, keepQueue, timestamp)
val bundle = bundleOf(IntentData.playerData to playerData)
val activity = ContextHelper.unwrapActivity(context)
@ -82,11 +82,11 @@ object NavigationHelper {
}
}
fun navigatePlaylist(context: Context, playlistId: String?, playlistType: PlaylistType) {
if (playlistId == null) return
fun navigatePlaylist(context: Context, playlistUrlOrId: String?, playlistType: PlaylistType) {
if (playlistUrlOrId == null) return
val activity = ContextHelper.unwrapActivity(context)
activity.navController.navigate(NavDirections.openPlaylist(playlistId, playlistType))
activity.navController.navigate(NavDirections.openPlaylist(playlistUrlOrId.toID(), playlistType))
}
/**

View File

@ -415,7 +415,7 @@ class MainActivity : BaseActivity() {
intent?.getStringExtra(IntentData.videoId)?.let {
NavigationHelper.navigateVideo(
context = this,
videoId = it,
videoUrlOrId = it,
timestamp = intent.getLongExtra(IntentData.timeStamp, 0L)
)
}

View File

@ -22,6 +22,7 @@ import com.github.libretube.api.obj.Comment
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.CommentsRowBinding
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID
import com.github.libretube.helpers.ClipboardHelper
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.NavigationHelper

View File

@ -35,10 +35,7 @@ class LegacySubscriptionAdapter(
channelAvatar
)
root.setOnClickListener {
NavigationHelper.navigateChannel(
root.context,
subscription.url.toID()
)
NavigationHelper.navigateChannel(root.context, subscription.url)
}
root.setOnLongClickListener {

View File

@ -105,7 +105,7 @@ class PlaylistAdapter(
if (!streamItem.uploaderUrl.isNullOrBlank()) {
videoInfo.setOnClickListener {
NavigationHelper.navigateChannel(root.context, streamItem.uploaderUrl.toID())
NavigationHelper.navigateChannel(root.context, streamItem.uploaderUrl)
}
// add some extra padding to make it easier to click
val extraPadding = 3f.dpToPx()

View File

@ -29,13 +29,14 @@ class SubscriptionGroupChannelsAdapter(
override fun onBindViewHolder(holder: SubscriptionGroupChannelRowViewHolder, position: Int) {
val channel = channels[position]
val channelId = channel.url.toID()
holder.binding.apply {
root.setOnClickListener {
NavigationHelper.navigateChannel(root.context, channelId)
NavigationHelper.navigateChannel(root.context, channel.url)
}
subscriptionChannelName.text = channel.name
ImageHelper.loadImage(channel.avatar, subscriptionChannelImage)
val channelId = channel.url.toID()
channelIncluded.setOnCheckedChangeListener(null)
channelIncluded.isChecked = group.channels.contains(channelId)
channelIncluded.setOnCheckedChangeListener { _, isChecked ->

View File

@ -163,7 +163,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
killFragment()
NavigationHelper.navigateVideo(
context = requireContext(),
videoId = PlayingQueue.getCurrent()?.url?.toID(),
videoUrlOrId = PlayingQueue.getCurrent()?.url,
timestamp = playerService?.player?.currentPosition?.div(1000) ?: 0,
keepQueue = true,
forceVideo = true

View File

@ -61,8 +61,10 @@ class ChannelFragment : DynamicLayoutManagerFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
channelId = args.channelId?.toID()
channelName = args.channelName?.replace("/c/", "")?.replace("/user/", "")
channelName = args.channelName
?.replace("/c/", "")
?.replace("/user/", "")
channelId = args.channelId
}
override fun onCreateView(

View File

@ -200,7 +200,7 @@ class PlaylistFragment : DynamicLayoutManagerFragment() {
if (playlistFeed.isEmpty()) return@setOnClickListener
NavigationHelper.navigateVideo(
requireContext(),
response.relatedStreams.first().url?.toID(),
response.relatedStreams.first().url,
playlistId
)
}
@ -230,7 +230,7 @@ class PlaylistFragment : DynamicLayoutManagerFragment() {
PlayingQueue.add(*queue.toTypedArray())
NavigationHelper.navigateVideo(
requireContext(),
queue.first().url?.toID(),
queue.first().url,
playlistId = playlistId,
keepQueue = true
)

View File

@ -212,8 +212,7 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
PlayingQueue.clear()
PlayingQueue.add(*streams.toTypedArray())
val videoId = streams.first().url.orEmpty().toID()
NavigationHelper.navigateVideo(requireContext(), videoId = videoId, keepQueue = true)
NavigationHelper.navigateVideo(requireContext(), videoUrlOrId = streams.first().url, keepQueue = true)
}
@SuppressLint("InflateParams")

View File

@ -34,7 +34,7 @@ class DownloadOptionsBottomSheet : BaseBottomSheet() {
}
R.string.go_to_video -> {
NavigationHelper.navigateVideo(requireContext(), videoId = videoId)
NavigationHelper.navigateVideo(requireContext(), videoUrlOrId = videoId)
}
R.string.share -> {