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.core.os.bundleOf
|
|
|
|
import com.github.libretube.R
|
2022-09-20 23:23:34 +05:30
|
|
|
import com.github.libretube.ui.activities.MainActivity
|
2022-09-08 23:49:44 +05:30
|
|
|
import com.github.libretube.constants.IntentData
|
2022-08-27 18:43:24 +05:30
|
|
|
import com.github.libretube.extensions.toID
|
2022-09-20 23:23:34 +05:30
|
|
|
import com.github.libretube.ui.fragments.PlayerFragment
|
2022-07-20 01:01:56 +05:30
|
|
|
|
|
|
|
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
|
2022-09-08 23:49:44 +05:30
|
|
|
val bundle = bundleOf(IntentData.channelId to channelId)
|
2022-07-20 01:01:56 +05:30
|
|
|
activity.navController.navigate(R.id.channelFragment, bundle)
|
|
|
|
try {
|
2022-09-20 20:21:38 +05:30
|
|
|
if (activity.binding.mainMotionLayout.progress == 0.toFloat()) {
|
|
|
|
activity.binding.mainMotionLayout.transitionToEnd()
|
|
|
|
activity.supportFragmentManager.fragments.forEach {
|
|
|
|
(it as PlayerFragment?)?.binding?.playerMotionLayout?.transitionToEnd()
|
|
|
|
}
|
2022-07-20 01:01:56 +05:30
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
2022-09-20 20:21:38 +05:30
|
|
|
e.printStackTrace()
|
2022-07-20 01:01:56 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-08 23:49:44 +05:30
|
|
|
bundle.putString(IntentData.videoId, videoId.toID())
|
|
|
|
if (playlistId != null) bundle.putString(IntentData.playlistId, playlistId)
|
2022-07-20 01:01:56 +05:30
|
|
|
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()
|
2022-09-08 23:49:44 +05:30
|
|
|
bundle.putString(IntentData.playlistId, playlistId)
|
2022-08-08 18:52:08 +05:30
|
|
|
bundle.putBoolean("isOwner", isOwner)
|
2022-07-20 01:01:56 +05:30
|
|
|
activity.navController.navigate(R.id.playlistFragment, bundle)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|