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 08a00e62a..a942b9204 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 @@ -53,7 +53,7 @@ class MainActivity : BaseActivity() { val autoRotationEnabled = PreferenceHelper.getBoolean(PreferenceKeys.AUTO_ROTATION, false) lateinit var searchView: SearchView - lateinit var searchItem: MenuItem + private lateinit var searchItem: MenuItem override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -131,9 +131,20 @@ class MainActivity : BaseActivity() { setupSubscriptionsBadge() + val playerViewModel = ViewModelProvider(this)[PlayerViewModel::class.java] + // new way of handling back presses onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { + if (playerViewModel.isFullscreen.value == true) { + for (fragment in supportFragmentManager.fragments) { + if (fragment is PlayerFragment) { + fragment.unsetFullscreen() + return + } + } + } + if (binding.mainMotionLayout.progress == 0F) { try { minimizePlayer() diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 9730a0244..0eab64d17 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -432,7 +432,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { } @SuppressLint("SourceLockedOrientationActivity") - private fun unsetFullscreen() { + fun unsetFullscreen() { // leave fullscreen mode with(binding.playerMotionLayout) { getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)