2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

Issue #1340: Forward Activity results to the fragment

This commit is contained in:
Jonathan Almeida 2021-02-01 14:52:56 +04:00 committed by Jonathan Almeida
parent 06c1734aa5
commit 824f3fd821
2 changed files with 15 additions and 4 deletions

View File

@ -52,6 +52,7 @@ import mozilla.components.feature.privatemode.notification.PrivateNotificationFe
import mozilla.components.feature.search.BrowserStoreSearchAdapter import mozilla.components.feature.search.BrowserStoreSearchAdapter
import mozilla.components.feature.search.ext.legacy import mozilla.components.feature.search.ext.legacy
import mozilla.components.service.fxa.sync.SyncReason 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.base.feature.UserInteractionHandler
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers import mozilla.components.support.ktx.android.arch.lifecycle.addObservers
import mozilla.components.support.ktx.android.content.call import mozilla.components.support.ktx.android.content.call
@ -536,6 +537,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
super.onBackPressed() 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 { private fun shouldUseCustomBackLongPress(): Boolean {
val isAndroidN = val isAndroidN =
Build.VERSION.SDK_INT == Build.VERSION_CODES.N || Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 Build.VERSION.SDK_INT == Build.VERSION_CODES.N || Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1

View File

@ -128,6 +128,7 @@ import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import mozilla.components.feature.media.fullscreen.MediaFullscreenOrientationFeature import mozilla.components.feature.media.fullscreen.MediaFullscreenOrientationFeature
import mozilla.components.feature.webauthn.WebAuthnFeature import mozilla.components.feature.webauthn.WebAuthnFeature
import mozilla.components.support.base.feature.ActivityResultHandler
import org.mozilla.fenix.FeatureFlags.newMediaSessionApi import org.mozilla.fenix.FeatureFlags.newMediaSessionApi
/** /**
@ -137,7 +138,7 @@ import org.mozilla.fenix.FeatureFlags.newMediaSessionApi
*/ */
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@Suppress("TooManyFunctions", "LargeClass") @Suppress("TooManyFunctions", "LargeClass")
abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, ActivityResultHandler,
OnBackLongPressedListener, AccessibilityManager.AccessibilityStateChangeListener { OnBackLongPressedListener, AccessibilityManager.AccessibilityStateChangeListener {
private lateinit var browserFragmentStore: BrowserFragmentStore 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?) { override fun onActivityResult(requestCode: Int, data: Intent?, resultCode: Int): Boolean {
listOf( return listOf(
promptsFeature, promptsFeature,
webAuthnFeature webAuthnFeature
).any { it.onActivityResult(requestCode, data, resultCode) } ).any { it.onActivityResult(requestCode, data, resultCode) }