Closes #21759: Do not render home fragment when launching to tab

Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
upstream-sync
Christian Sadilek 3 years ago committed by mergify[bot]
parent 910a425cc3
commit f919e97445

@ -132,7 +132,7 @@ import java.lang.ref.WeakReference
* - browser screen
*/
@OptIn(ExperimentalCoroutinesApi::class)
@SuppressWarnings("TooManyFunctions", "LargeClass", "LongParameterList")
@SuppressWarnings("TooManyFunctions", "LargeClass", "LongParameterList", "LongMethod")
open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
// DO NOT MOVE ANYTHING ABOVE THIS, GETTING INIT TIME IS CRITICAL
// we need to store startup timestamp for warm startup. we cant directly store
@ -229,12 +229,18 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
it.start()
}
if (!shouldStartOnHome() &&
shouldNavigateBrowserFragmentOnColdStart(savedInstanceState)
) {
// Unless the activity is recreated, navigate to home first (without rendering it)
// to add it to the back stack.
if (savedInstanceState == null) {
navigateToHome()
}
if (!shouldStartOnHome() && shouldNavigateToBrowserOnColdStart(savedInstanceState)) {
navigateToBrowserOnColdStart()
} else if (FeatureFlags.showStartOnHomeSettings) {
components.analytics.metrics.track(Event.StartOnHomeEnterHomeScreen)
} else {
if (FeatureFlags.showStartOnHomeSettings) {
components.analytics.metrics.track(Event.StartOnHomeEnterHomeScreen)
}
}
Performance.processIntentIfPerformanceTest(intent, this)
@ -879,13 +885,16 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
open fun navigateToBrowserOnColdStart() {
// Normal tabs + cold start -> Should go back to browser if we had any tabs open when we left last
// except for PBM + Cold Start there won't be any tabs since they're evicted so we never will navigate
if (settings().shouldReturnToBrowser &&
!browsingModeManager.mode.isPrivate
) {
if (settings().shouldReturnToBrowser && !browsingModeManager.mode.isPrivate) {
// Navigate to home first (without rendering it) to add it to the back stack.
openToBrowser(BrowserDirection.FromGlobal, null)
}
}
open fun navigateToHome() {
navHost.navController.navigate(NavGraphDirections.actionStartupHome())
}
override fun attachBaseContext(base: Context) {
base.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
super.attachBaseContext(base)
@ -1001,7 +1010,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
@VisibleForTesting
internal fun getSettings(): Settings = settings()
private fun shouldNavigateBrowserFragmentOnColdStart(savedInstanceState: Bundle?): Boolean {
private fun shouldNavigateToBrowserOnColdStart(savedInstanceState: Bundle?): Boolean {
return isActivityColdStarted(intent, savedInstanceState) &&
!externalSourceIntentProcessors.any {
it.process(

@ -0,0 +1,19 @@
/* 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
import androidx.fragment.app.Fragment
import org.mozilla.fenix.home.HomeFragment
/**
* This empty fragment serves as a start destination in our navigation
* graph. It contains no layout and is fast to create compared to our
* [HomeFragment], which would otherwise be the start destination.
*
* When our [HomeActivity] is created we make a decision which fragment
* to navigate to, which makes sure we only render the [HomeFragment]
* as needed.
*/
class StartupFragment : Fragment()

@ -53,6 +53,10 @@ open class ExternalAppBrowserActivity : HomeActivity() {
// No-op for external app
}
override fun navigateToHome() {
// No-op for external app
}
override fun handleNewIntent(intent: Intent) {
// No-op for external app
}

@ -3,7 +3,13 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/homeFragment">
app:startDestination="@id/startupFragment">
<action
android:id="@+id/action_startup_home"
app:destination="@id/homeFragment"
app:popUpTo="@id/startupFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_global_home"
@ -157,6 +163,11 @@
app:argType="string" />
</dialog>
<fragment
android:id="@+id/startupFragment"
android:name="org.mozilla.fenix.StartupFragment">
</fragment>
<fragment
android:id="@+id/homeFragment"
android:name="org.mozilla.fenix.home.HomeFragment"

Loading…
Cancel
Save