Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: android back button doesn't work due to dependency upgrade #5653

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/StartupTheme"
tools:targetApi="n">
android:enableOnBackInvokedCallback="true"
tools:targetApi="tiramisu">

<activity
android:name=".ui.activities.WelcomeActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class MainActivity : BaseActivity() {

setupSubscriptionsBadge()

// new way of handling back presses
onBackPressedDispatcher.addCallback {
if (playerViewModel.isFullscreen.value == true) {
runOnPlayerFragment { unsetFullscreen() }
val fullscreenUnsetSuccess = runOnPlayerFragment { unsetFullscreen() }
if (fullscreenUnsetSuccess) return@addCallback
}

if (binding.mainMotionLayout.progress == 0F) {
Expand Down Expand Up @@ -497,12 +497,19 @@ class MainActivity : BaseActivity() {
}

override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
return runOnPlayerFragment { onKeyUp(keyCode, event) } ?: false
return runOnPlayerFragment { onKeyUp(keyCode, event) }
}

private fun <T> runOnPlayerFragment(action: PlayerFragment.() -> T): T? {
return supportFragmentManager.fragments.filterIsInstance<PlayerFragment>()
/**
* Attempt to run code on the player fragment if running
* Returns true if a running player fragment was found and the action got consumed, else false
*/
private fun runOnPlayerFragment(action: PlayerFragment.() -> Unit): Boolean {
supportFragmentManager.fragments.filterIsInstance<PlayerFragment>()
.firstOrNull()
?.let(action)
?.run { return true }

return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class BaseActivity : AppCompatActivity() {
}

/**
* Rotate according to the preference
* Rotate the screen according to the app orientation preference
*/
fun requestOrientationChange() {
requestedOrientation = screenOrientationPref
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.marginStart
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.commit
import androidx.media3.common.C
import androidx.media3.common.Player
import androidx.media3.common.text.Cue
Expand Down
Loading