fix the abnormal channel behavior

This commit is contained in:
Bnyro 2022-10-05 21:47:09 +02:00
parent 977acaefbf
commit a3a87780ad

View File

@ -12,26 +12,26 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.ui.activities.MainActivity import com.github.libretube.ui.activities.MainActivity
import com.github.libretube.ui.fragments.PlayerFragment import com.github.libretube.ui.fragments.PlayerFragment
import com.github.libretube.ui.views.SingleViewTouchableMotionLayout
object NavigationHelper { object NavigationHelper {
fun navigateChannel( fun navigateChannel(
context: Context, context: Context,
channelId: String? channelId: String?
) { ) {
if (channelId != null) { if (channelId == null) return
val activity = context as MainActivity
val bundle = bundleOf(IntentData.channelId to channelId) val activity = context as MainActivity
activity.navController.navigate(R.id.channelFragment, bundle) val bundle = bundleOf(IntentData.channelId to channelId)
try { activity.navController.navigate(R.id.channelFragment, bundle)
if (activity.binding.mainMotionLayout.progress == 0.toFloat()) { try {
activity.binding.mainMotionLayout.transitionToEnd() if (activity.binding.mainMotionLayout.progress == 0.toFloat()) {
activity.supportFragmentManager.fragments.forEach { activity.binding.mainMotionLayout.transitionToEnd()
(it as PlayerFragment?)?.binding?.playerMotionLayout?.transitionToEnd() activity.findViewById<SingleViewTouchableMotionLayout>(R.id.playerMotionLayout)
} .transitionToEnd()
}
} catch (e: Exception) {
e.printStackTrace()
} }
} catch (e: Exception) {
e.printStackTrace()
} }
} }
@ -40,20 +40,20 @@ object NavigationHelper {
videoId: String?, videoId: String?,
playlistId: String? = null playlistId: String? = null
) { ) {
if (videoId != null) { if (videoId == null) return
val bundle = Bundle()
bundle.putString(IntentData.videoId, videoId.toID()) val bundle = Bundle()
if (playlistId != null) bundle.putString(IntentData.playlistId, playlistId) bundle.putString(IntentData.videoId, videoId.toID())
val frag = PlayerFragment() if (playlistId != null) bundle.putString(IntentData.playlistId, playlistId)
frag.arguments = bundle val frag = PlayerFragment()
val activity = context as AppCompatActivity frag.arguments = bundle
activity.supportFragmentManager.beginTransaction() val activity = context as AppCompatActivity
.remove(PlayerFragment()) activity.supportFragmentManager.beginTransaction()
.commit() .remove(PlayerFragment())
activity.supportFragmentManager.beginTransaction() .commit()
.replace(R.id.container, frag) activity.supportFragmentManager.beginTransaction()
.commitNow() .replace(R.id.container, frag)
} .commitNow()
} }
fun navigatePlaylist( fun navigatePlaylist(
@ -61,13 +61,13 @@ object NavigationHelper {
playlistId: String?, playlistId: String?,
isOwner: Boolean isOwner: Boolean
) { ) {
if (playlistId != null) { if (playlistId == null) return
val activity = context as MainActivity
val bundle = Bundle() val activity = context as MainActivity
bundle.putString(IntentData.playlistId, playlistId) val bundle = Bundle()
bundle.putBoolean("isOwner", isOwner) bundle.putString(IntentData.playlistId, playlistId)
activity.navController.navigate(R.id.playlistFragment, bundle) bundle.putBoolean("isOwner", isOwner)
} activity.navController.navigate(R.id.playlistFragment, bundle)
} }
/** /**