From 1b6aa1dfff824dd3be0b64cc0b77b754ba73b593 Mon Sep 17 00:00:00 2001 From: Christian Sadilek Date: Thu, 10 Jun 2021 12:12:44 -0400 Subject: [PATCH] [fenix] Issue https://github.com/mozilla-mobile/fenix/issues/17800: Cleanup and fix request desktop site from home --- .../java/org/mozilla/fenix/HomeActivity.kt | 20 ++++++++----------- .../org/mozilla/fenix/home/HomeFragment.kt | 1 - .../SessionControlController.kt | 5 ++--- .../DefaultSessionControlControllerTest.kt | 2 -- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 56bd1479c5..cfa0e82b9c 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -843,7 +843,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { // has removed all of them, or we couldn't load any) we will pass searchTermOrURL to Gecko // and let it try to load whatever was entered. if ((!forceSearch && searchTermOrURL.isUrl()) || engine == null) { - if (newTab) { + val tabId = if (newTab) { components.useCases.tabsUseCases.addTab( url = searchTermOrURL.toNormalizedUrl(), flags = flags, @@ -854,10 +854,11 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { url = searchTermOrURL.toNormalizedUrl(), flags = flags ) + components.core.store.state.selectedTabId } - if (requestDesktopMode) { - handleRequestDesktopMode() + if (requestDesktopMode && tabId != null) { + handleRequestDesktopMode(tabId) } } else { if (newTab) { @@ -885,15 +886,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { } } - internal fun handleRequestDesktopMode() { - val requestDesktopSiteUseCase = - components.useCases.sessionUseCases.requestDesktopSite - requestDesktopSiteUseCase.invoke(true) - components.core.store.dispatch( - ContentAction.UpdateDesktopModeAction( - components.core.store.state.selectedTabId.toString(), true - ) - ) + internal fun handleRequestDesktopMode(tabId: String) { + components.useCases.sessionUseCases.requestDesktopSite(true, tabId) + components.core.store.dispatch(ContentAction.UpdateDesktopModeAction(tabId, true)) + // Reset preference value after opening the tab in desktop mode settings().openNextTabInDesktopMode = false } diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 8036fb0151..4cb0d57d46 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -255,7 +255,6 @@ class HomeFragment : Fragment() { restoreUseCase = components.useCases.tabsUseCases.restore, reloadUrlUseCase = components.useCases.sessionUseCases.reload, selectTabUseCase = components.useCases.tabsUseCases.selectTab, - requestDesktopSiteUseCase = components.useCases.sessionUseCases.requestDesktopSite, fragmentStore = homeFragmentStore, navController = findNavController(), viewLifecycleScope = viewLifecycleOwner.lifecycleScope, diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt index 5efc98120e..ac14a87bcb 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt @@ -192,7 +192,6 @@ class DefaultSessionControlController( private val restoreUseCase: TabsUseCases.RestoreUseCase, private val reloadUrlUseCase: SessionUseCases.ReloadUrlUseCase, private val selectTabUseCase: TabsUseCases.SelectTabUseCase, - private val requestDesktopSiteUseCase: SessionUseCases.RequestDesktopSiteUseCase, private val fragmentStore: HomeFragmentStore, private val navController: NavController, private val viewLifecycleScope: CoroutineScope, @@ -410,14 +409,14 @@ class DefaultSessionControlController( } event?.let { activity.metrics.track(it) } - addTabUseCase.invoke( + val tabId = addTabUseCase.invoke( url = appendSearchAttributionToUrlIfNeeded(url), selectTab = true, startLoading = true ) if (settings.openNextTabInDesktopMode) { - activity.handleRequestDesktopMode() + activity.handleRequestDesktopMode(tabId) } activity.openToBrowser(BrowserDirection.FromHome) } diff --git a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt index b9e36968be..59b84ac593 100644 --- a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt @@ -145,7 +145,6 @@ class DefaultSessionControlControllerTest { every { analytics.metrics } returns metrics val restoreUseCase: TabsUseCases.RestoreUseCase = mockk(relaxed = true) - val requestDesktopSiteUseCase: SessionUseCases.RequestDesktopSiteUseCase = mockk(relaxed = true) controller = spyk(DefaultSessionControlController( activity = activity, @@ -158,7 +157,6 @@ class DefaultSessionControlControllerTest { reloadUrlUseCase = reloadUrlUseCase.reload, selectTabUseCase = selectTabUseCase.selectTab, restoreUseCase = restoreUseCase, - requestDesktopSiteUseCase = requestDesktopSiteUseCase, fragmentStore = fragmentStore, navController = navController, viewLifecycleScope = scope,