2022-07-20 01:01:56 +05:30
|
|
|
package com.github.libretube.util
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
|
|
|
import androidx.core.os.bundleOf
|
|
|
|
import com.github.libretube.R
|
|
|
|
import com.github.libretube.activities.MainActivity
|
|
|
|
import com.github.libretube.fragments.PlayerFragment
|
|
|
|
|
|
|
|
object NavigationHelper {
|
2022-08-08 18:52:08 +05:30
|
|
|
fun navigateChannel(
|
|
|
|
context: Context,
|
|
|
|
channelId: String?
|
|
|
|
) {
|
2022-07-20 01:01:56 +05:30
|
|
|
if (channelId != null) {
|
|
|
|
val activity = context as MainActivity
|
|
|
|
val bundle = bundleOf("channel_id" to channelId)
|
|
|
|
activity.navController.navigate(R.id.channelFragment, bundle)
|
|
|
|
try {
|
|
|
|
val mainMotionLayout =
|
|
|
|
activity.findViewById<MotionLayout>(R.id.mainMotionLayout)
|
|
|
|
if (mainMotionLayout.progress == 0.toFloat()) {
|
|
|
|
mainMotionLayout.transitionToEnd()
|
|
|
|
activity.findViewById<MotionLayout>(R.id.playerMotionLayout)
|
|
|
|
.transitionToEnd()
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:52:08 +05:30
|
|
|
fun navigateVideo(
|
|
|
|
context: Context,
|
|
|
|
videoId: String?,
|
|
|
|
playlistId: String? = null
|
|
|
|
) {
|
2022-07-20 01:01:56 +05:30
|
|
|
if (videoId != null) {
|
|
|
|
val bundle = Bundle()
|
2022-07-29 12:30:13 +05:30
|
|
|
bundle.putString("videoId", videoId.toID())
|
2022-07-20 01:01:56 +05:30
|
|
|
if (playlistId != null) bundle.putString("playlistId", playlistId)
|
|
|
|
val frag = PlayerFragment()
|
|
|
|
frag.arguments = bundle
|
|
|
|
val activity = context as AppCompatActivity
|
|
|
|
activity.supportFragmentManager.beginTransaction()
|
|
|
|
.remove(PlayerFragment())
|
|
|
|
.commit()
|
|
|
|
activity.supportFragmentManager.beginTransaction()
|
|
|
|
.replace(R.id.container, frag)
|
|
|
|
.commitNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:52:08 +05:30
|
|
|
fun navigatePlaylist(
|
|
|
|
context: Context,
|
|
|
|
playlistId: String?,
|
|
|
|
isOwner: Boolean
|
|
|
|
) {
|
2022-07-20 01:01:56 +05:30
|
|
|
if (playlistId != null) {
|
|
|
|
val activity = context as MainActivity
|
2022-08-08 18:52:08 +05:30
|
|
|
val bundle = Bundle()
|
|
|
|
bundle.putString("playlist_id", playlistId)
|
|
|
|
bundle.putBoolean("isOwner", isOwner)
|
2022-07-20 01:01:56 +05:30
|
|
|
activity.navController.navigate(R.id.playlistFragment, bundle)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|