diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt index 4c3376bb..1e2ea540 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt @@ -6,6 +6,7 @@ import android.net.Uri import android.os.Bundle import android.util.Log import android.view.KeyEvent +import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import com.lagradost.cloudstream3.CommonActivity import com.lagradost.cloudstream3.R @@ -34,10 +35,6 @@ class DownloadedPlayerActivity : AppCompatActivity() { CommonActivity.onUserLeaveHint(this) } - override fun onBackPressed() { - finish() - } - private fun playLink(url: String) { this.navigate( R.id.global_to_navigation_player, GeneratorPlayer.newInstance( @@ -109,6 +106,15 @@ class DownloadedPlayerActivity : AppCompatActivity() { finish() return } + + onBackPressedDispatcher.addCallback( + this, + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + finish() + } + } + ) } override fun onResume() { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt index c30e70e5..baa9fbf2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultTrailerPlayer.kt @@ -7,6 +7,7 @@ import android.os.Bundle import android.view.View import android.view.ViewGroup import android.widget.FrameLayout +import androidx.activity.OnBackPressedCallback import androidx.core.view.isGone import androidx.core.view.isVisible import com.lagradost.cloudstream3.CommonActivity.screenHeight @@ -15,10 +16,8 @@ import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.ui.player.CSPlayerEvent import com.lagradost.cloudstream3.ui.player.PlayerEventSource import com.lagradost.cloudstream3.ui.player.SubtitleData -import com.lagradost.cloudstream3.utils.IOnBackPressed - -open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed { +open class ResultTrailerPlayer : ResultFragmentPhone() { override var lockRotation = false override var isFullScreenPlayer = false @@ -28,7 +27,7 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed { const val TAG = "RESULT_TRAILER" } - var playerWidthHeight: Pair? = null + private var playerWidthHeight: Pair? = null override fun nextEpisode() {} @@ -154,6 +153,10 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed { } fixPlayerSize() uiReset() + + if (isFullScreenPlayer) { + attachBackPressedCallback() + } else detachBackPressedCallback() } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -172,12 +175,22 @@ open class ResultTrailerPlayer : ResultFragmentPhone(), IOnBackPressed { } } - override fun onBackPressed(): Boolean { - return if (isFullScreenPlayer) { - updateFullscreen(false) - false - } else { - true + private var backPressedCallback: OnBackPressedCallback? = null + + private fun attachBackPressedCallback() { + if (backPressedCallback == null) { + backPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + updateFullscreen(false) + } + } } + + backPressedCallback?.isEnabled = true + requireActivity().onBackPressedDispatcher.addCallback(requireActivity(), backPressedCallback!!) + } + + private fun detachBackPressedCallback() { + backPressedCallback?.isEnabled = false } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/IOnBackPressed.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/IOnBackPressed.kt deleted file mode 100644 index b4922945..00000000 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/IOnBackPressed.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.lagradost.cloudstream3.utils - -interface IOnBackPressed { - fun onBackPressed(): Boolean -} \ No newline at end of file