From 824f3fd82138b2e93dcfeddcf6310f7878e1de2d Mon Sep 17 00:00:00 2001 From: Jonathan Almeida Date: Mon, 1 Feb 2021 14:52:56 +0400 Subject: [PATCH] Issue #1340: Forward Activity results to the fragment --- app/src/main/java/org/mozilla/fenix/HomeActivity.kt | 10 ++++++++++ .../org/mozilla/fenix/browser/BaseBrowserFragment.kt | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 64cfb77401..c39d42e6d8 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -52,6 +52,7 @@ import mozilla.components.feature.privatemode.notification.PrivateNotificationFe import mozilla.components.feature.search.BrowserStoreSearchAdapter import mozilla.components.feature.search.ext.legacy import mozilla.components.service.fxa.sync.SyncReason +import mozilla.components.support.base.feature.ActivityResultHandler import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.ktx.android.arch.lifecycle.addObservers import mozilla.components.support.ktx.android.content.call @@ -536,6 +537,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { super.onBackPressed() } + final override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + supportFragmentManager.primaryNavigationFragment?.childFragmentManager?.fragments?.forEach { + if (it is ActivityResultHandler && it.onActivityResult(requestCode, data, resultCode)) { + return + } + } + super.onActivityResult(requestCode, resultCode, data) + } + private fun shouldUseCustomBackLongPress(): Boolean { val isAndroidN = Build.VERSION.SDK_INT == Build.VERSION_CODES.N || Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 869be62a97..7aa83991e2 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -128,6 +128,7 @@ import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration import java.lang.ref.WeakReference import mozilla.components.feature.media.fullscreen.MediaFullscreenOrientationFeature import mozilla.components.feature.webauthn.WebAuthnFeature +import mozilla.components.support.base.feature.ActivityResultHandler import org.mozilla.fenix.FeatureFlags.newMediaSessionApi /** @@ -137,7 +138,7 @@ import org.mozilla.fenix.FeatureFlags.newMediaSessionApi */ @ExperimentalCoroutinesApi @Suppress("TooManyFunctions", "LargeClass") -abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, +abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, ActivityResultHandler, OnBackLongPressedListener, AccessibilityManager.AccessibilityStateChangeListener { private lateinit var browserFragmentStore: BrowserFragmentStore @@ -1037,10 +1038,10 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, } /** - * Forwards activity results to the prompt feature. + * Forwards activity results to the [ActivityResultHandler] features. */ - final override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - listOf( + override fun onActivityResult(requestCode: Int, data: Intent?, resultCode: Int): Boolean { + return listOf( promptsFeature, webAuthnFeature ).any { it.onActivityResult(requestCode, data, resultCode) }