From 57df4f3fcca9b65e3714ee7094b5236a92bd6466 Mon Sep 17 00:00:00 2001 From: Jonathan Almeida Date: Mon, 31 May 2021 23:54:46 -0400 Subject: [PATCH] [fenix] Issue https://github.com/mozilla-mobile/fenix/issues/19112: Remove old Synced Tabs code --- .../java/org/mozilla/fenix/ui/SmokeTest.kt | 1 - .../mozilla/fenix/ui/ThreeDotMenuMainTest.kt | 1 - .../org/mozilla/fenix/BrowserDirection.kt | 1 - .../java/org/mozilla/fenix/HomeActivity.kt | 3 - .../toolbar/BrowserToolbarMenuController.kt | 7 - .../components/toolbar/DefaultToolbarMenu.kt | 8 -- .../fenix/components/toolbar/ToolbarMenu.kt | 1 - .../org/mozilla/fenix/home/HomeFragment.kt | 7 - .../java/org/mozilla/fenix/home/HomeMenu.kt | 11 +- .../mozilla/fenix/sync/SyncedTabsFragment.kt | 103 --------------- .../mozilla/fenix/sync/SyncedTabsLayout.kt | 124 ------------------ .../main/res/layout/component_sync_tabs.xml | 35 ----- .../main/res/layout/fragment_synced_tabs.xml | 9 -- app/src/main/res/navigation/nav_graph.xml | 12 -- .../fenix/sync/ListenerDelegateTest.kt | 31 ----- .../fenix/sync/SyncedTabsLayoutTest.kt | 22 ---- 16 files changed, 1 insertion(+), 375 deletions(-) delete mode 100644 app/src/main/java/org/mozilla/fenix/sync/SyncedTabsFragment.kt delete mode 100644 app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt delete mode 100644 app/src/main/res/layout/component_sync_tabs.xml delete mode 100644 app/src/main/res/layout/fragment_synced_tabs.xml delete mode 100644 app/src/test/java/org/mozilla/fenix/sync/ListenerDelegateTest.kt delete mode 100644 app/src/test/java/org/mozilla/fenix/sync/SyncedTabsLayoutTest.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt index a3893ce3f8..4efe9cd00e 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -20,7 +20,6 @@ import org.junit.Before import org.junit.Ignore import org.junit.Rule import org.junit.Test -import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.IntentReceiverActivity import org.mozilla.fenix.R import org.mozilla.fenix.ext.components diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt index 4bd2e73088..a992796f61 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/ThreeDotMenuMainTest.kt @@ -9,7 +9,6 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test -import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.ui.robots.homeScreen diff --git a/app/src/main/java/org/mozilla/fenix/BrowserDirection.kt b/app/src/main/java/org/mozilla/fenix/BrowserDirection.kt index 6aa089a222..113001daaa 100644 --- a/app/src/main/java/org/mozilla/fenix/BrowserDirection.kt +++ b/app/src/main/java/org/mozilla/fenix/BrowserDirection.kt @@ -18,7 +18,6 @@ enum class BrowserDirection(@IdRes val fragmentId: Int) { FromHome(R.id.homeFragment), FromSearchDialog(R.id.searchDialogFragment), FromSettings(R.id.settingsFragment), - FromSyncedTabs(R.id.syncedTabsFragment), FromBookmarks(R.id.bookmarkFragment), FromHistory(R.id.historyFragment), FromTrackingProtectionExceptions(R.id.trackingProtectionExceptionsFragment), diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index bd5060797b..3d45483ab5 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -111,7 +111,6 @@ import org.mozilla.fenix.settings.logins.fragment.SavedLoginsAuthFragmentDirecti import org.mozilla.fenix.settings.search.AddSearchEngineFragmentDirections import org.mozilla.fenix.settings.search.EditCustomSearchEngineFragmentDirections import org.mozilla.fenix.share.AddNewDeviceFragmentDirections -import org.mozilla.fenix.sync.SyncedTabsFragmentDirections import org.mozilla.fenix.tabstray.TabsTrayFragment import org.mozilla.fenix.tabstray.TabsTrayFragmentDirections import org.mozilla.fenix.theme.DefaultThemeManager @@ -786,8 +785,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { SearchDialogFragmentDirections.actionGlobalBrowser(customTabSessionId) BrowserDirection.FromSettings -> SettingsFragmentDirections.actionGlobalBrowser(customTabSessionId) - BrowserDirection.FromSyncedTabs -> - SyncedTabsFragmentDirections.actionGlobalBrowser(customTabSessionId) BrowserDirection.FromBookmarks -> BookmarkFragmentDirections.actionGlobalBrowser(customTabSessionId) BrowserDirection.FromHistory -> diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt index 8f7fdd0f06..90cba92fec 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarMenuController.kt @@ -219,12 +219,6 @@ class DefaultBrowserToolbarMenuController( val directions = BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment() navController.nav(R.id.browserFragment, directions) } - is ToolbarMenu.Item.SyncedTabs -> browserAnimator.captureEngineViewAndDrawStatically { - navController.nav( - R.id.browserFragment, - BrowserFragmentDirections.actionBrowserFragmentToSyncedTabsFragment() - ) - } is ToolbarMenu.Item.SyncAccount -> { val directions = if (item.signedIn) { BrowserFragmentDirections.actionGlobalAccountSettingsFragment() @@ -396,7 +390,6 @@ class DefaultBrowserToolbarMenuController( is ToolbarMenu.Item.SaveToCollection -> Event.BrowserMenuItemTapped.Item.SAVE_TO_COLLECTION is ToolbarMenu.Item.AddToTopSites -> Event.BrowserMenuItemTapped.Item.ADD_TO_TOP_SITES is ToolbarMenu.Item.AddToHomeScreen -> Event.BrowserMenuItemTapped.Item.ADD_TO_HOMESCREEN - is ToolbarMenu.Item.SyncedTabs -> Event.BrowserMenuItemTapped.Item.SYNC_TABS is ToolbarMenu.Item.SyncAccount -> Event.BrowserMenuItemTapped.Item.SYNC_ACCOUNT is ToolbarMenu.Item.Bookmark -> Event.BrowserMenuItemTapped.Item.BOOKMARK is ToolbarMenu.Item.AddonsManager -> Event.BrowserMenuItemTapped.Item.ADDONS_MANAGER diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt index 65c659be58..be7b4434c8 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/DefaultToolbarMenu.kt @@ -332,14 +332,6 @@ open class DefaultToolbarMenu( onItemTapped.invoke(ToolbarMenu.Item.Quit) } - val syncedTabsItem = BrowserMenuImageText( - context.getString(R.string.synced_tabs), - R.drawable.ic_synced_tabs, - primaryTextColor() - ) { - onItemTapped.invoke(ToolbarMenu.Item.SyncedTabs) - } - private fun getSyncItemTitle(): String { val authenticatedAccount = accountManager.authenticatedAccount val email = accountManager.accountProfileEmail diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt index ec384c188b..c2baee035f 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarMenu.kt @@ -22,7 +22,6 @@ interface ToolbarMenu { object AddToTopSites : Item() object InstallPwaToHomeScreen : Item() object AddToHomeScreen : Item() - object SyncedTabs : Item() data class SyncAccount(val signedIn: Boolean) : Item() object AddonsManager : Item() object Quit : Item() 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 c726cc55e2..8036fb0151 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -786,13 +786,6 @@ class HomeFragment : Fragment() { ) requireComponents.analytics.metrics.track(Event.HomeMenuSettingsItemClicked) } - HomeMenu.Item.SyncTabs -> { - hideOnboardingIfNeeded() - nav( - R.id.homeFragment, - HomeFragmentDirections.actionGlobalSyncedTabsFragment() - ) - } is HomeMenu.Item.SyncAccount -> { hideOnboardingIfNeeded() val directions = if (it.signedIn) { diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt index 3e6bf870d7..89dce92272 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt @@ -45,7 +45,6 @@ class HomeMenu( object History : Item() object Downloads : Item() object Extensions : Item() - object SyncTabs : Item() data class SyncAccount(val signedIn: Boolean) : Item() object WhatsNew : Item() object Help : Item() @@ -91,14 +90,6 @@ class HomeMenu( } } - val syncedTabsItem = BrowserMenuImageText( - context.getString(R.string.synced_tabs), - R.drawable.ic_synced_tabs, - primaryTextColor - ) { - onItemTapped.invoke(Item.SyncTabs) - } - private fun getSyncItemTitle(): String { val authenticatedAccount = accountManager.authenticatedAccount val email = accountManager.accountProfileEmail @@ -110,7 +101,7 @@ class HomeMenu( } } - val syncSignInMenuItem = BrowserMenuImageText( + private val syncSignInMenuItem = BrowserMenuImageText( getSyncItemTitle(), R.drawable.ic_synced_tabs, primaryTextColor diff --git a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsFragment.kt b/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsFragment.kt deleted file mode 100644 index 2c5018629d..0000000000 --- a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsFragment.kt +++ /dev/null @@ -1,103 +0,0 @@ -/* 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.sync - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.core.content.ContextCompat -import androidx.recyclerview.widget.RecyclerView -import kotlinx.android.synthetic.main.component_sync_tabs.view.* -import kotlinx.android.synthetic.main.fragment_synced_tabs.* -import kotlinx.android.synthetic.main.sync_tabs_error_row.view.* -import mozilla.components.browser.storage.sync.Tab -import mozilla.components.feature.syncedtabs.SyncedTabsFeature -import mozilla.components.support.base.feature.ViewBoundFeatureWrapper -import org.mozilla.fenix.BrowserDirection -import org.mozilla.fenix.HomeActivity -import org.mozilla.fenix.R -import org.mozilla.fenix.ext.components -import org.mozilla.fenix.ext.showToolbar -import org.mozilla.fenix.library.LibraryPageFragment -import org.mozilla.fenix.theme.ThemeManager - -class SyncedTabsFragment : LibraryPageFragment() { - private val syncedTabsFeature = ViewBoundFeatureWrapper() - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return inflater.inflate(R.layout.fragment_synced_tabs, container, false) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val backgroundServices = requireContext().components.backgroundServices - - /* - * Needed because the synced tabs error layout is also used in tabs tray where there is no private theme. - * See https://github.com/mozilla-mobile/fenix/issues/15061 - */ - setProperErrorColor(view.synced_tabs_list as RecyclerView) - - syncedTabsFeature.set( - feature = SyncedTabsFeature( - context = requireContext(), - storage = backgroundServices.syncedTabsStorage, - accountManager = backgroundServices.accountManager, - view = synced_tabs_layout, - lifecycleOwner = this.viewLifecycleOwner, - onTabClicked = ::handleTabClicked - ), - owner = this, - view = view - ) - } - - private fun setProperErrorColor(syncedTabsList: RecyclerView) { - syncedTabsList.addOnChildAttachStateChangeListener( - object : RecyclerView.OnChildAttachStateChangeListener { - override fun onChildViewAttachedToWindow(view: View) { - val errorView = view.sync_tabs_error_description - val primaryText = ContextCompat.getColor( - view.context, - ThemeManager.resolveAttribute(R.attr.primaryText, view.context) - ) - errorView?.let { - it.setTextColor(primaryText) - syncedTabsList.removeOnChildAttachStateChangeListener( - this - ) - } - } - - override fun onChildViewDetachedFromWindow(view: View) { - // do nothing - } - } - ) - } - - override fun onResume() { - super.onResume() - showToolbar(getString(R.string.library_synced_tabs)) - } - - private fun handleTabClicked(tab: Tab) { - - (activity as HomeActivity).openToBrowserAndLoad( - searchTermOrURL = tab.active().url, - newTab = true, - from = BrowserDirection.FromSyncedTabs - ) - } - - override val selectedItems: Set - get() = emptySet() -} diff --git a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt b/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt deleted file mode 100644 index b6c65b90e2..0000000000 --- a/app/src/main/java/org/mozilla/fenix/sync/SyncedTabsLayout.kt +++ /dev/null @@ -1,124 +0,0 @@ -/* 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.sync - -import android.content.Context -import android.util.AttributeSet -import android.widget.FrameLayout -import androidx.fragment.app.findFragment -import androidx.navigation.NavController -import androidx.navigation.fragment.findNavController -import androidx.recyclerview.widget.LinearLayoutManager -import kotlinx.android.synthetic.main.component_sync_tabs.view.* -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.cancel -import kotlinx.coroutines.launch -import mozilla.components.browser.storage.sync.SyncedDeviceTabs -import mozilla.components.browser.storage.sync.Tab -import mozilla.components.feature.syncedtabs.view.SyncedTabsView -import org.mozilla.fenix.R -import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.components.metrics.MetricController -import org.mozilla.fenix.ext.components -import org.mozilla.fenix.sync.ext.toAdapterItem -import org.mozilla.fenix.sync.ext.toStringRes -import java.lang.IllegalStateException - -class SyncedTabsLayout @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0 -) : FrameLayout(context, attrs, defStyleAttr), SyncedTabsView { - - override var listener: SyncedTabsView.Listener? = null - private val metrics = context.components.analytics.metrics - - private val adapter = SyncedTabsAdapter(ListenerDelegate(metrics) { listener }) - private val coroutineScope = CoroutineScope(Dispatchers.Main) - - init { - inflate(getContext(), R.layout.component_sync_tabs, this) - - synced_tabs_list.layoutManager = LinearLayoutManager(context) - synced_tabs_list.adapter = adapter - - synced_tabs_pull_to_refresh.setOnRefreshListener { listener?.onRefresh() } - } - - override fun onError(error: SyncedTabsView.ErrorType) { - coroutineScope.launch { - // We may still be displaying a "loading" spinner, hide it. - stopLoading() - - val navController: NavController? = try { - findFragment().findNavController() - } catch (exception: IllegalStateException) { - null - } - - val descriptionResId = error.toStringRes() - val errorItem = error.toAdapterItem(descriptionResId, navController) - - val errorList: List = listOf(errorItem) - adapter.submitList(errorList) - - synced_tabs_pull_to_refresh.isEnabled = pullToRefreshEnableState(error) - } - } - - override fun displaySyncedTabs(syncedTabs: List) { - coroutineScope.launch { - adapter.updateData(syncedTabs) - } - } - - override fun startLoading() { - synced_tabs_pull_to_refresh.isRefreshing = true - } - - override fun stopLoading() { - synced_tabs_pull_to_refresh.isRefreshing = false - } - - override fun onDetachedFromWindow() { - super.onDetachedFromWindow() - coroutineScope.cancel() - } - - companion object { - - internal fun pullToRefreshEnableState(error: SyncedTabsView.ErrorType) = when (error) { - // Disable "pull-to-refresh" when we clearly can't sync tabs, and user needs to take an - // action within the app. - SyncedTabsView.ErrorType.SYNC_UNAVAILABLE, - SyncedTabsView.ErrorType.SYNC_NEEDS_REAUTHENTICATION -> false - - // Enable "pull-to-refresh" when an external event (e.g. connecting a desktop client, - // or enabling tabs sync, or connecting to a network) may resolve our problem. - SyncedTabsView.ErrorType.SYNC_ENGINE_UNAVAILABLE, - SyncedTabsView.ErrorType.MULTIPLE_DEVICES_UNAVAILABLE, - SyncedTabsView.ErrorType.NO_TABS_AVAILABLE -> true - } - } -} - -/** - * We have to do this weird daisy-chaining of callbacks because the listener is nullable and - * when we get a null reference, we never get a new binding to the non-null listener. - */ -class ListenerDelegate( - private val metrics: MetricController, - private val listener: (() -> SyncedTabsView.Listener?) -) : SyncedTabsView.Listener { - override fun onRefresh() { - listener.invoke()?.onRefresh() - } - - override fun onTabClicked(tab: Tab) { - listener.invoke()?.onTabClicked(tab) - metrics.track(Event.SyncedTabOpened) - } -} diff --git a/app/src/main/res/layout/component_sync_tabs.xml b/app/src/main/res/layout/component_sync_tabs.xml deleted file mode 100644 index f5a07f0967..0000000000 --- a/app/src/main/res/layout/component_sync_tabs.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_synced_tabs.xml b/app/src/main/res/layout/fragment_synced_tabs.xml deleted file mode 100644 index 190b36d967..0000000000 --- a/app/src/main/res/layout/fragment_synced_tabs.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 9465202b20..cfc4d08b71 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -57,9 +57,6 @@ - @@ -196,9 +193,6 @@ android:name="activeSessionId" app:argType="string" app:nullable="true" /> - @@ -357,12 +351,6 @@ app:popUpToInclusive="true" /> - -