diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index efa76e346..3a1ecf382 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -84,6 +84,7 @@ import org.mozilla.fenix.theme.DefaultThemeManager import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.utils.BrowsersCache import org.mozilla.fenix.utils.RunWhenReadyQueue +import org.mozilla.fenix.home.intent.OpenSpecificTabIntentProcessor /** * The main activity of the application. The application is primarily a single Activity (this one) @@ -119,7 +120,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { SpeechProcessingIntentProcessor(this, components.analytics.metrics), StartSearchIntentProcessor(components.analytics.metrics), DeepLinkIntentProcessor(this), - OpenBrowserIntentProcessor(this, ::getIntentSessionId) + OpenBrowserIntentProcessor(this, ::getIntentSessionId), + OpenSpecificTabIntentProcessor(this) ) } diff --git a/app/src/main/java/org/mozilla/fenix/home/intent/OpenSpecificTabIntentProcessor.kt b/app/src/main/java/org/mozilla/fenix/home/intent/OpenSpecificTabIntentProcessor.kt new file mode 100644 index 000000000..618274272 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/home/intent/OpenSpecificTabIntentProcessor.kt @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.home.intent + +import android.content.Intent +import androidx.navigation.NavController +import mozilla.components.feature.media.service.AbstractMediaService +import org.mozilla.fenix.BrowserDirection +import org.mozilla.fenix.HomeActivity +import org.mozilla.fenix.ext.components + +/** + * When the media notification is clicked we need to switch to the tab where the audio/video is + * playing. This intent has the following informations: + * action - [AbstractMediaService.Companion.ACTION_SWITCH_TAB] + * extra string for the tab id - [AbstractMediaService.Companion.EXTRA_TAB_ID] + */ +class OpenSpecificTabIntentProcessor( + private val activity: HomeActivity +) : HomeIntentProcessor { + + override fun process(intent: Intent, navController: NavController, out: Intent): Boolean { + if (intent.action == AbstractMediaService.Companion.ACTION_SWITCH_TAB) { + val sessionManager = activity.components.core.sessionManager + val sessionId = intent.extras?.getString(AbstractMediaService.Companion.EXTRA_TAB_ID) + val session = sessionId?.let { sessionManager.findSessionById(it) } + if (session != null) { + sessionManager.select(session) + activity.openToBrowser(BrowserDirection.FromGlobal) + return true + } + } + + return false + } +}