Skip to content

Commit

Permalink
For mozilla-mobile#3194 - Pause media while undo snackbar appears
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager committed Apr 14, 2020
1 parent eace991 commit 664c08a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.menu.view.MenuButton
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.state.state.MediaState.State.PLAYING
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.feature.media.ext.pauseIfPlaying
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.lib.state.ext.flowScoped
Expand Down Expand Up @@ -411,6 +413,11 @@ class HomeFragment : Fragment() {

private fun closeTab(sessionId: String) {
val deletionJob = pendingSessionDeletion?.deletionJob
context?.let {
if (sessionManager.findSessionById(sessionId)?.toTab(it)?.mediaState == PLAYING) {
requireComponents.core.store.state.media.pauseIfPlaying()
}
}

if (deletionJob == null) {
removeTabWithUndo(sessionId, browsingModeManager.mode.isPrivate)
Expand All @@ -427,6 +434,14 @@ class HomeFragment : Fragment() {
private fun closeAllTabs(isPrivateMode: Boolean) {
val deletionJob = pendingSessionDeletion?.deletionJob

context?.let {
sessionManager.sessionsOfType(private = isPrivateMode).forEach { session ->
if (session.toTab(it).mediaState == PLAYING) {
it.components.core.store.state.media.pauseIfPlaying()
}
}
}

if (deletionJob == null) {
removeAllTabsWithUndo(
sessionManager.sessionsOfType(private = isPrivateMode),
Expand Down

0 comments on commit 664c08a

Please sign in to comment.