finish fullscreen on backpress

This commit is contained in:
Bnyro 2022-11-26 08:33:30 +01:00
parent 852a3311b3
commit 187f96bc49
2 changed files with 13 additions and 2 deletions

View File

@ -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()

View File

@ -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)