Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: can't open playlists #5449

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class LegacySubscriptionAdapter(
channelAvatar
)
root.setOnClickListener {
NavigationHelper.navigateChannel(
root.context,
subscription.url.toID()
)
NavigationHelper.navigateChannel(root.context, subscription.url)
}

root.setOnLongClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Loading