From e03f8fb6dcf42b0d0df9abaa0f00eb966ce3c323 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Mon, 6 Mar 2023 11:53:10 +0200 Subject: [PATCH] Bug 1820169 - Ensure shortcuts snackbars are shown They must have the right parent to ensure they are shown on top of other Views and that they are also scrollable in pair with the bottom toolbar. --- .../mozilla/fenix/browser/BaseBrowserFragment.kt | 2 +- .../toolbar/BrowserToolbarMenuController.kt | 14 +++++++------- .../DefaultBrowserToolbarMenuControllerTest.kt | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index b9761c3d16..0ab3717601 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -390,7 +390,7 @@ abstract class BaseBrowserFragment : readerModeController = readerMenuController, sessionFeature = sessionFeature, findInPageLauncher = { findInPageIntegration.withFeature { it.launch() } }, - swipeRefresh = binding.swipeRefresh, + snackbarParent = binding.dynamicSnackbarContainer, browserAnimator = browserAnimator, customTabSessionId = customTabSessionId, openInFenixIntent = openInFenixIntent, 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 1765b16927..38dfc48a0c 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 @@ -5,10 +5,10 @@ package org.mozilla.fenix.components.toolbar import android.content.Intent +import android.view.ViewGroup import androidx.annotation.VisibleForTesting import androidx.appcompat.app.AlertDialog import androidx.navigation.NavController -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -67,7 +67,7 @@ class DefaultBrowserToolbarMenuController( private val sessionFeature: ViewBoundFeatureWrapper, private val findInPageLauncher: () -> Unit, private val browserAnimator: BrowserAnimator, - private val swipeRefresh: SwipeRefreshLayout, + private val snackbarParent: ViewGroup, private val customTabSessionId: String?, private val openInFenixIntent: Intent, private val bookmarkTapped: (String, String) -> Unit, @@ -251,12 +251,12 @@ class DefaultBrowserToolbarMenuController( } is ToolbarMenu.Item.AddToTopSites -> { scope.launch { - val context = swipeRefresh.context + val context = snackbarParent.context val numPinnedSites = topSitesStorage.cachedTopSites .filter { it is TopSite.Default || it is TopSite.Pinned }.size if (numPinnedSites >= settings.topSitesMaxLimit) { - AlertDialog.Builder(swipeRefresh.context).apply { + AlertDialog.Builder(snackbarParent.context).apply { setTitle(R.string.shortcut_max_limit_title) setMessage(R.string.shortcut_max_limit_content) setPositiveButton(R.string.top_sites_max_limit_confirmation_button) { dialog, _ -> @@ -274,7 +274,7 @@ class DefaultBrowserToolbarMenuController( }.join() FenixSnackbar.make( - view = swipeRefresh, + view = snackbarParent, duration = Snackbar.LENGTH_SHORT, isDisplayedWithBrowserToolbar = true, ) @@ -378,12 +378,12 @@ class DefaultBrowserToolbarMenuController( } FenixSnackbar.make( - view = swipeRefresh, + view = snackbarParent, duration = Snackbar.LENGTH_SHORT, isDisplayedWithBrowserToolbar = true, ) .setText( - swipeRefresh.context.getString(R.string.snackbar_top_site_removed), + snackbarParent.context.getString(R.string.snackbar_top_site_removed), ) .show() } diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt index afeee75c34..f97e84c3c8 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarMenuControllerTest.kt @@ -5,8 +5,8 @@ package org.mozilla.fenix.components.toolbar import android.content.Intent +import android.view.ViewGroup import androidx.navigation.NavController -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import io.mockk.MockKAnnotations import io.mockk.Runs import io.mockk.coEvery @@ -87,7 +87,7 @@ class DefaultBrowserToolbarMenuControllerTest { @get:Rule val gleanTestRule = GleanTestRule(testContext) - @MockK private lateinit var swipeRefreshLayout: SwipeRefreshLayout + @MockK private lateinit var snackbarParent: ViewGroup @RelaxedMockK private lateinit var activity: HomeActivity @@ -522,7 +522,7 @@ class DefaultBrowserToolbarMenuControllerTest { every { topSitesUseCase.addPinnedSites } returns addPinnedSiteUseCase every { - swipeRefreshLayout.context.getString(R.string.snackbar_added_to_shortcuts) + snackbarParent.context.getString(R.string.snackbar_added_to_shortcuts) } returns "Added to shortcuts!" val controller = createController(scope = this, store = browserStore) @@ -550,7 +550,7 @@ class DefaultBrowserToolbarMenuControllerTest { coEvery { pinnedSiteStorage.getPinnedSites() } returns listOf(topSite) every { topSitesUseCase.removeTopSites } returns removePinnedSiteUseCase every { - swipeRefreshLayout.context.getString(R.string.snackbar_top_site_removed) + snackbarParent.context.getString(R.string.snackbar_top_site_removed) } returns snackbarMessage val controller = createController(scope = this, store = browserStore) @@ -821,7 +821,7 @@ class DefaultBrowserToolbarMenuControllerTest { customTabSessionId = customTabSessionId, openInFenixIntent = openInFenixIntent, scope = scope, - swipeRefresh = swipeRefreshLayout, + snackbarParent = snackbarParent, tabCollectionStorage = tabCollectionStorage, bookmarkTapped = bookmarkTapped, readerModeController = readerModeController,