From 3661cd82f78b2e4cdf7eb5eebd8058df036ad6df Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 6 Jan 2024 14:19:17 +0100 Subject: [PATCH] fix: can't open playlists --- .../libretube/helpers/NavigationHelper.kt | 20 +++++++++---------- .../libretube/ui/activities/MainActivity.kt | 2 +- .../libretube/ui/adapters/CommentsAdapter.kt | 1 + .../ui/adapters/LegacySubscriptionAdapter.kt | 5 +---- .../libretube/ui/adapters/PlaylistAdapter.kt | 2 +- .../SubscriptionGroupChannelsAdapter.kt | 5 +++-- .../ui/fragments/AudioPlayerFragment.kt | 2 +- .../libretube/ui/fragments/ChannelFragment.kt | 6 ++++-- .../ui/fragments/PlaylistFragment.kt | 4 ++-- .../ui/fragments/SubscriptionsFragment.kt | 3 +-- .../ui/sheets/DownloadOptionsBottomSheet.kt | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt index 4dad886f26..092c71bfbd 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt @@ -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)) } /** diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index 4cb74fda1b..189140d528 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -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) ) } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index cf1c05c62e..a962f269a2 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt index 078d91fc24..e67e461e75 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/LegacySubscriptionAdapter.kt @@ -35,10 +35,7 @@ class LegacySubscriptionAdapter( channelAvatar ) root.setOnClickListener { - NavigationHelper.navigateChannel( - root.context, - subscription.url.toID() - ) + NavigationHelper.navigateChannel(root.context, subscription.url) } root.setOnLongClickListener { diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt index 82ef6d0aed..3c3d9eac3f 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt @@ -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() diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupChannelsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupChannelsAdapter.kt index 8757c42f16..6f0c30a99d 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupChannelsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SubscriptionGroupChannelsAdapter.kt @@ -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 -> diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index 4b0e452ae0..d171e02229 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -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 diff --git a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt index d3d23a46a1..c7c9aa3e42 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt @@ -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( diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index cffaafa047..5cc1ee13b9 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -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 ) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index 3b51e92cef..b8dffb044b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -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") diff --git a/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt index 4038e98afe..3294a747ba 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt @@ -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 -> {