Skip to content

Commit

Permalink
Closes mozilla-mobile#21759: Do not render home fragment when launchi…
Browse files Browse the repository at this point in the history
…ng to tab

Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
  • Loading branch information
csadilek and pocmo committed Oct 15, 2021
1 parent ee86362 commit d4f9446
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
28 changes: 17 additions & 11 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
it.start()
}

if (!shouldStartOnHome() &&
shouldNavigateBrowserFragmentOnCouldStart(savedInstanceState)
) {
navigateToBrowserOnColdStart()
} else if (FeatureFlags.showStartOnHomeSettings) {
components.analytics.metrics.track(Event.StartOnHomeEnterHomeScreen)
// Navigate to home first (without rendering it) to add it to the back stack.
navigateToHome()

if (!shouldStartOnHome() && shouldNavigateToBrowserOnColdStart(savedInstanceState)) {
maybeNavigateToBrowserOnColdStart()
} else {
if (FeatureFlags.showStartOnHomeSettings) {
components.analytics.metrics.track(Event.StartOnHomeEnterHomeScreen)
}
}

Performance.processIntentIfPerformanceTest(intent, this)
Expand Down Expand Up @@ -874,16 +877,19 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
settings().openNextTabInDesktopMode = false
}

open fun navigateToBrowserOnColdStart() {
open fun maybeNavigateToBrowserOnColdStart() {
// 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)
Expand Down Expand Up @@ -999,7 +1005,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
@VisibleForTesting
internal fun getSettings(): Settings = settings()

private fun shouldNavigateBrowserFragmentOnCouldStart(savedInstanceState: Bundle?): Boolean {
private fun shouldNavigateToBrowserOnColdStart(savedInstanceState: Bundle?): Boolean {
return isActivityColdStarted(intent, savedInstanceState) &&
!externalSourceIntentProcessors.any {
it.process(
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/org/mozilla/fenix/StartupFragment.kt
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ open class ExternalAppBrowserActivity : HomeActivity() {

final override fun getIntentSessionId(intent: SafeIntent) = intent.getSessionId()

override fun navigateToBrowserOnColdStart() {
override fun maybeNavigateToBrowserOnColdStart() {
// No-op for external app
}

override fun navigateToHome() {
// No-op for external app
}

Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -152,6 +158,11 @@
app:argType="boolean" />
</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"
Expand Down

0 comments on commit d4f9446

Please sign in to comment.