Bug 1870613 - Extracted the HomeActivity`getBreadcrumbMessage`, `getIntentSource` and `getIntentSessionId` as generic Activity functions

fenix/123.0
t-p-white 6 months ago committed by mergify[bot]
parent 3587b445de
commit 53415dddb4

@ -28,13 +28,11 @@ import androidx.annotation.CallSuper
import androidx.annotation.IdRes
import androidx.annotation.RequiresApi
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting.Companion.PROTECTED
import androidx.appcompat.app.ActionBar
import androidx.appcompat.widget.Toolbar
import androidx.core.app.NotificationManagerCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDestination
import androidx.navigation.NavDirections
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
@ -107,6 +105,9 @@ import org.mozilla.fenix.experiments.ResearchSurfaceDialogFragment
import org.mozilla.fenix.ext.alreadyOnDestination
import org.mozilla.fenix.ext.breadcrumb
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getBreadcrumbMessage
import org.mozilla.fenix.ext.getIntentSessionId
import org.mozilla.fenix.ext.getIntentSource
import org.mozilla.fenix.ext.hasTopDestination
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.setNavigationIcon
@ -887,20 +888,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
super.onUserLeaveHint()
}
protected open fun getBreadcrumbMessage(destination: NavDestination): String {
val fragmentName = resources.getResourceEntryName(destination.id)
return "Changing to fragment $fragmentName, isCustomTab: false"
}
@VisibleForTesting(otherwise = PROTECTED)
internal open fun getIntentSource(intent: SafeIntent): String? {
return when {
intent.isLauncherIntent -> APP_ICON
intent.action == Intent.ACTION_VIEW -> "LINK"
else -> null
}
}
/**
* External sources such as 3rd party links and shortcuts use this function to enter
* private mode directly before the content view is created. Returns the mode set by the intent
@ -981,8 +968,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
}
protected open fun getIntentSessionId(intent: SafeIntent): String? = null
/**
* Navigates to the browser fragment and loads a URL or performs a search (depending on the
* value of [searchTermOrURL]).

@ -10,18 +10,17 @@ import android.net.Uri
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.annotation.VisibleForTesting
import androidx.navigation.NavDestination
import androidx.navigation.NavDirections
import mozilla.components.browser.state.selector.findCustomTab
import mozilla.components.browser.state.state.SessionState
import mozilla.components.concept.engine.manifest.WebAppManifestParser
import mozilla.components.feature.intent.ext.getSessionId
import mozilla.components.feature.pwa.ext.getWebAppManifest
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getIntentSessionId
import java.security.InvalidParameterException
const val EXTRA_IS_SANDBOX_CUSTOM_TAB = "org.mozilla.fenix.customtabs.EXTRA_IS_SANDBOX_CUSTOM_TAB"
@ -45,15 +44,6 @@ open class ExternalAppBrowserActivity : HomeActivity() {
}
}
final override fun getBreadcrumbMessage(destination: NavDestination): String {
val fragmentName = resources.getResourceEntryName(destination.id)
return "Changing to fragment $fragmentName, isCustomTab: true"
}
final override fun getIntentSource(intent: SafeIntent) = "CUSTOM_TAB"
final override fun getIntentSessionId(intent: SafeIntent) = intent.getSessionId()
override fun navigateToBrowserOnColdStart() {
// No-op for external app
}

@ -15,11 +15,15 @@ import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.navigation.NavDestination
import mozilla.components.concept.base.crash.Breadcrumb
import mozilla.components.concept.engine.EngineSession
import mozilla.components.feature.intent.ext.getSessionId
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity
import org.mozilla.fenix.settings.SupportUtils
/**
@ -174,3 +178,54 @@ const val REQUEST_CODE_BROWSER_ROLE = 1
const val SETTINGS_SELECT_OPTION_KEY = ":settings:fragment_args_key"
const val SETTINGS_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args"
const val DEFAULT_BROWSER_APP_OPTION = "default_browser"
const val EXTERNAL_APP_BROWSER_INTENT_SOURCE = "CUSTOM_TAB"
/**
* Depending on the [Activity], maybe derive the source of the given [intent].
*
* @param intent the [SafeIntent] to derive the source from.
*/
fun Activity.getIntentSource(intent: SafeIntent): String? = when (this) {
is ExternalAppBrowserActivity -> EXTERNAL_APP_BROWSER_INTENT_SOURCE
else -> getHomeIntentSource(intent)
}
private fun getHomeIntentSource(intent: SafeIntent): String? {
return when {
intent.isLauncherIntent -> HomeActivity.APP_ICON
intent.action == Intent.ACTION_VIEW -> "LINK"
else -> null
}
}
/**
* Depending on the [Activity], maybe derive the session ID of the given [intent].
*
* @param intent the [SafeIntent] to derive the session ID from.
*/
fun Activity.getIntentSessionId(intent: SafeIntent): String? = when (this) {
is ExternalAppBrowserActivity -> getExternalAppBrowserIntentSessionId(intent)
else -> null
}
private fun getExternalAppBrowserIntentSessionId(intent: SafeIntent) = intent.getSessionId()
/**
* Get the breadcrumb message for the [Activity].
*
* @param destination the [NavDestination] required to provide the destination ID.
*/
fun Activity.getBreadcrumbMessage(destination: NavDestination): String = when (this) {
is ExternalAppBrowserActivity -> getExternalAppBrowserBreadcrumbMessage(destination.id)
else -> getHomeBreadcrumbMessage(destination.id)
}
private fun Activity.getExternalAppBrowserBreadcrumbMessage(destinationId: Int): String {
val fragmentName = resources.getResourceEntryName(destinationId)
return "Changing to fragment $fragmentName, isCustomTab: true"
}
private fun Activity.getHomeBreadcrumbMessage(destinationId: Int): String {
val fragmentName = resources.getResourceEntryName(destinationId)
return "Changing to fragment $fragmentName, isCustomTab: false"
}

@ -25,6 +25,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppState
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getIntentSource
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.helpers.perf.TestStrictModeManager

@ -28,6 +28,7 @@ import org.junit.runner.RunWith
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getIntentSource
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.utils.Settings

Loading…
Cancel
Save