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

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

Loading…
Cancel
Save